Program: 57451
Project: 57451
Buggy source:
/** 
 * <p>Evolve the given population into the next generation.</p> <p><ol> <li>Get nextGeneration population 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.
 */
public Population nextGeneration(Population current){
  Population nextGeneration=current.nextGeneration();
  while (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
    ChromosomePair pair=getSelectionPolicy().select(current);
    if (randomGenerator.nextDouble() < getCrossoverRate()) {
      pair=getCrossoverPolicy().crossover(pair.getFirst(),pair.getSecond());
    }
    if (randomGenerator.nextDouble() < 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 population 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.
 */
public Population nextGeneration(Population current){
  Population nextGeneration=current.nextGeneration();
  RandomGenerator randGen=getRandomGenerator();
  while (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
    ChromosomePair pair=getSelectionPolicy().select(current);
    if (randGen.nextDouble() < getCrossoverRate()) {
      pair=getCrossoverPolicy().crossover(pair.getFirst(),pair.getSecond());
    }
    if (randGen.nextDouble() < 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;
}