/// <summary> /// Method that receives reports of fitness from the modeler /// </summary> /// <param name="Server"></param> /// <param name="Generation"></param> /// <param name="Stats"></param> private void ReceiveFitness(int Server, int Generation, ModelingResults.ServerData Stats) { // // Update the process with the current modeling stats m_Queue[0].Fitness = Stats.BestFitness; m_Queue[0].Hits = Stats.BestHits; m_Queue[0].Complexity = Stats.BestComplexity; // // TODO: HACK, HACK, HACK and I know it! I'm not proud of it, but I'm doing // it anyway. I'm having trouble synchronizing the registration of new clients // while batch processing is taking place, so this is my hack to deal with it. UpdatePendingRegistrations(); // // Broadcast this information foreach (KeyValuePair <IBatchClient, IBatchClient> Client in m_Clients) { Client.Value.ProcessUpdate(Generation); } }
/// <summary> /// Works through the set of distributed servers, gets the best program /// and records the statistics generated at each server. /// </summary> private void UpdateGenerationResults(int Generation, List <IGPModeler> Modelers, ref List <String> BestPrograms) { // // Collect best program from each modeler BestPrograms = new List <string>(Modelers.Count); for (int ModelerIndex = 0; ModelerIndex < Modelers.Count; ModelerIndex++) { BestPrograms.Add(Modelers[ModelerIndex].BestProgram); } #if GPLOG GPLog.ReportLine("Number of best programs returned: " + BestPrograms.Count, true); #endif m_BestFitness = 1000000000.0; // Some crazy big value m_BestComplexity = 10000000; // Some crazy big value m_BestHits = 0; // Worst possible value #if GPLOG GPLog.ReportLine("Finding Best program among servers...", true); #endif // // Collect the best program and population stats from each server for (int ModelerIndex = 0; ModelerIndex < Modelers.Count; ModelerIndex++) { ModelingResults.ServerData Stats = new ModelingResults.ServerData(); // // Best program Modelers[ModelerIndex].GetBestProgramStats( out Stats.BestFitness, out Stats.BestHits, out Stats.BestComplexity); // // Population stats Modelers[ModelerIndex].GetPopulationStats( out Stats.FitnessMaximum, out Stats.FitnessAverage, out Stats.ComplexityMinimum, out Stats.ComplexityMaximum, out Stats.ComplexityAverage); Stats.FitnessMinimum = Stats.BestFitness; // // Reports this back to the UI if (m_DELReportFitness != null) { m_DELReportFitness(Generation, ModelerIndex, Stats); } #if GPLOG GPLog.ReportLine(" Testing Program - Fitness: " + Stats.BestFitness + " Hits: " + Stats.BestHits + " Complexity: " + Stats.BestComplexity, false); #endif // // Track the best program string if (Stats.BestFitness < m_BestFitness) { m_BestProgram = BestPrograms[ModelerIndex]; m_BestFitness = Stats.BestFitness; m_BestHits = Stats.BestHits; m_BestComplexity = Stats.BestComplexity; } else if (Stats.BestFitness == m_BestFitness && Stats.BestComplexity < m_BestComplexity) { m_BestProgram = BestPrograms[ModelerIndex]; m_BestFitness = Stats.BestFitness; m_BestHits = Stats.BestHits; m_BestComplexity = Stats.BestComplexity; } } #if GPLOG if (BestUpdated) { GPLog.ReportLine(" A best program was found", false); } else { GPLog.ReportLine(" No best program was updated!!", false); GPLog.ReportLine(" Modeler Count: " + Modelers.Count, false); } #endif if (m_DELGenerationComplete != null) { m_DELGenerationComplete(); } }
/// <summary> /// Used to report the last generation stats for each server /// </summary> /// <param name="Generation">Generation of thedata</param> /// <param name="Server">Index of the server being reported</param> /// <param name="Stats">The actual data</param> public void ReportFitness(int Generation, int Server, ModelingResults.ServerData Stats) { // // Record this data in the results object m_ServerData.ReportServerData(Generation, Server, Stats); }