public void SigmaScalingStrategy_UpdateScaledFitnessValues_NullPopulation() { SigmaScalingStrategy strategy = new SigmaScalingStrategy(); PrivateObject accessor = new PrivateObject(strategy); Assert.Throws <ArgumentNullException>(() => accessor.Invoke("UpdateScaledFitnessValues", (Population)null)); }
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_Serialization() { SigmaScalingStrategy strategy = new SigmaScalingStrategy { Multiplier = 11 }; SigmaScalingStrategy result = (SigmaScalingStrategy)SerializationHelper.TestSerialization(strategy, new Type[0]); Assert.Equal(strategy.Multiplier, result.Multiplier); }
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)); }
public void SigmaScalingStrategy_Ctor_InvalidSetting() { SigmaScalingStrategy config = new SigmaScalingStrategy(); Assert.Throws <ValidationException>(() => config.Multiplier = -2); }
public void SigmaScalingStrategy_Ctor_NullAlgorithm() { SigmaScalingStrategy strategy = new SigmaScalingStrategy(); Assert.Throws <ArgumentNullException>(() => strategy.Initialize(null)); }