public async Task MultiThreadedEvolve(int maxGenerationCount, bool asynchronous = false, int?threadCount = null) { string format = "Generation: {0}; Score: {1}; Iteration time: {2} ms."; double generationScore = GetScoreOfGeneration(); Console.WriteLine("Chosen neighborhood: {0}\nChoose replace method: {1}", NeighborhoodSelectionMethod.ToString(), ReplaceMethod.ToString()); Console.WriteLine("Initial generation score: {0}", generationScore); Stopwatch s = new Stopwatch(); for (int generation = 1; generation <= maxGenerationCount; generation++) { s.Start(); if (asynchronous) { await MultithreadedAsynchronousEvolutionStep(threadCount); } else { await MultiThreadEvolutionStep(threadCount); } s.Stop(); //for (int i = 0; i < _currentPopulation.Length; i++) //{ // if (_currentPopulation[i] == null) // { // Console.WriteLine($"{i} is null wtf"); // } //} generationScore = GetScoreOfGeneration(); Console.WriteLine(format, generation, generationScore, s.Elapsed.TotalMilliseconds); s.Reset(); if (generationScore == 1.0) { Console.WriteLine("Reached our objective."); } } }
public void Evolve(int maxGenerationCount, bool asynchronous, bool saveImagesInDebug = false, string folder = null) { string format = "Generation: {0}; Score: {1}; Iteration time: {2} ms."; double generationScore = GetScoreOfGeneration(); Console.WriteLine("Chosen neighborhood: {0}\nChoose replace method: {1}", NeighborhoodSelectionMethod.ToString(), ReplaceMethod.ToString()); Console.WriteLine("Initial generation score: {0}", generationScore); Stopwatch s = new Stopwatch(); for (int generation = 1; generation <= maxGenerationCount; generation++) { s.Start(); if (asynchronous) { AsynchronousEvolutionStep(); } else { SynchronousEvolutionStep(); } s.Stop(); generationScore = GetScoreOfGeneration(); Console.WriteLine(format, generation, generationScore, s.Elapsed.TotalMilliseconds); s.Reset(); if (saveImagesInDebug) { DebugDumpGridToImage($"{folder}/population{(generation + 1)}.png", System.Drawing.Imaging.ImageFormat.Png); } if (generationScore == 1.0) { Console.WriteLine("Reached our objective."); break; } } }