src/GenFx.Components/Algorithms/SteadyStateGeneticAlgorithm.cs
/// <summary>
/// Modifies <paramref name="population"/> to become the next generation of <see cref="GeneticEntity"/> objects.
/// </summary>
/// <param name="population">The current <see cref="Population"/> to be modified.</param>
/// <exception cref="ArgumentNullException"><paramref name="population"/> is null.</exception>
Modifies  to become the next generation of  objects.
Modifies to become the next generation of objects .
protected override Task CreateNextGenerationAsync(Population population)
        {
            if (population == null)
            {
                throw new ArgumentNullException(nameof(population));
            }
            this.AssertIsInitialized();
            int populationCount = population.Entities.Count;
            int replacementCount;
            if (this.PopulationReplacementValue.Kind == ReplacementValueKind.Percentage)
            {
                replacementCount = Convert.ToInt32(
                    Math.Round(
                        populationCount * ((double)this.PopulationReplacementValue.Value / 100)
                    ));
            }
            else
            {
                replacementCount = this.PopulationReplacementValue.Value;
            }
            IList<GeneticEntity> parents = this.ApplySelection(replacementCount, population);
            IList<GeneticEntity> offspring = this.ApplyCrossover(population, parents);
            offspring = this.ApplyMutation(offspring);
            population.Entities.AddRange(offspring.Take(replacementCount));
            ObservableCollection<GeneticEntity> workingGeneticEntities = new ObservableCollection<GeneticEntity>(population.Entities);
            GeneticEntity[] sortedEntities = workingGeneticEntities.GetEntitiesSortedByFitness(
                this.SelectionOperator!.SelectionBasedOnFitnessType,
                this.FitnessEvaluator!.EvaluationMode).ToArray();
            population.Entities.Clear();
            for (int i = sortedEntities.Length - 1; i >= sortedEntities.Length - populationCount; i--)
            {
                population.Entities.Add(sortedEntities[i]);
            }
            return Task.FromResult(true);
        }
protected override Task CreateNextGenerationAsync ( Population population ) { if ( population == null ) { throw new ArgumentNullException ( nameof ( population ) ) ; } this . AssertIsInitialized ( ) ; int populationCount = population . Entities . Count ; int replacementCount ; if ( this . PopulationReplacementValue . Kind == ReplacementValueKind . Percentage ) { replacementCount = Convert . ToInt32 ( Math . Round ( populationCount * ( ( double ) this . PopulationReplacementValue . Value / 100 ) ) ) ; } else { replacementCount = this . PopulationReplacementValue . Value ; } IList < GeneticEntity > parents = this . ApplySelection ( replacementCount , population ) ; IList < GeneticEntity > offspring = this . ApplyCrossover ( population , parents ) ; offspring = this . ApplyMutation ( offspring ) ; population . Entities . AddRange ( offspring . Take ( replacementCount ) ) ; ObservableCollection < GeneticEntity > workingGeneticEntities = new ObservableCollection < GeneticEntity > ( population . Entities ) ; GeneticEntity [ ] sortedEntities = workingGeneticEntities . GetEntitiesSortedByFitness ( this . SelectionOperator ! . SelectionBasedOnFitnessType , this . FitnessEvaluator ! . EvaluationMode ) . ToArray ( ) ; population . Entities . Clear ( ) ; for ( int i = sortedEntities . Length - 1 ; i >= sortedEntities . Length - populationCount ; i -- ) { population . Entities . Add ( sortedEntities [ i ] ) ; } return Task . FromResult ( true ) ; }
Modifies  to become the next generation of  objects.
Modifies to become the next generation of objects .
// Add a select number of potentially modified Entities to the new generation. // Remove the weakest Entities from the population.
None
population
Population
The current  to be modified.
The current to be modified .