コード例 #1
0
        private IList <Individual> generateNewPopulation(int populationSize, double crossoverProb, int tournamentSize)
        {
            IList <Individual> newPopulation = new List <Individual>(populationSize);

            //newPopulation.Add(BestIndividual);
            while (newPopulation.Count < populationSize)
            {
                Individual firstParent  = selection.PerformSelection(population, tournamentSize);
                Individual secondParent = selection.PerformSelection(population, tournamentSize);

                if (randomGenerator.NextDouble() < crossoverProb)
                {
                    IList <Individual> children = crossover.DoCrossover(firstParent, secondParent);
                    newPopulation = newPopulation.Concat(children).ToList();
                }
                else
                {
                    newPopulation.Add(new Individual {
                        Order = firstParent.Order
                    });
                    newPopulation.Add(new Individual {
                        Order = secondParent.Order
                    });
                }
            }

            return(newPopulation);
        }