static void Main(string[] args) { Population p = new Population(); p.WriteNextGeneration(); int count = 0; byte res = 0; EquationGenome resGenome; while (p.Converged() == false) { p.NextGeneration(); if (count % 50 == 0) { p.WriteNextGeneration(); resGenome = (EquationGenome) p.GetNextGenerationBest(); res = resGenome.PerformCalculation(0, 1, 1, 1); Console.WriteLine("<Loop> Result => {0}", res.ToString()); } count++; if (count > 40000) { Console.WriteLine("---------------"); p.WriteNextGenerationBest(); Console.WriteLine("---------------"); break; } // End of if } // End of the while Console.WriteLine("Done"); resGenome = (EquationGenome) p.GetNextGenerationBest(); res = resGenome.PerformCalculation(0, 1, 1, 1); Console.WriteLine("Result => {0}", res.ToString()); }
public void RunPopulation(object thePopulationObject) { Population thePopulation = (Population)thePopulationObject; int NumberOfGenerations = 50000; for (int i = 0; i < NumberOfGenerations; i++) { thePopulation.NextGeneration(); if (i % (NumberOfGenerations / 20) == 0) { thePopulation.WriteNextGenerationTop(10); if (EquationGenome.PerfectFitness == true) { NumberOfGenerations = i; break; } } if (i % (NumberOfGenerations / 4) == 0) { EquationGenome[] EquationGenomesBest = (EquationGenome[])thePopulation.GetHighestScoreGenomes(Population.kNumberOfChoiceGenomes); CopyHighestFitnessToOtherPopulations(EquationGenomesBest); } } thePopulation.FinishedRunning = true; thePopulation.CalculateFitnessForAll(); EquationGenome EquationGenomeToIllustrate = (EquationGenome)thePopulation.GetHighestScoreGenome(); Console.WriteLine(""); Console.WriteLine("Best Genome in {1} after {0} Generations", NumberOfGenerations, thePopulation.Name); Console.WriteLine(EquationGenomeToIllustrate.ToString()); EquationGenomeToIllustrate = GetBestGeneFromAllPopulations(); Console.WriteLine("The next value in the series = {0}", EquationGenomeToIllustrate.CalculateNextValue()); Class1.EquationGenomeToIllustrate = EquationGenomeToIllustrate; // Console.ReadLine(); }