public void SigmaScalingStrategy_Scale_Multiplier1() { GeneticAlgorithm algorithm = GetAlgorithm(5); SigmaScalingStrategy strategy = new SigmaScalingStrategy { Multiplier = 1 }; strategy.Initialize(algorithm); SimplePopulation population = new SimplePopulation(); population.Initialize(algorithm); PrivateObject populationAccessor = new PrivateObject(population, new PrivateType(typeof(Population))); AddEntity(algorithm, 4, population); AddEntity(algorithm, 10, population); AddEntity(algorithm, 20, population); AddEntity(algorithm, 0, population); populationAccessor.SetField("rawMean", (double)(4 + 10 + 20) / 4); populationAccessor.SetField("rawStandardDeviation", MathHelper.GetStandardDeviation(population.Entities, population.RawMean.Value, FitnessType.Raw)); strategy.Scale(population); Assert.Equal(3.03, Math.Round(population.Entities[0].ScaledFitnessValue, 2)); Assert.Equal(9.03, Math.Round(population.Entities[1].ScaledFitnessValue, 2)); Assert.Equal(19.03, Math.Round(population.Entities[2].ScaledFitnessValue, 2)); Assert.Equal(0, Math.Round(population.Entities[3].ScaledFitnessValue, 2)); }
public void SigmaScalingStrategy_Scale_NullPopulation() { GeneticAlgorithm algorithm = GetAlgorithm(10); SigmaScalingStrategy op = new SigmaScalingStrategy(); op.Initialize(algorithm); Assert.Throws <ArgumentNullException>(() => op.Scale(null)); }
public void SigmaScalingStrategy_Scale_EmptyPopulation() { GeneticAlgorithm algorithm = GetAlgorithm(10); SigmaScalingStrategy op = new SigmaScalingStrategy(); op.Initialize(algorithm); SimplePopulation population = new SimplePopulation(); population.Initialize(algorithm); Assert.Throws <ArgumentException>(() => op.Scale(population)); }