コード例 #1
0
        public void Start_UsingAllConfigurationCombinationsAvailable_AllRun()
        {
            var selections   = SelectionService.GetSelectionNames();
            var crossovers   = CrossoverService.GetCrossoverNames();
            var mutations    = MutationService.GetMutationNames().Where(m => !m.Equals("Flip Bit"));
            var reinsertions = ReinsertionService.GetReinsertionNames();
            var chromosome   = new OrderedChromosomeStub();

            foreach (var s in selections)
            {
                foreach (var c in crossovers)
                {
                    foreach (var m in mutations)
                    {
                        foreach (var r in reinsertions)
                        {
                            var selection   = SelectionService.CreateSelectionByName(s);
                            var crossover   = CrossoverService.CreateCrossoverByName(c);
                            var mutation    = MutationService.CreateMutationByName(m);
                            var reinsertion = ReinsertionService.CreateReinsertionByName(r);

                            if (crossover.IsOrdered ^ mutation.IsOrdered)
                            {
                                continue;
                            }

                            if (crossover.ParentsNumber > crossover.ChildrenNumber && !reinsertion.CanExpand)
                            {
                                continue;
                            }

                            if (mutation is UniformMutation)
                            {
                                mutation = new UniformMutation(1);
                            }

                            var target = new GeneticAlgorithm(
                                new Population(50, 50, chromosome.Clone())
                            {
                                GenerationStrategy = new TrackingGenerationStrategy()
                            },
                                new FitnessStub()
                            {
                                SupportsParallel = false
                            },
                                selection,
                                crossover,
                                mutation);

                            target.Reinsertion          = reinsertion;
                            target.Termination          = new GenerationNumberTermination(25);
                            target.CrossoverProbability = reinsertion.CanExpand ? 0.75f : 1f;

                            target.Start();
                            Assert.AreEqual(25, target.Population.Generations.Count);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Start_UsingAllConfigurationCombinationsAvailable_AllRun()
        {
            var selections = SelectionService.GetSelectionNames();
            var crossovers = CrossoverService.GetCrossoverNames();
            var mutations = MutationService.GetMutationNames();
            var reinsertions = ReinsertionService.GetReinsertionNames();
            var chromosome = new OrderedChromosomeStub();

            foreach (var s in selections)
            {
                foreach (var c in crossovers)
                {
                    foreach (var m in mutations)
                    {
                        foreach (var r in reinsertions)
                        {
                            var selection = SelectionService.CreateSelectionByName(s);
                            var crossover = CrossoverService.CreateCrossoverByName(c);
                            var mutation = MutationService.CreateMutationByName(m);
                            var reinsertion = ReinsertionService.CreateReinsertionByName(r);

                            if (crossover.IsOrdered ^ mutation.IsOrdered)
                            {
                                continue;
                            }

                            if (crossover.ParentsNumber > crossover.ChildrenNumber && !reinsertion.CanExpand)
                            {
                                continue;
                            }

                            if (mutation is UniformMutation)
                            {
                                mutation = new UniformMutation(1);
                            }

                            var target = new GeneticAlgorithm(
                                 new Population(50, 50, chromosome.Clone())
                                 {
                                     GenerationStrategy = new TrackingGenerationStrategy()
                                 },
                                 new FitnessStub() { SupportsParallel = false },
                                 selection,
                                 crossover,
                                 mutation);

                            target.Reinsertion = reinsertion;
                            target.Termination = new GenerationNumberTermination(25);
                            target.CrossoverProbability = reinsertion.CanExpand ? 0.75f : 1f;

                            target.Start();
                            Assert.AreEqual(25, target.Population.Generations.Count);
                        }
                    }
                }
            }
        }