public void FinishPhaseKeepsIncumbentForMaximumReplacementRate() { // Create population along with an incumbent. var basePopulation = this.CreatePopulation(); var incumbent = this.CreateIncumbentGenomeWrapper(); basePopulation.AddGenome(new Genome(incumbent.IncumbentGenome), isCompetitive: true); // Create strategy with a replacement rate of 1. var configuration = new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder() .SetMaximumNumberParallelEvaluations(1) .AddDetailedConfigurationBuilder( RegressionForestArgumentParser.Identifier, new GenomePredictionRandomForestConfig.GenomePredictionRandomForestConfigBuilder()) .AddDetailedConfigurationBuilder( CovarianceMatrixAdaptationStrategyArgumentParser.Identifier, new CovarianceMatrixAdaptationStrategyConfiguration.CovarianceMatrixAdaptationStrategyConfigurationBuilder() .SetFixInstances(this.FixInstances) .SetReplacementRate(1) .SetMaximumNumberGenerations(30)); this.Strategy = new LocalCovarianceMatrixAdaptationStrategy <TestInstance, IntegerResult>( configuration.Build(), this.ParameterTree, this.GenomeBuilder, this.GenomeSorter, this.ResultStorageActor); // Perform an iteration and finish the phase. this.Strategy.Initialize(basePopulation, incumbent, this.SingleTestInstance); this.Strategy.PerformIteration(0, this.SingleTestInstance); this.Strategy.DumpStatus(); var updatedPopulation = this.Strategy.FinishPhase(basePopulation); // Incumbent should still exist. Assert.True( updatedPopulation.GetCompetitiveIndividuals().Contains(incumbent.IncumbentGenome, new Genome.GeneValueComparator()), "Updated population should contain incumbent, but does not."); // Age structure should be correct. for (int age = 0; age < 3; age++) { Assert.True( basePopulation.GetCompetitiveIndividuals().Count(individual => individual.Age == age) == updatedPopulation.GetCompetitiveIndividuals().Count(individual => individual.Age == age), $"Different number of genomes with age {age}."); } Assert.False( updatedPopulation.GetCompetitiveIndividuals().Any(individual => individual.Age < 0 || individual.Age > 3), "There exists a genome with age not in age range!"); }