示例#1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Population(int size,
     IIndividual ancestor,
     IFitnessFunction fitnessFunction,
     ISelection selectionMethod,
     int numberIterations)
 {
     FitnessFunction = fitnessFunction;
     Selection = Replacement = selectionMethod;
     PopulationSize = size;
     firstSelectionCount = size;
     firstReplacementCount = ((int)(size / 2)) % 2 == 0 ? (int)(size / 2) : (int)(size / 2) + 1;
     iterations = numberIterations;
     // Agregar el ancestro a la poblacion
     ancestor.Evaluate(fitnessFunction);
     Individuals.Add(ancestor);
     // Se agregan mas cromosomas a la poblacion
     for (int i = 1; i < size; i++)
     {
         // Se crea un nuevo cromosoma al azar
         IIndividual c = ancestor.CreateRandomIndividual();
         // se calcula su aptitud
         c.Evaluate(fitnessFunction);
         // Se lo agrega a la poblacion
         Individuals.Add(c);
     }
 }