public void InstancesAreOnlyUpdatedOncePerPhaseIfConfigurationIndicatesThat()
        {
            // Create configuration which determines that instances should be fixed in each phase.
            this.FixInstances  = true;
            this.Configuration = this.CreateTunerConfigurationBuilder().Build();
            this.Strategy      = this.CreateStrategy(this.Configuration);

            var severalInstances = new List <TestInstance> {
                new TestInstance("c"), new TestInstance("d")
            };
            var population = this.CreatePopulation();

            // Start first phase.
            this.Strategy.Initialize(population, this.CreateIncumbentGenomeWrapper(), this.SingleTestInstance);
            this.Strategy.PerformIteration(0, severalInstances);
            this.Strategy.DumpStatus();

            // Check instances have not been updated.
            var incumbent = this.Strategy.FindIncumbentGenome();

            Assert.Single(
                incumbent.IncumbentInstanceResults);

            // Start second phase.
            this.Strategy.Initialize(population, this.CreateIncumbentGenomeWrapper(), severalInstances);
            this.Strategy.PerformIteration(0, this.SingleTestInstance);
            this.Strategy.DumpStatus();

            // Instances should have been updated now.
            incumbent = this.Strategy.FindIncumbentGenome();
            Assert.Equal(
                2,
                incumbent.IncumbentInstanceResults.Count);
        }
        public void UseStatusDumpUpdatesEvaluationInstances()
        {
            // Create configuration which determines that instances should be fixed in each phase.
            // This makes sure that the update is required.
            this.FixInstances  = true;
            this.Configuration = this.CreateTunerConfigurationBuilder().Build();
            this.Strategy      = this.CreateStrategy(this.Configuration);

            // Use the strategy.
            var severalInstances = new List <TestInstance> {
                new TestInstance("c"), new TestInstance("d")
            };

            this.Strategy.Initialize(this.CreatePopulation(), this.CreateIncumbentGenomeWrapper(), severalInstances);
            this.Strategy.PerformIteration(0, severalInstances);
            this.Strategy.DumpStatus();

            // Create new strategy to read the status dump.
            var newStrategy = this.CreateStrategy(this.Configuration);

            newStrategy.UseStatusDump(null);
            newStrategy.PerformIteration(0, severalInstances);

            // Check instances are as before.
            var incumbent = newStrategy.FindIncumbentGenome();

            Assert.Equal(
                2,
                incumbent.IncumbentInstanceResults.Count);
        }
        /// <summary>
        /// Updates <see cref="_informationHistory"/> with the current (finished) generation.
        /// </summary>
        /// <param name="currentStrategy">The current strategy.</param>
        private void UpdateGenerationHistory(IPopulationUpdateStrategy <TInstance, TResult> currentStrategy)
        {
            var evaluationCountRequest =
                this._targetRunResultStorage.Ask <EvaluationStatistic>(new EvaluationStatisticRequest());

            evaluationCountRequest.Wait();

            var generationInformation = new GenerationInformation(
                generation: this._currGeneration,
                totalNumberOfEvaluations: evaluationCountRequest.Result.TotalEvaluationCount,
                strategy: currentStrategy.GetType(),
                incumbent: new ImmutableGenome(this._incumbentGenomeWrapper.IncumbentGenome));

            this._informationHistory.Add(generationInformation);
        }
        /// <summary>
        /// Called before every test case.
        /// </summary>
        protected override void InitializeDefault()
        {
            this.Configuration = this.CreateTunerConfigurationBuilder().Build();
            this.ActorSystem   = ActorSystem.Create(TestBase.ActorSystemName, this.Configuration.AkkaConfiguration);

            // Create parameter tree with quasi-continuous and categorical parameters.
            var root = new AndNode();

            root.AddChild(
                new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-6, 143)));
            root.AddChild(
                new ValueNode <string>("categorical", new CategoricalDomain <string>(new List <string> {
                "a", "b"
            })));
            this.ParameterTree = new ParameterTree(root);

            this.GenomeSorter = this.ActorSystem.ActorOf(
                Props.Create(() => new GenomeSorter <TestInstance, IntegerResult>(this.RunEvaluator)),
                AkkaNames.GenomeSorter);

            this.ResultStorageActor = this.ActorSystem.ActorOf(
                Props.Create(() => new ResultStorageActor <TestInstance, IntegerResult>()),
                AkkaNames.ResultStorageActor);
            this.TournamentSelector = this.ActorSystem.ActorOf(
                Props.Create(
                    () => new TournamentSelector <ExtractIntegerValue, TestInstance, IntegerResult>(
                        new ExtractIntegerValueCreator(),
                        this.RunEvaluator,
                        this.Configuration,
                        this.ResultStorageActor,
                        this.ParameterTree)),
                AkkaNames.TournamentSelector);

            this.GenomeBuilder = new ValueGenomeBuilder(this.ParameterTree, this.Configuration, this._genomeValues);

            this.Strategy = this.CreateStrategy(this.Configuration);
        }