/// <summary> /// Preps for evaluation via decoding agents to their phenome representation and creating a separate evaluation unit /// for each non-evaluated agent/maze combination. /// </summary> /// <param name="agents">The agents that are in the queue at the given time.</param> public void Initialize(IEnumerable <MccexperimentNavigatorGenome> agents) { // Build a separate evaluation unit for each agent/maze combination, but only consider those agents // who have not already been evaluated foreach ( var serializedAgent in agents.Where(agentGenome => _agentGenomeIds.Contains(agentGenome.GenomeId) == false)) { NeatGenome agentGenome; // Read in the current navigator agent genome using (var xmlReader = XmlReader.Create(new StringReader(serializedAgent.GenomeXml))) { agentGenome = NeatGenomeXmlIO.ReadSingleGenomeFromRoot(xmlReader, false, _neatGenomeFactory); } // Iterate through every maze and add an evaluation unit for that maze and the agent foreach (var maze in _mazeIdStructureMap) { // Only need to decode the agent genome as the mazes have already been decoded EvaluationUnits.Add(new MazeNavigatorEvaluationUnit(maze.Value, _agentDecoder.Decode(agentGenome), maze.Key, serializedAgent.GenomeId)); } // Add the agent genome ID to the list of agents that have been evaluated _agentGenomeIds.Add(serializedAgent.GenomeId); } }
/// <summary> /// Preps for running the maze navigation simulations by decoding the given maze/navigator combinations genomes. These /// are presumably combinations that were determined to be successful in solving the respective maze. /// </summary> /// <param name="navigationCombos">The combinations of mazes and navigators.</param> public void Initialize( IEnumerable <Tuple <MccexperimentMazeGenome, MccexperimentNavigatorGenome> > navigationCombos) { foreach (var navigationCombo in navigationCombos) { MazeGenome mazeGenome; NeatGenome navigatorGenome; // Deserialize the maze XML into a maze genome using (var xmlReader = XmlReader.Create(new StringReader(navigationCombo.Item1.GenomeXml))) { mazeGenome = MazeGenomeXmlIO.ReadSingleGenomeFromRoot(xmlReader, _mazeGenomeFactory); } // Deserialize the navigator XML into a NEAT genome using (var xmlReader = XmlReader.Create(new StringReader(navigationCombo.Item2.GenomeXml))) { navigatorGenome = NeatGenomeXmlIO.ReadSingleGenomeFromRoot(xmlReader, false, _neatGenomeFactory); } // Decode to maze and navigator phenomes and add to the evaluation units list EvaluationUnits.Add(new MazeNavigatorEvaluationUnit(_mazeDecoder.Decode(mazeGenome), _agentDecoder.Decode(navigatorGenome), navigationCombo.Item1.GenomeId, navigationCombo.Item2.GenomeId)); } }
/// <summary> /// Preps for running the maze navigation simulations by constructing all combinations of mazes/navigators that need to /// be evaluated in tandem. /// </summary> /// <param name="mazes">The mazes that were in the maze queue during the given batch.</param> /// <param name="navigators">The navigators that were in the navigator queue during the given batch.</param> public void Initialize(IEnumerable <MccexperimentMazeGenome> mazes, IList <MccexperimentNavigatorGenome> navigators) { IList <NeatGenome> cachedAgents = new List <NeatGenome>(navigators.Count); foreach (var serializedMaze in mazes) { MazeGenome mazeGenome; // Deserialize the maze XML into a maze genome using (var xmlReader = XmlReader.Create(new StringReader(serializedMaze.GenomeXml))) { mazeGenome = MazeGenomeXmlIO.ReadSingleGenomeFromRoot(xmlReader, _mazeGenomeFactory); } // If no agents have been deserialized yet, we need to parse the XML and load the genotype list if (cachedAgents.Count < 1) { // Go through every serialized navigator genome, deserialize it, and use it with the maze to build // a new evaluation unit foreach (var serializedNavigator in navigators) { NeatGenome agentGenome; // Read in the current navigator agent genome using (var xmlReader = XmlReader.Create(new StringReader(serializedNavigator.GenomeXml))) { agentGenome = NeatGenomeXmlIO.ReadSingleGenomeFromRoot(xmlReader, false, _neatGenomeFactory); } // Decode to maze and navigator phenomes and add to the evaluation units list EvaluationUnits.Add(new MazeNavigatorEvaluationUnit(_mazeDecoder.Decode(mazeGenome), _agentDecoder.Decode(agentGenome), serializedMaze.GenomeId, serializedNavigator.GenomeId)); // Also add to the list of cached genomes cachedAgents.Add(agentGenome); } } // Otherwise, skip the deserialization process else { // Add each genome with the current maze to create new evaluation units foreach (var cachedAgent in cachedAgents) { EvaluationUnits.Add(new MazeNavigatorEvaluationUnit(_mazeDecoder.Decode(mazeGenome), _agentDecoder.Decode(cachedAgent), serializedMaze.GenomeId, (int)cachedAgent.Id)); } } } }