/// <summary> /// This is specially useful since it is possible that startevolution will be called /// after stop evolution (because stopping is not instantaneous!) /// </summary> static void SaveDataIfRunning(string userName) { if (ActiveUsersList <NeatGenome> .IsUserRunning(userName)) { PopulationReadWrite.SavePopulation(userName); } }
static void StartAndRunEvolution(string userName) { StartEvolution(userName); while (ActiveUsersList <NeatGenome> .IsUserRunning(userName)) { } System.Diagnostics.Debug.WriteLine("User: "******". End evolution: " + DateTime.Now.ToString()); }
static void TryLaunchEvolution(Action <string> launchDelegate, string userName) { if (!ActiveUsersList <NeatGenome> .ContainsUser(userName) || !ActiveUsersList <NeatGenome> .IsUserRunning(userName)) { LaunchActionInThread(launchDelegate, userName); } else { System.Diagnostics.Debug.WriteLine("Evolution is already running: skipping start."); } }
static void StartEvolution(string userName) { NeatEvolutionAlgorithm <NeatGenome> evolutionAlgorithm = ActiveUsersList <NeatGenome> .EvolutionAlgorithmForUser(userName); evolutionAlgorithm.MakeEvolutionReady(); System.Diagnostics.Debug.WriteLine("\nEvolution ready, starting iterations"); SaveDataIfRunning(userName); if (ActiveUsersList <NeatGenome> .IsUserRunning(userName)) { evolutionAlgorithm.StartContinue(); } }
private static void TryStopEvolution(string userName) { // We should not be able to ask to stop a process that has not started! // (And thus we ALWAYS expect this check to be true) if (ActiveUsersList <NeatGenome> .ContainsUser(userName)) { if (ActiveUsersList <NeatGenome> .IsUserRunning(userName)) { System.Diagnostics.Debug.WriteLine("Stopping evolution process..."); ActiveUsersList <NeatGenome> .SetRunningStatus(userName, false); ActiveUsersList <NeatGenome> .EvolutionAlgorithmForUser(userName).StopEvolution(); } else { System.Diagnostics.Debug.WriteLine("Evolution is already stopped: skipping stop."); } } else { System.Diagnostics.Debug.WriteLine("Requested to stop " + userName + " but it was not found in the dictionary!"); } }