Example #1
0
        /// <summary>
        /// Uses a status dump.
        /// </summary>
        /// <param name="currentStrategyIndex">
        /// Index of the current <see cref="IPopulationUpdateStrategy{TInstance,TResult}"/> in
        /// <see cref="_populationUpdateStrategies"/>.
        /// </param>
        /// <param name="population">The population as stored in <see cref="BasePopulation"/>.</param>
        /// <param name="geneticEngineering">
        /// Reference to genetic engineering used by
        /// <see cref="AlgorithmTuner{TTargetAlgorithm,TInstance,TResult,TModelLearner,TPredictorModel,TSamplingStrategy}"/>.
        /// </param>
        public void UseStatusDump(int currentStrategyIndex, Population population, IGeneticEngineering geneticEngineering)
        {
            this.CurrentUpdateStrategyIndex = currentStrategyIndex;
            this.BasePopulation             = population;

            // Restore status of all population update strategies.
            foreach (var strategy in this._populationUpdateStrategies)
            {
                strategy.UseStatusDump(geneticEngineering);
            }
        }
Example #2
0
        /// <inheritdoc />
        public override void UseStatusDump(IGeneticEngineering evaluationModel)
        {
            // The CMA-ES runner must be reinitialized for every phase in order to use the correct genome as base.
            // Recreate the latest runner.
            var strategyStatus    = this.DeserializeStrategyStatusFile();
            var originalIncumbent = strategyStatus.OriginalIncumbent;

            if (originalIncumbent != null)
            {
                this._cmaEsRunner = this.CreateCmaEsRunner(evaluationBase: originalIncumbent);
            }

            base.UseStatusDump(evaluationModel);
        }
Example #3
0
        /// <inheritdoc />
        public virtual void UseStatusDump(IGeneticEngineering evaluationModel)
        {
            var strategyStatus = this.DeserializeStrategyStatusFile();

            this.OriginalIncumbent          = strategyStatus.OriginalIncumbent;
            this.MostRecentSorting          = strategyStatus.MostRecentSorting?.Select(point => point.Restore()).ToList();
            this.CurrentEvaluationInstances = strategyStatus.CurrentEvaluationInstances;

            // Instances must be updated in case they are fixed, i.e. only updated at initialization.
            if (this.CurrentEvaluationInstances != null)
            {
                this.SearchPointSorter.UpdateInstances(this.CurrentEvaluationInstances);
            }

            this.ContinuousOptimizer.UseStatusDump(this.ContinuousOptimizerStatusFilePath);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GgaStrategy{TInstance, TResult}"/> class.
        /// </summary>
        /// <param name="configuration">Options used for this instance.</param>
        /// <param name="parameterTree">Provides the tuneable parameters.</param>
        /// <param name="genomeBuilder">Responsible for creation, modification and crossover of genomes.
        /// Needs to be compatible with the given parameter tree and configuration.</param>
        /// <param name="tournamentSelector">An <see cref="IActorRef" /> to a
        /// <see cref="GenerationEvaluationActor{TTargetAlgorithm,TInstance,TResult}" /> which decides which competitive
        /// genomes are allowed to reproduce.</param>
        /// <param name="geneticEngineering">Object which trains a model and enables model-based crossovers.</param>
        public GgaStrategy(
            AlgorithmTunerConfiguration configuration,
            ParameterTree parameterTree,
            GenomeBuilder genomeBuilder,
            IActorRef tournamentSelector,
            IGeneticEngineering geneticEngineering)
        {
            this._configuration      = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._parameterTree      = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree));
            this._genomeBuilder      = genomeBuilder ?? throw new ArgumentNullException(nameof(genomeBuilder));
            this._tournamentSelector = tournamentSelector ?? throw new ArgumentNullException(nameof(tournamentSelector));
            this._geneticEngineering = geneticEngineering ?? throw new ArgumentNullException(nameof(geneticEngineering));

            this.AllKnownRanks = new Dictionary <Genome, List <GenomeTournamentRank> >(
                3 * this._configuration.PopulationSize,
                Genome.GenomeComparer);
        }
Example #5
0
        /// <summary>
        /// Called before every test case.
        /// </summary>
        protected override void InitializeDefault()
        {
            this._configuration      = this.GetDefaultAlgorithmTunerConfiguration();
            this._genomeBuilder      = new ValueGenomeBuilder(this._parameterTree, this._configuration, this._genomeValues);
            this._geneticEngineering =
                new GeneticEngineering <StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>,
                                        ReuseOldTreesStrategy>(
                    this._parameterTree,
                    this._configuration);

            this.ActorSystem         = ActorSystem.Create(TestBase.ActorSystemName, this._configuration.AkkaConfiguration);
            this._resultStorageActor = this.ActorSystem.ActorOf(
                Props.Create(
                    () => new ResultStorageActor <TestInstance, IntegerResult>()),
                AkkaNames.ResultStorageActor);
            this._generationEvaluationActor = this.CreateTournamentSelector(
                this.ActorSystem,
                new ExtractIntegerValueCreator(),
                new TargetAlgorithm.InterfaceImplementations.ValueConsideration.SortByDescendingIntegerValue <TestInstance>());
        }
Example #6
0
        /// <summary>
        /// Reads all internal data from file.
        /// </summary>
        /// <param name="evaluationModel">Reference to up-to-date evaluation model.</param>
        public void UseStatusDump(IGeneticEngineering evaluationModel)
        {
            // Update evaluation model.
            this._geneticEngineering = evaluationModel;

            // Read status from file.
            var status = StatusBase.ReadFromFile <GgaStatus>(this.StatusFilePath);

            this._population           = status.Population;
            this._iterationCounter     = status.IterationCounter;
            this._incumbentKeptCounter = status.IncumbentKeptCounter;
            this.AllKnownRanks         = status.AllKnownRanks;

            // somehow, the equality comparer is not restored properly.
            // fix this.
            var restoredRanks = this.AllKnownRanks.GroupBy(kr => kr.Key, Genome.GenomeComparer).ToDictionary(
                grp => grp.Key,
                grp => grp.SelectMany(ranks => ranks.Value).ToList(),
                Genome.GenomeComparer);

            this.AllKnownRanks = restoredRanks;
        }