@Override protected void iterate() { Population offspring = new Population(); int populationSize = population.size(); while (offspring.size() < populationSize) { Solution[] parents = selection.select(variation.getArity(), population); Solution[] children = variation.evolve(parents); offspring.addAll(children); } evaluateAll(offspring); population.addAll(offspring); fitnessEvaluator.evaluate(population); while (population.size() > populationSize) { int worstIndex = findWorstIndex(); fitnessEvaluator.removeAndUpdate(population, worstIndex); } }
@Override protected void iterate() { // mating and selection to generate offspring Population offspring = new Population(); int populationSize = population.size(); while (offspring.size() < numberOfOffspring) { Solution[] parents = selection.select(variation.getArity(), population); Solution[] children = variation.evolve(parents); offspring.addAll(children); } // evaluate the offspring evaluateAll(offspring); // evaluate the fitness of the population and offspring offspring.addAll(population); fitnessEvaluator.evaluate(offspring); // perform environmental selection to downselect the next population population.clear(); population.addAll(truncate(offspring, populationSize)); }