예제 #1
0
  public void postGeneration() {
    // Create the solutionSet union of solutionSet and offSpring
    union_ = ((SolutionSet) population_).union(offspringPopulation_);

    // Ranking the union
    Ranking ranking = new Ranking(union_);

    if (ranking.getNumberOfSubfronts() == 0) System.out.println("No hay subfrentes!!");

    int remain = populationSize_;
    int index = 0;
    SolutionSet front = null;
    population_.clear();

    // Obtain the next front
    front = ranking.getSubfront(index);

    while ((remain > 0) && (remain >= front.size())) {
      // Assign crowding distance to individuals
      distance_.crowdingDistanceAssignment(front, problem_.getNumberOfObjectives());
      // Add the individuals of this front
      for (int k = 0; k < front.size(); k++) {
        population_.add(front.get(k));
      } // for

      // Decrement remain
      remain = remain - front.size();

      // Obtain the next front
      index++;
      if (remain > 0) {
        front = ranking.getSubfront(index);
      } // if
    } // while

    // Remain is less than front(index).size, insert only the best one
    if (remain > 0) { // front contains individuals to insert
      distance_.crowdingDistanceAssignment(front, problem_.getNumberOfObjectives());
      front.sort(new jmetal.coevolutionary.base.operator.comparator.CrowdingComparator());
      for (int k = 0; k < remain; k++) {
        population_.add(front.get(k));
      } // for

      remain = 0;
    } // if

    // This piece of code shows how to use the indicator object into the code
    // of NSGA-II. In particular, it finds the number of evaluations required
    // by the algorithm to obtain a Pareto front with a hypervolume higher
    // than the hypervolume of the true Pareto front.
    if ((indicators_ != null) && (requiredEvaluations_ == 0)) {
      double HV = indicators_.getHypervolume(population_);
      if (HV >= (0.98 * indicators_.getTrueParetoFrontHypervolume())) {
        requiredEvaluations_ = evaluations_;
      } // if
    } // if

    prepareBestSolutions();
  } // postGeneration