public virtual void Crossover()
{
// crossover
for (int i = 1; i < size; i += 2)
{
// generate next random number and check if we need to do crossover
if (Generator.Random.NextDouble() <= crossoverRate)
{
// clone both ancestors
IChromosome c1 = population[i - 1].Clone();
IChromosome c2 = population[i].Clone();
// do crossover
c1.Crossover(c2);
// calculate fitness of these two offsprings
c1.Evaluate(fitnessFunction);
c2.Evaluate(fitnessFunction);
// add two new offsprings to the population
population.Add(c1);
population.Add(c2);
}
}
}