Example #1
0
 /// <summary>
 /// Initially, all genome instance evaluations are considered "running", while results are fetched from <see cref="ResultStorageActor{TInstance,TResult}"/>.
 /// For testing, this step is skipped an all evaluations need to be requeued.
 /// </summary>
 /// <param name="manager">The manager to update.</param>
 private void RequeueAllEvaluations(MiniTournamentManager <TestInstance, ContinuousResult> manager)
 {
     foreach (var genomeInstancePair in this._instances.SelectMany(
                  i => manager.Participants.Select(p => new GenomeInstancePair <TestInstance>(p, i))))
     {
         manager.RequeueEvaluationIfRelevant(genomeInstancePair);
     }
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MiniTournamentManagerTest"/> class.
        /// </summary>
        public MiniTournamentManagerTest()
        {
            this._instances    = Enumerable.Range(0, 5).Select(i => new TestInstance($"{i}")).ToList();
            this._participants = this.CreateGenomesDescendingByAge(8, 0).ToList();
            this._globalQueue  = new SimplePriorityQueue <GenomeTournamentKey, double>();
            this._runEvaluator = new KeepSuggestedOrder <TestInstance, ContinuousResult>();

            this._defaultManager = new MiniTournamentManager <TestInstance, ContinuousResult>(
                this._participants,
                this._instances,
                42,
                0,
                this._runEvaluator,
                false,
                1);
        }
Example #3
0
        public void RacingRemovesKilledGenomesFromQueue()
        {
            var participants = this.CreateGenomesDescendingByAge(2, 0).ToList();
            var instances    = this._instances.Take(2).ToList();
            var queue        = new SimplePriorityQueue <GenomeTournamentKey, double>();

            // always return second genome as target to kill by racing.
            var evaluatorMock = new Mock <IRunEvaluator <TestInstance, ContinuousResult> >();

            evaluatorMock.Setup(
                e => e.GetGenomesThatCanBeCancelledByRacing(
                    It.IsAny <IReadOnlyList <ImmutableGenomeStats <TestInstance, ContinuousResult> > >(),
                    It.IsAny <int>()))
            .Returns(new[] { participants[1] });

            var manager = new MiniTournamentManager <TestInstance, ContinuousResult>(
                participants,
                instances,
                0,
                0,
                evaluatorMock.Object,
                true,
                1);

            this.RequeueAllEvaluations(manager);
            manager.StartSynchronizingQueue(queue);

            queue.Count.ShouldBe(2);

            // start an instance
            var winnerGenome = new GenomeTournamentKey(participants[0], 0);

            manager.TryGetNextInstanceAndUpdateGenomePriority(winnerGenome, out var instance).ShouldBeTrue();

            // send a result
            var result             = new ContinuousResult(42, TimeSpan.Zero);
            var genomeInstancePair = new GenomeInstancePair <TestInstance>(winnerGenome.Genome, instance);

            manager.UpdateResult(genomeInstancePair, result);

            // second genome should have been killed by racing + removed from queue
            queue.Count.ShouldBe(1);
            queue.First.ShouldBe(winnerGenome);
        }