/// <summary> /// Runs the genetic algorithm until we found a solution /// </summary> /// <param name="population">The initial population.</param> /// <param name="selection">The selection operator .</param> /// <param name="fitnessCalculator">The fitness calculator</param> public void Run(Population population, ISelection selection, IFitness fitnessCalculator, IGenerationCallback callback) { int generation = 0; while (!population.Finished) { callback.OnStart(generation); // calculate fitness of all chromosones in the population population.Calculate(fitnessCalculator, generation); double bestFitness = population[0].Fitness; // create a new popuplation based on the current population population = selection.CreateNewPopulation(population, _elite, _mutate, _crossover, _diversify); callback.OnEnd(generation, bestFitness); generation++; } }