示例#1
0
        /// <summary>
        /// Waiting for evaluation state.
        /// </summary>
        private void WaitingForEvaluation()
        {
            this.Receive <GenomeInstancePairEvaluation <TInstance> >(
                evaluation =>
            {
                this._currentEvaluation = evaluation;
                this._evaluationTries   = 0;
                this.ConfigureTargetAlgorithm();
                this.Become(this.Evaluating);
                this.StartEvaluation();
            });

            this.Receive <NoJob>(
                noJob => { this.Become(this.Ready); });
        }
示例#2
0
        /// <inheritdoc />
        public bool TryPopEvaluation(out GenomeInstancePairEvaluation <TInstance> nextEvaluation)
        {
            if (this._priorityQueue.Count <= 0)
            {
                nextEvaluation = null;
                return(false);
            }

            var nextGenomeKey = this._priorityQueue.First;
            var associatedTournamentManager = this._tournamentManagers.FirstOrDefault(tm => tm.MiniTournamentId == nextGenomeKey.TournamentId);

            if (associatedTournamentManager == null)
            {
                var exception = new InvalidOperationException($"Cannot find a MiniTournamentManager with ID {nextGenomeKey.TournamentId}!");
                LoggingHelper.WriteLine(
                    VerbosityLevel.Warn,
                    $"Error: {exception.Message}");
                throw exception;
            }

            if (!associatedTournamentManager.TryGetNextInstanceAndUpdateGenomePriority(nextGenomeKey, out var nextInstance))
            {
                nextEvaluation = null;
                return(false);
            }

            var nextGenomeInstancePair = new GenomeInstancePair <TInstance>(nextGenomeKey.Genome, nextInstance);

            foreach (var manager in this._tournamentManagers.Where(tm => tm.MiniTournamentId != associatedTournamentManager.MiniTournamentId))
            {
                manager.NotifyEvaluationStarted(nextGenomeInstancePair);
            }

            nextEvaluation = new GenomeInstancePairEvaluation <TInstance>(
                nextGenomeInstancePair,
                this._generation,
                associatedTournamentManager.MiniTournamentId,
                this._useGrayBoxInGeneration);
            return(true);
        }
示例#3
0
        /// <summary>
        /// Tries to pop the next evaluation to perform.
        /// Only returns evaluations, after <see cref="BecomeWorking"/> has been called.
        /// </summary>
        /// <param name="nextEvaluation">The next evaluation.</param>
        /// <returns><c>true</c>, if an evaluation has been popped.</returns>
        public bool TryPopEvaluation(out GenomeInstancePairEvaluation <TInstance> nextEvaluation)
        {
            if (!this._hasStartedWorking)
            {
                nextEvaluation = null;
                return(false);
            }

            if (this.IsGenerationFinished)
            {
                nextEvaluation = null;
                return(false);
            }

            var nextGenomeStats = this._genomeToGenomeStats.Values.FirstOrDefault(gs => gs.HasOpenInstances);

            if (nextGenomeStats == null)
            {
                nextEvaluation = null;
                return(false);
            }

            if (!nextGenomeStats.TryStartInstance(out var nextInstance))
            {
                var exception = new InvalidOperationException(
                    $"The GenomeStats for Genome {Environment.NewLine}{nextGenomeStats.Genome}{Environment.NewLine} reports that it has open instances, but fails to pop the next instance for evaluation.");
                LoggingHelper.WriteLine(
                    VerbosityLevel.Warn,
                    $"Error: {exception.Message}");
                throw exception;
            }

            nextEvaluation = new GenomeInstancePairEvaluation <TInstance>(
                new GenomeInstancePair <TInstance>(nextGenomeStats.Genome, nextInstance),
                this._generation,
                0,
                this._useGrayBoxInGeneration);
            return(true);
        }