Beispiel #1
0
        public List <Solution> ComputeNextGeneration()
        {
            var nextGeneration = new List <Individual>();

            while (nextGeneration.Count < settings.PopulationSize)
            {
                var parent1 = selectionOperator.SelectOne(CurrentSolutions);
                var parent2 = selectionOperator.SelectOne(CurrentSolutions.Where(x => !ReferenceEquals(x.Individual, parent1)).ToList());

                var offsprings = crossoverOperator.GetOffsprings(parent1, parent2, settings.CrossoverRate);

                mutationOperator.ApplyMutation(offsprings.Item1, settings.MutationRate);
                mutationOperator.ApplyMutation(offsprings.Item2, settings.MutationRate);

                AddIfNotDupplicate(nextGeneration, offsprings.Item1);
                AddIfNotDupplicate(nextGeneration, offsprings.Item2);
            }

            AddElites(nextGeneration);

            currentPopulation = nextGeneration;
            ComputeCurrentGenerationData();

            return(CurrentSolutions);
        }