public override void _Ready() { logLabel = GetNode("CanvasLayer/RTLLog") as RTLLog; logLabel.LogLine("Prepping configs..."); foreach (var populationSize in populationSizes) { foreach (var mutationRate in mutationRates) { foreach (var elitism in elitisms) { foreach (var maxIteration in maxIterations) { GD.Print($"{populationSize}, {mutationRate}, {maxIteration}"); var config = new TestConfiguration( populationSize, // int popupationSize, mutationRate, // float mutationRate, elitism, // float elitism, maxIteration, // int maxIterations, 100, // int genChunkSize, 5 // int refChunkSize ); configurations.Add(config); } } } } logLabel.LogLine("Configs ready."); }
void runTests() { foreach (var configuration in configurations) { configuration.StartTest(logLabel); } logLabel.LogLine("Done!"); }
public void StartTest(RTLLog log = null) { File testData = new File(); string fileName = "test.csv"; if (testData.FileExists(fileName)) { testData.Open(fileName, File.ModeFlags.ReadWrite); testData.GetCsvLine(); while (!testData.EofReached()) { Int32.TryParse(testData.GetCsvLine()[0], out int tId); if (this.TestId <= tId) { this.TestId++; } } } else { testData.Open(fileName, File.ModeFlags.Write); testData.StoreCsvLine(GenerationResult.GetHeaderStringArray()); } if (log != null) { log.LogLine($"Initiating test id {this.TestId} with config: popSize {this.PopulationSize}, mutRate {MutationRate}, elitism {Elitism}, maxIterations {MaxIterations}."); } // First generation of this test batch // Start timer to track ellapsed time per generation var watch = System.Diagnostics.Stopwatch.StartNew(); double duration = 0; // the code that you want to measure comes here int genNumber = 0; List <MapIndividual> population = Generator.EvolveTestChunkOnRight(); MapIndividual bestIndividual = population[population.Count - 1]; GenerationResult currentGenerationResult = new GenerationResult { TestId = this.TestId, BestFitness = bestIndividual.Fitness, GenerationNumber = genNumber, FivePercentBestFitnessAvg = getFivePercentAvg(population), IsBestPlayable = bestIndividual.IsPlayable, FitnessAverage = getFitnessAverage(population), FitnessMedian = getFitnessMedian(population), PopulationSize = this.PopulationSize, GenChunkSize = this.GenChunkSize, MutationRate = this.MutationRate, Elitism = this.Elitism, }; watch.Stop(); currentGenerationResult.ExecutionTimeMs = watch.ElapsedMilliseconds; testData.StoreCsvLine(currentGenerationResult.GetCsvStringArray()); for (genNumber = genNumber + 1; genNumber <= MaxIterations; genNumber++) { watch = System.Diagnostics.Stopwatch.StartNew(); population = Generator.EvolveTestChunkOnRight(population); bestIndividual = population[population.Count - 1]; currentGenerationResult = new GenerationResult { TestId = this.TestId, BestFitness = bestIndividual.Fitness, GenerationNumber = genNumber, FivePercentBestFitnessAvg = getFivePercentAvg(population), IsBestPlayable = bestIndividual.IsPlayable, FitnessAverage = getFitnessAverage(population), FitnessMedian = getFitnessMedian(population), PopulationSize = this.PopulationSize, GenChunkSize = this.GenChunkSize, MutationRate = this.MutationRate, Elitism = this.Elitism, }; watch.Stop(); currentGenerationResult.ExecutionTimeMs = watch.ElapsedMilliseconds; duration += watch.ElapsedMilliseconds; testData.StoreCsvLine(currentGenerationResult.GetCsvStringArray()); } // Close file at the end of this test testData.Close(); TimeSpan t = TimeSpan.FromMilliseconds(duration); string durationString = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", t.Hours, t.Minutes, t.Seconds, t.Milliseconds); if (log != null) { log.LogLine($"Done with test {this.TestId} in {durationString}!"); } }