예제 #1
0
 @Override
 protected List<S> createInitialPopulation() {
   List<S> population = new ArrayList<>(populationSize);
   for (int i = 0; i < populationSize; i++) {
     S newIndividual = problem.createSolution();
     population.add(newIndividual);
   }
   return population;
 }
예제 #2
0
 /**
  * Fills a population with new solutions until its size is maxListSize
  *
  * @param solutionList The list of solutions
  * @param problem The problem being solved
  * @param maxListSize The target size of the list
  * @param <S> The type of the solutions to be created
  */
 public static <S extends Solution<?>> void fillPopulationWithNewSolutions(
     List<S> solutionList, Problem<S> problem, int maxListSize) {
   while (solutionList.size() < maxListSize) {
     solutionList.add(problem.createSolution());
   }
 }