public Population(int size,
IChromosome ancestor,
IFitnessFunction fitnessFunction,
ISelectionMethod selectionMethod)
{
if (size < 2)
throw new ArgumentException("Too small population's size was specified.");
this.fitnessFunction = fitnessFunction;
this.selectionMethod = selectionMethod;
this.size = size;
// add ancestor to the population
ancestor.Evaluate(fitnessFunction);
population.Add(ancestor.Clone());
// add more chromosomes to the population
for (int i = 1; i < size; i++)
{
// create new chromosome
IChromosome c = ancestor.CreateNew();
// calculate it's fitness
c.Evaluate(fitnessFunction);
// add it to population
population.Add(c);
}
}