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."); }
public void BoltzmannSelectionOperator_Ctor() { double initialTemp = 10; GeneticAlgorithm algorithm = GetMockAlgorithm(initialTemp); FakeBoltzmannSelectionOperator op = new FakeBoltzmannSelectionOperator { InitialTemperature = initialTemp }; op.Initialize(algorithm); Assert.Equal(initialTemp, op.GetTemp()); }
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)); }
public void BoltzmannSelectionOperator_Temperature() { double initialTemp = 10; MockGeneticAlgorithm algorithm = GetMockAlgorithm(initialTemp); FakeBoltzmannSelectionOperator op = (FakeBoltzmannSelectionOperator)algorithm.SelectionOperator; op.Initialize(algorithm); double currentTemp = initialTemp; for (int i = 0; i < 10; i++) { algorithm.RaiseGenerationCreatedEvent(); Assert.Equal(op.GetTemp(), currentTemp + 1); currentTemp++; } }