Beispiel #1
0
        public void BoltzmannSelectionOperator_Select()
        {
            double           initialTemp = 10;
            GeneticAlgorithm algorithm   = GetMockAlgorithm(initialTemp);

            FakeBoltzmannSelectionOperator op = (FakeBoltzmannSelectionOperator)algorithm.SelectionOperator;

            op.Initialize(algorithm);
            MockPopulation population = new MockPopulation();

            population.Initialize(algorithm);

            MockEntity entity1 = new MockEntity();

            entity1.Initialize(algorithm);
            population.Entities.Add(entity1);

            MockEntity entity2 = new MockEntity();

            entity2.Initialize(algorithm);
            population.Entities.Add(entity2);

            IEnumerable <GeneticEntity> entities = op.SelectEntities(2, population);

            Assert.NotNull(entities);
            Assert.True(entities.Count() > 0, "An entity should have been selected.");
        }
Beispiel #2
0
        public void BoltzmannSelectionOperator_Select_Overflow()
        {
            double initialTemp = .0000001;
            MockGeneticAlgorithm           algorithm = GetMockAlgorithm(initialTemp);
            FakeBoltzmannSelectionOperator op        = new FakeBoltzmannSelectionOperator();

            op.Initialize(algorithm);
            MockPopulation population = new MockPopulation();

            population.Initialize(algorithm);
            MockEntity entity = new MockEntity();

            entity.Initialize(algorithm);
            entity.ScaledFitnessValue = 1;
            population.Entities.Add(entity);
            Assert.Throws <OverflowException>(() => op.SelectEntities(1, population));
        }