コード例 #1
0
        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));
        }
コード例 #2
0
        public void SigmaScalingStrategy_Scale_NullPopulation()
        {
            GeneticAlgorithm     algorithm = GetAlgorithm(10);
            SigmaScalingStrategy op        = new SigmaScalingStrategy();

            op.Initialize(algorithm);
            Assert.Throws <ArgumentNullException>(() => op.Scale(null));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public void SigmaScalingStrategy_Ctor_NullAlgorithm()
        {
            SigmaScalingStrategy strategy = new SigmaScalingStrategy();

            Assert.Throws <ArgumentNullException>(() => strategy.Initialize(null));
        }