예제 #1
0
        public void K_PointCrossover_ShortAndLongChromosomes(int k)
        {
            var crossoverManager = new K_PointCrossoverManager <int>(k, A.Fake <IMutationManager <int> >(), A.Fake <IEvaluator>());

            for (int i = 0; i < TEST_RUNS; i++)
            {
                var chromosome1   = (VectorChromosome <int>)smallPopulationGenerator1.GeneratePopulation(1).First();
                var chromosome2   = (VectorChromosome <int>)largePopulationGenerator.GeneratePopulation(1).First();
                var newChromosome = (VectorChromosome <int>)crossoverManager.Crossover(chromosome1, chromosome2);

                var crossoverPoints = Utils.K_CrossoverGetCrossoverPointsAndAssertThatGenomesAreRight(newChromosome, chromosome2, chromosome1);
                Assert.AreEqual(k, crossoverPoints.Count,
                                $"Found wrong number of crossoverPoints. 1: {chromosome1}; 2 {chromosome2}; newChromosome {newChromosome}");
            }
        }
예제 #2
0
        public void K_PointCrossover_CrossoverPointsAreDiffrent()
        {
            var crossoverPoints  = new List <int>();
            var crossoverManager = new K_PointCrossoverManager <int>(2, A.Fake <IMutationManager <int> >(), A.Fake <IEvaluator>());

            for (int i = 0; i < 100; i++)
            {
                var chromosome1   = (VectorChromosome <int>)smallPopulationGenerator1.GeneratePopulation(1).First();
                var chromosome2   = (VectorChromosome <int>)smallPopulationGenerator2.GeneratePopulation(1).First();
                var newChromosome = (VectorChromosome <int>)crossoverManager.Crossover(chromosome1, chromosome2);

                crossoverPoints.AddRange(Utils.K_CrossoverGetCrossoverPointsAndAssertThatGenomesAreRight(newChromosome, chromosome2, chromosome1));
            }

            for (int i = 1; i < SMALL_CHROMOSOME_SIZE; i++)
            {
                Assert.IsTrue(crossoverPoints.Contains(i), $"{nameof(crossoverPoints)} dosn't contain {i}");
            }
        }