Exemplo n.º 1
0
        public void WhenNextGenerationCreated_PopulationSizeShouldNotChange()
        {
            TestEvaluator <int> evaluator = new TestEvaluator <int> ();

            Engine <int> engine = new Engine <int> (evaluator);

            engine.Setup();

            int population = engine.Population.PopulationSize;

            Population <int> nextGen = engine.ExecuteOneGeneration();

            Assert.AreEqual(population, nextGen.PopulationSize);
        }
Exemplo n.º 2
0
        public void WhenNextGenerationCreated_GenomeLengthShouldNotChange()
        {
            TestEvaluator <int> evaluator = new TestEvaluator <int> ();

            Engine <int> engine = new Engine <int> (evaluator);

            engine.Setup();

            int genomeLength = engine.Population.Individuals[0].GenomeLength;

            Population <int> nextGen = engine.ExecuteOneGeneration();

            Assert.AreEqual(genomeLength, nextGen.Individuals[0].GenomeLength);
        }
Exemplo n.º 3
0
        public void WhenNextGenerationCreated_FullMutation_FittestShouldBeFullyMutated()
        {
            TestEvaluator <int> evaluator = new TestEvaluator <int> (
                (i) => {
                if (i.Code [0] == 0)
                {
                    return(0d);
                }

                return(.5d);
            }
                );

            Engine <int> engine = new Engine <int> (evaluator);

            engine.Setup();

            engine.Population.Individuals.For((ind, i) => {
                ind.Code [0] = i < 2 ? 1 : 0;
            });

            ConfigurationProvider.Mutation.ChanceOfMutation = 1d;
            int[] first  = new int[engine.Population[0].GenomeLength];
            int[] second = new int[engine.Population [0].GenomeLength];

            engine.Population [0].Code.CopyTo(first, 0);
            engine.Population [1].Code.CopyTo(second, 0);

            Population <int> population = engine.ExecuteOneGeneration();

            Assert.IsFalse(FoundMatch(new List <int[]> {
                first, second
            }, population[0]));
            Assert.IsFalse(FoundMatch(new List <int[]> {
                first, second
            }, population[1]));
        }
Exemplo n.º 4
0
        public void WhenNextGenerationCreated_NextGenShouldBeDifferentToInitialGeneration()
        {
            TestEvaluator <int> evaluator = new TestEvaluator <int> (
                (i) => {
                if (i.Code [0] == 0)
                {
                    return(0d);
                }

                return(.5d);
            }
                );

            Engine <int> engine = new Engine <int> (evaluator);

            engine.Setup();

            engine.Population.Individuals.For((ind, i) => {
                ind.Code [0] = i < 2 ? 1 : 0;
            });

            ConfigurationProvider.Mutation.ChanceOfMutation = 0d;
            int[] third  = new int[engine.Population[0].GenomeLength];
            int[] fourth = new int[engine.Population [0].GenomeLength];

            engine.Population [2].Code.CopyTo(third, 0);
            engine.Population [3].Code.CopyTo(fourth, 0);

            Population <int> population = engine.ExecuteOneGeneration();

            Assert.IsFalse(FoundMatch(new List <int[]> {
                third, fourth
            }, population[2]));
            Assert.IsFalse(FoundMatch(new List <int[]> {
                third, fourth
            }, population[3]));
        }