/// <summary>
        /// Called before every test.
        /// </summary>
        protected override void InitializeDefault()
        {
            base.InitializeDefault();

            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0.25);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);

            var root = new AndNode();

            root.AddChild(new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-1, 3)));
            root.AddChild(new ValueNode <int>("quasi-continuous", new IntegerDomain(0, this._deConfiguration.MinimumDomainSize + 1)));
            this._parameterTree = new ParameterTree(root);

            this._genomeBuilder = new GenomeBuilder(this._parameterTree, this._completeConfiguration);
        }
        public void DefineCompetitivePopulationThrowsForIncumbentChangeOnlyWithoutIncumbent()
        {
            // Create configuration with a replacement rate of 0.
            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);
            var informationFlow = new LocalDifferentialEvolutionInformationFlow(
                this._deConfiguration,
                this._parameterTree,
                this._genomeBuilder);

            // Call defineCompetitivePopulation without an incumbent.
            Assert.Throws <ArgumentNullException>(
                () => informationFlow
                .DefineCompetitivePopulation(
                    originalCompetitives: this.CreateRandomGenomes(number: 6).ToList(),
                    originalIncumbent: null,
                    mostRecentSorting: this.CreateRandomSearchPoints())
                .ToList());
        }
        public void DefineCompetitivePopulationWorksForIncumbentChangeOnly()
        {
            // Create configuration with a replacement rate of 0.
            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);
            var informationFlow = new LocalDifferentialEvolutionInformationFlow(
                this._deConfiguration,
                this._parameterTree,
                this._genomeBuilder);

            // Create a competitive population which contains the same genome twice.
            var originalCompetitives = this.CreateRandomGenomes(number: 6).ToList();
            var incumbent            = originalCompetitives[3];

            originalCompetitives.Add(new Genome(incumbent));
            Assert.Equal(
                2,
                originalCompetitives.Count(individual => new Genome.GeneValueComparator().Equals(individual, incumbent)));

            // Call define competitive population with some search points.
            var searchPoints        = this.CreateRandomSearchPoints();
            var updatedCompetitives = informationFlow.DefineCompetitivePopulation(
                originalCompetitives,
                incumbent,
                searchPoints);

            // Best point should now replace incumbent in competitive population.
            var expectedCompetitives = originalCompetitives
                                       .Select(genome => genome.ToString())
                                       .ToList();

            expectedCompetitives.Remove(incumbent.ToString());
            expectedCompetitives.Add(new Genome(searchPoints[0].Genome.CreateMutableGenome(), incumbent.Age).ToString());
            Assert.Equal(
                expectedCompetitives.OrderBy(x => x).ToArray(),
                updatedCompetitives.Select(genome => genome.ToString()).OrderBy(x => x).ToArray());
        }