src/GenFx.Components.Tests/FitnessSharingScalingStrategyTest.cs
/// <summary>
/// Tests that the Scale method works correctly.
/// </summary>
Tests that the Scale method works correctly.
Tests that the Scale method works correctly .
[Fact]
        public void FitnessSharingScalingStrategy_Scale()
        {
            double scalingCurvature = .8;
            double scalingDistance = 3;
            GeneticAlgorithm algorithm = GetAlgorithm(scalingCurvature, scalingDistance);
            FakeFitnessSharingScalingStrategy strategy = (FakeFitnessSharingScalingStrategy)algorithm.FitnessScalingStrategy;
            strategy.Initialize(algorithm);
            SimplePopulation population = new SimplePopulation();
            population.Initialize(algorithm);
            GeneticEntity entity1 = AddEntity(algorithm, population, 5);
            GeneticEntity entity2 = AddEntity(algorithm, population, 6);
            GeneticEntity entity3 = AddEntity(algorithm, population, 9);
            GeneticEntity entity4 = AddEntity(algorithm, population, 11.5);
            GeneticEntity entity5 = AddEntity(algorithm, population, 20);
            GeneticEntity entity6 = AddEntity(algorithm, population, 25);
            strategy.Scale(population);
            ValidateScale(entity1, 3.16);
            ValidateScale(entity2, 3.79);
            ValidateScale(entity3, 7.92);
            ValidateScale(entity4, 10.13);
            ValidateScale(entity5, 20);
            ValidateScale(entity6, 25);
            GeneticEntity entity7 = AddEntity(algorithm, population, 10);
            strategy.Scale(population);
            ValidateScale(entity1, 1.84);
            ValidateScale(entity2, 2.21);
            ValidateScale(entity3, 5.37);
            ValidateScale(entity4, 4.73);
            ValidateScale(entity5, 20);
            ValidateScale(entity6, 25);
            ValidateScale(entity7, 4.6);
        }
[ Fact ] public void FitnessSharingScalingStrategy_Scale ( ) { double scalingCurvature = .8 ; double scalingDistance = 3 ; GeneticAlgorithm algorithm = GetAlgorithm ( scalingCurvature , scalingDistance ) ; FakeFitnessSharingScalingStrategy strategy = ( FakeFitnessSharingScalingStrategy ) algorithm . FitnessScalingStrategy ; strategy . Initialize ( algorithm ) ; SimplePopulation population = new SimplePopulation ( ) ; population . Initialize ( algorithm ) ; GeneticEntity entity1 = AddEntity ( algorithm , population , 5 ) ; GeneticEntity entity2 = AddEntity ( algorithm , population , 6 ) ; GeneticEntity entity3 = AddEntity ( algorithm , population , 9 ) ; GeneticEntity entity4 = AddEntity ( algorithm , population , 11.5 ) ; GeneticEntity entity5 = AddEntity ( algorithm , population , 20 ) ; GeneticEntity entity6 = AddEntity ( algorithm , population , 25 ) ; strategy . Scale ( population ) ; ValidateScale ( entity1 , 3.16 ) ; ValidateScale ( entity2 , 3.79 ) ; ValidateScale ( entity3 , 7.92 ) ; ValidateScale ( entity4 , 10.13 ) ; ValidateScale ( entity5 , 20 ) ; ValidateScale ( entity6 , 25 ) ; GeneticEntity entity7 = AddEntity ( algorithm , population , 10 ) ; strategy . Scale ( population ) ; ValidateScale ( entity1 , 1.84 ) ; ValidateScale ( entity2 , 2.21 ) ; ValidateScale ( entity3 , 5.37 ) ; ValidateScale ( entity4 , 4.73 ) ; ValidateScale ( entity5 , 20 ) ; ValidateScale ( entity6 , 25 ) ; ValidateScale ( entity7 , 4.6 ) ; }
Tests that the Scale method works correctly.
Tests that the Scale method works correctly .
// Change the population size to verify fitness distances are recalculated