Exemple #1
0
  /**
   * This methods takes a list of solutions, removes a percentage of its solutions, and it is filled
   * with new random generated solutions
   *
   * @param solutionList
   * @param problem
   * @param percentageOfSolutionsToRemove
   */
  public static <S extends Solution<?>> void restart(
      List<S> solutionList, Problem<S> problem, int percentageOfSolutionsToRemove) {
    if (solutionList == null) {
      throw new JMetalException("The solution list is null");
    } else if (problem == null) {
      throw new JMetalException("The problem is null");
    } else if ((percentageOfSolutionsToRemove < 0) || (percentageOfSolutionsToRemove > 100)) {
      throw new JMetalException(
          "The percentage of solutions to remove is invalid: " + percentageOfSolutionsToRemove);
    }

    int solutionListOriginalSize = solutionList.size();
    int numberOfSolutionsToRemove =
        (int) (solutionListOriginalSize * percentageOfSolutionsToRemove / 100.0);

    removeSolutionsFromList(solutionList, numberOfSolutionsToRemove);
    fillPopulationWithNewSolutions(solutionList, problem, solutionListOriginalSize);
  }