示例#1
0
        /// <summary>
        /// Removes or updates the given genome tournament key in the evaluation queue.
        /// </summary>
        /// <param name="genomeTournamentKey">The genome tournament key.</param>
        private void RemoveOrUpdateInPriorityQueue(GenomeTournamentKey genomeTournamentKey)
        {
            if (this._globalPriorityQueue == null)
            {
                // We are in result storage update phase!
                return;
            }

            var genomeStats = this._genomeToGenomeStats[genomeTournamentKey.Genome];

            if (!genomeStats.HasOpenInstances)
            {
                if (this._globalPriorityQueue.Contains(genomeTournamentKey))
                {
                    this._globalPriorityQueue.Remove(genomeTournamentKey);
                }
            }
            else
            {
                var genomePriority = this._runEvaluator
                                     .ComputeEvaluationPriorityOfGenome(
                    this._genomeToGenomeStats[genomeTournamentKey.Genome].ToImmutable());
                this._globalPriorityQueue.UpdatePriority(genomeTournamentKey, genomePriority);
            }
        }
示例#2
0
        /// <summary>
        /// Requeues the given evaluation, if relevant for this mini tournament.
        /// </summary>
        /// <param name="evaluation">The evaluation.</param>
        public void RequeueEvaluationIfRelevant(GenomeInstancePair <TInstance> evaluation)
        {
            lock (this._lock)
            {
                if (!this._genomeToGenomeStats.TryGetValue(evaluation.Genome, out var genomeStats))
                {
                    return;
                }

                var genomeKey      = new GenomeTournamentKey(evaluation.Genome, this.MiniTournamentId);
                var genomePriority = this._runEvaluator.ComputeEvaluationPriorityOfGenome(genomeStats.ToImmutable());

                if (genomeStats.RequeueInstance(evaluation.Instance))
                {
                    if (this._globalPriorityQueue != null)
                    {
                        if (!this._globalPriorityQueue.Contains(genomeKey))
                        {
                            this._globalPriorityQueue.Enqueue(
                                genomeKey,
                                genomePriority);
                        }
                        else
                        {
                            this._globalPriorityQueue.UpdatePriority(genomeKey, genomePriority);
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Tries to get the next instance of the given genome tournament key and updates the evaluation queue.
        /// </summary>
        /// <param name="nextGenomeKey">The next genome tournament key.</param>
        /// <param name="nextInstance">The next instance.</param>
        /// <returns>True, if there is a next instance.</returns>
        public bool TryGetNextInstanceAndUpdateGenomePriority(GenomeTournamentKey nextGenomeKey, out TInstance nextInstance)
        {
            lock (this._lock)
            {
                var genomeStats        = this._genomeToGenomeStats[nextGenomeKey.Genome];
                var hasStartedInstance = genomeStats.TryStartInstance(out nextInstance);

                this.RemoveOrUpdateInPriorityQueue(nextGenomeKey);

                return(hasStartedInstance);
            }
        }
示例#4
0
 /// <summary>
 /// Checks if equal.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns>True, if equal.</returns>
 protected bool Equals(GenomeTournamentKey other)
 {
     return(this.TournamentId == other.TournamentId &&
            ImmutableGenome.GenomeComparer.Equals(this.Genome, other.Genome));
 }