src/GenFx.Components/Scaling/FitnessSharingScalingStrategy.cs
/// <summary>
/// Sets the <see cref="GeneticEntity.ScaledFitnessValue"/> property of each entity
/// in <paramref name="population"/> according to the fitness sharing scaling algorithm.
/// </summary>
/// <param name="population"><see cref="Population"/> containing the <see cref="GeneticEntity"/> objects.</param>
/// <exception cref="ArgumentNullException"><paramref name="population"/> is null.</exception>
Sets the  property of each entity
in  according to the fitness sharing scaling algorithm.
Sets the property of each entity in according to the fitness sharing scaling algorithm .
protected override void UpdateScaledFitnessValues(Population population)
        {
            if (population == null)
            {
                throw new ArgumentNullException(nameof(population));
            }
            int entityCount = population.Entities.Count;
            this.fitnessDistances = new double[(int)Math.Pow(entityCount, 2)];
            for (int i = 0; i < entityCount; i++)
            {
                this.fitnessDistances[(i * entityCount) + 1] = 0;
                for (int j = 0; j < entityCount; j++)
                {
                    this.fitnessDistances[(i * entityCount) + j] =
                        this.fitnessDistances[(j * entityCount) + i] =
                        this.EvaluateFitnessDistance(population.Entities[i], population.Entities[j]);
                }
            }
            for (int i = 0; i < entityCount; i++)
            {
                double sum = 0;
                for (int j = 0; j < entityCount; j++)
                {
                    if (this.fitnessDistances[(i * entityCount) + j] < this.ScalingDistanceCutoff)
                    {
                        sum += 1 - Math.Pow(this.fitnessDistances[(i * entityCount) + j] / this.ScalingDistanceCutoff,
                          this.ScalingCurvature);
                    }
                }
                population.Entities[i].ScaledFitnessValue = population.Entities[i].ScaledFitnessValue / sum;
            }
        }
protected override void UpdateScaledFitnessValues ( Population population ) { if ( population == null ) { throw new ArgumentNullException ( nameof ( population ) ) ; } int entityCount = population . Entities . Count ; this . fitnessDistances = new double [ ( int ) Math . Pow ( entityCount , 2 ) ] ; for ( int i = 0 ; i < entityCount ; i ++ ) { this . fitnessDistances [ ( i * entityCount ) + 1 ] = 0 ; for ( int j = 0 ; j < entityCount ; j ++ ) { this . fitnessDistances [ ( i * entityCount ) + j ] = this . fitnessDistances [ ( j * entityCount ) + i ] = this . EvaluateFitnessDistance ( population . Entities [ i ] , population . Entities [ j ] ) ; } } for ( int i = 0 ; i < entityCount ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < entityCount ; j ++ ) { if ( this . fitnessDistances [ ( i * entityCount ) + j ] < this . ScalingDistanceCutoff ) { sum += 1 - Math . Pow ( this . fitnessDistances [ ( i * entityCount ) + j ] / this . ScalingDistanceCutoff , this . ScalingCurvature ) ; } } population . Entities [ i ] . ScaledFitnessValue = population . Entities [ i ] . ScaledFitnessValue / sum ; } }
Sets the  property of each entity
in  according to the fitness sharing scaling algorithm.
Sets the property of each entity in according to the fitness sharing scaling algorithm .
// Collect the fitness distances between genetic entities
None
population
Population
containing the  objects.
containing the objects .