Program: 57496
Project: 57496
Buggy source:
/** 
 * <p>Evolve the given population into the next generation.</p> <p><ol> <li>Get nextGeneration polulation to fill from <code>current</code> generation, using its nextGeneration method</li> <li>Loop until new generation is filled:</li> <ul><li>Apply configured SelectionPolicy to select a pair of parents from <code>current</code></li> <li>With probability =   {@link #getCrossoverRate()}, apply configured   {@link CrossoverPolicy} to parents</li><li>With probability =  {@link #getMutationRate()}, apply configured   {@link MutationPolicy} to each parent</li><li>Add resulting chromosomes individually to nextGeneration, space permitting</li> </ul> <li>Return nextGeneration</li> </ol> </p>
 * @param current the current population.
 * @return the population for the next generation.
 */
private Population nextGeneration(Population current){
  Population nextGeneration=current.nextGeneration();
  while (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
    ChromosomePair pair=getSelectionPolicy().select(current);
    if (Math.random() < getCrossoverRate()) {
      pair=getCrossoverPolicy().crossover(pair.getFirst(),pair.getSecond());
    }
    if (Math.random() < getMutationRate()) {
      pair=new ChromosomePair(getMutationPolicy().mutate(pair.getFirst()),getMutationPolicy().mutate(pair.getSecond()));
    }
    nextGeneration.addChromosome(pair.getFirst());
    if (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
      nextGeneration.addChromosome(pair.getSecond());
    }
  }
  return nextGeneration;
}

Fixed version (ground truth):
/** 
 * <p>Evolve the given population into the next generation.</p> <p><ol> <li>Get nextGeneration polulation to fill from <code>current</code> generation, using its nextGeneration method</li> <li>Loop until new generation is filled:</li> <ul><li>Apply configured SelectionPolicy to select a pair of parents from <code>current</code></li> <li>With probability =   {@link #getCrossoverRate()}, apply configured   {@link CrossoverPolicy} to parents</li><li>With probability =  {@link #getMutationRate()}, apply configured   {@link MutationPolicy} to each of the offspring</li><li>Add offspring individually to nextGeneration, space permitting</li> </ul> <li>Return nextGeneration</li> </ol> </p>
 * @param current the current population.
 * @return the population for the next generation.
 */
private Population nextGeneration(Population current){
  Population nextGeneration=current.nextGeneration();
  while (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
    ChromosomePair pair=getSelectionPolicy().select(current);
    if (Math.random() < getCrossoverRate()) {
      pair=getCrossoverPolicy().crossover(pair.getFirst(),pair.getSecond());
    }
    if (Math.random() < getMutationRate()) {
      pair=new ChromosomePair(getMutationPolicy().mutate(pair.getFirst()),getMutationPolicy().mutate(pair.getSecond()));
    }
    nextGeneration.addChromosome(pair.getFirst());
    if (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
      nextGeneration.addChromosome(pair.getSecond());
    }
  }
  return nextGeneration;
}