ElitisticListPopulation extends ListPopulation { public Population nextGeneration() { ElitisticListPopulation nextGeneration = new ElitisticListPopulation(getPopulationLimit(), getElitismRate()); final List<Chromosome> oldChromosomes = getChromosomeList(); Collections.sort(oldChromosomes); int boundIndex = (int) FastMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size()); for (int i = boundIndex; i < oldChromosomes.size(); i++) { nextGeneration.addChromosome(oldChromosomes.get(i)); } return nextGeneration; } ElitisticListPopulation(final List<Chromosome> chromosomes, final int populationLimit,
                                   final double elitismRate);  ElitisticListPopulation(final int populationLimit, final double elitismRate); Population nextGeneration(); void setElitismRate(final double elitismRate); double getElitismRate();  }
@Test public void testNextGeneration() { ElitisticListPopulation pop = new ElitisticListPopulation(100, 0.203); for (int i=0; i<pop.getPopulationLimit(); i++) { pop.addChromosome(new DummyChromosome()); } Population nextGeneration = pop.nextGeneration(); Assert.assertEquals(20, nextGeneration.getPopulationSize()); }