src/GenFx/Population.cs
/// <summary>
/// Evaluates the <see cref="GeneticEntity.RawFitnessValue"/> of all the <see cref="GeneticEntity"/> objects
/// within the population followed by evaluation of the <see cref="GeneticEntity.ScaledFitnessValue"/>
/// using the <see cref="FitnessScalingStrategy"/>.
/// </summary>
Evaluates the  of all the  objects
within the population followed by evaluation of the
using the .
Evaluates the of all the objects within the population followed by evaluation of the using the .
public virtual async Task EvaluateFitnessAsync()
        {
            this.AssertIsInitialized();
            double rawSum = 0;
            List<Task> fitnessEvalTasks = new List<Task>();
            foreach (GeneticEntity entity in this.geneticEntities)
            {
                fitnessEvalTasks.Add(entity.EvaluateFitnessAsync());
            }
            await Task.WhenAll(fitnessEvalTasks);
            if (this.Algorithm!.Metrics.Any() || this.Algorithm.FitnessScalingStrategy != null)
            {
                for (int i = 0; i < this.geneticEntities.Count; i++)
                {
                    rawSum += this.geneticEntities[i].RawFitnessValue;
                    if (i == 0 || this.geneticEntities[i].RawFitnessValue > this.rawMax)
                    {
                        this.rawMax = this.geneticEntities[i].RawFitnessValue;
                    }
                    if (i == 0 || this.geneticEntities[i].RawFitnessValue < this.rawMin)
                    {
                        this.rawMin = this.geneticEntities[i].RawFitnessValue;
                    }
                }
                this.rawMean = rawSum / this.geneticEntities.Count;
                this.rawStandardDeviation = MathHelper.GetStandardDeviation(this.geneticEntities, this.rawMean.Value, FitnessType.Raw);
            }
            if (this.Algorithm.FitnessScalingStrategy != null)
            {
                this.Algorithm.FitnessScalingStrategy.Scale(this);
            }
        }
public virtual async Task EvaluateFitnessAsync ( ) { this . AssertIsInitialized ( ) ; double rawSum = 0 ; List < Task > fitnessEvalTasks = new List < Task > ( ) ; foreach ( GeneticEntity entity in this . geneticEntities ) { fitnessEvalTasks . Add ( entity . EvaluateFitnessAsync ( ) ) ; } await Task . WhenAll ( fitnessEvalTasks ) ; if ( this . Algorithm ! . Metrics . Any ( ) || this . Algorithm . FitnessScalingStrategy != null ) { for ( int i = 0 ; i < this . geneticEntities . Count ; i ++ ) { rawSum += this . geneticEntities [ i ] . RawFitnessValue ; if ( i == 0 || this . geneticEntities [ i ] . RawFitnessValue > this . rawMax ) { this . rawMax = this . geneticEntities [ i ] . RawFitnessValue ; } if ( i == 0 || this . geneticEntities [ i ] . RawFitnessValue < this . rawMin ) { this . rawMin = this . geneticEntities [ i ] . RawFitnessValue ; } } this . rawMean = rawSum / this . geneticEntities . Count ; this . rawStandardDeviation = MathHelper . GetStandardDeviation ( this . geneticEntities , this . rawMean . Value , FitnessType . Raw ) ; } if ( this . Algorithm . FitnessScalingStrategy != null ) { this . Algorithm . FitnessScalingStrategy . Scale ( this ) ; } }
Evaluates the  of all the  objects
within the population followed by evaluation of the
using the .
Evaluates the of all the objects within the population followed by evaluation of the using the .
// Wait for all entities to evaluate their fitness values // There's no need to perform these calculations if there aren't any metrics or a fitness scaling strategy. // Calculate the metrics based on raw fitness value // Calculate the metrics based on raw fitness value // Scale the fitness values of the population.