/// <summary> /// Resets all fields that change between two different commands. /// </summary> protected override void ResetCommandSpecificFields() { LoggingHelper.WriteLine(VerbosityLevel.Info, $"{this.Self.Path}: Finished a tournament."); // Reset timeout. this.EvaluationActorRouter.Tell(new Broadcast(new ResetTimeout())); this._miniTournament = null; this._currentlyFinishedEvaluations.Clear(); base.ResetCommandSpecificFields(); }
public void ParticipantsAreSetCorrectly() { // Set participants in constructor. var participants = new List <ImmutableGenome>() { new ImmutableGenome(new Genome()) }; var message = new MiniTournament(participants, tournamentId: 0); // Check gene values of messages' participants are equal to the original ones. Assert.True( participants.SequenceEqual(message.Participants), "Some participant has different gene values than the ones that have been provided in the constructor."); }
/// <summary> /// Actor is ready to process mini tournaments. /// </summary> protected override void Ready() { // Polls are accepted. this.Receive <Poll>(poll => this.Sender.Tell(new Accept())); // Switch to working state if a mini tournament was sent. this.Receive <MiniTournament>( tournament => { this._miniTournament = tournament; this.CommandIssuer = this.Sender; this.BecomeWorking(); }); // Switch to waiting for configuration state if instances are reset. this.Receive <ClearInstances>( update => { this._instancesForEvaluation.Clear(); this.EvaluationActorRouter.Tell(new Broadcast(update)); this.Become(this.WaitForInstances); }); // Instance updates without earlier reset indicate missing messages. this.Receive <AddInstances <TInstance> >( update => { this.Sender.Tell(new InstancesRequest()); this.Become(this.WaitForInstances); }); this.Receive <InstanceUpdateFinished>( update => { this.Sender.Tell(new InstancesRequest()); this.Become(this.WaitForInstances); }); // Evaluation actors might ask for instances. this.Receive <InstancesRequest>( request => { foreach (var message in UpdateInstances.CreateInstanceUpdateMessages(this.InstancesForEvaluation)) { this.Sender.Tell(message); } }); }
/// <summary> /// Creates random disjunct mini tournaments covering all genomes that have been part of the /// <see cref="_selectCommand" />. /// The mini tournament size is at most <see cref="AlgorithmTunerConfiguration.MaximumMiniTournamentSize"/>. /// </summary> /// <returns>The mini tournaments.</returns> private List <MiniTournament> CreateMiniTournamentsOutOfSelectionCommand() { // Find number of mini tournaments that have to be held // s.t. no mini tournament exceeds the number of available cores per node. var maximumTournamentSize = this._configuration.MaximumMiniTournamentSize; var numberParticipants = this._selectCommand.Participants.Count; var numberTournaments = (int)Math.Ceiling((double)numberParticipants / maximumTournamentSize); // Balance the tournaments and find how many of them will have to be enlarged by one in order for all the // genomes to be mapped to a mini tournament. var balancedTournamentSize = numberParticipants / numberTournaments; var numberEnlargedTournaments = numberParticipants % numberTournaments; // Create list of mini tournaments: var miniTournaments = new List <MiniTournament>(numberTournaments); // Shuffle participants to get random subsets (for mini tournaments) when slicing. List <ImmutableGenome> participants = Randomizer.Instance.ChooseRandomSubset(this._selectCommand.Participants, numberParticipants).ToList(); lock (this._genomeToTournamentResultsLock) { // For numberTournaments times, ... var nextFirstIndex = 0; for (var i = 0; i < numberTournaments; i++) { // ...determine the tournament size... var tournamentSize = i < numberEnlargedTournaments ? balancedTournamentSize + 1 : balancedTournamentSize; // ...and take the next genomes from participants to create a mini tournament. var tournament = new MiniTournament(participants.GetRange(nextFirstIndex, tournamentSize), this.NextTournamentId()); miniTournaments.Add(tournament); // Finally update the index for the first genome in the next tournament. nextFirstIndex += tournamentSize; } } // Return the created list. return(miniTournaments); }
public void ParticipantCollectionIsImmutable() { // Create message. var originalParticipants = new List <ImmutableGenome>() { new ImmutableGenome(new Genome()) }; var message = new MiniTournament(originalParticipants, tournamentId: 0); // Precondition: Same genes. Assert.True(originalParticipants.SequenceEqual(message.Participants)); // Change original participants. originalParticipants.RemoveAt(0); // Check genes are now different. Assert.False( originalParticipants.SequenceEqual(message.Participants), "Participants have been changed even if message is supposed to be immutable."); }
/// <summary> /// Adds an assignment. /// </summary> /// <param name="assignee">The assignee.</param> /// <param name="miniTournament">The mini tournament.</param> public void AddAssignment(IActorRef assignee, MiniTournament miniTournament) { this._assignedMiniTournaments.Add(assignee, miniTournament); }