Example #1
0
  protected void addRankedSolutionsToPopulation(Ranking ranking, int rank) throws JMetalException {
    SolutionSet front;

    front = ranking.getSubfront(rank);

    for (int i = 0; i < front.size(); i++) {
      population.add(front.get(i));
    }
  }
Example #2
0
  protected void createInitialPopulation() throws ClassNotFoundException, JMetalException {
    population = new SolutionSet(populationSize);

    Solution newSolution;
    for (int i = 0; i < populationSize; i++) {
      newSolution = new Solution(problem);
      population.add(newSolution);
    }
  }
  /** Execute() method */
  public Object execute(Object object) throws JMetalException {
    if (null == object) {
      throw new JMetalException("Null parameter");
    } else if (!(object instanceof Solution)) {
      throw new JMetalException("Invalid parameter class");
    }

    int i = 0;
    int best = 0;
    evaluations = 0;
    Solution solution = (Solution) object;

    int rounds = improvementRounds;

    if (rounds <= 0) {
      return new Solution(solution);
    }

    do {
      i++;
      Solution mutatedSolution = new Solution(solution);
      mutationOperator.execute(mutatedSolution);

      // Evaluate the getNumberOfConstraints
      if (problem.getNumberOfConstraints() > 0) {
        problem.evaluateConstraints(mutatedSolution);
        best = constraintComparator.compare(mutatedSolution, solution);
        if (best == 0) {
          // none of then is better that the other one
          problem.evaluate(mutatedSolution);
          evaluations++;
          best = dominanceComparator.compare(mutatedSolution, solution);
        } else if (best == -1) {
          // mutatedSolution is best
          problem.evaluate(mutatedSolution);
          evaluations++;
        }
      } else {
        problem.evaluate(mutatedSolution);
        evaluations++;
        best = dominanceComparator.compare(mutatedSolution, solution);
      }
      if (best == -1) {
        // mutated is best
        solution = mutatedSolution;
      } else if (best == 1) {
        // original is best

      } else {
        // mutatedSolution and original are non-dominated
        if (archive != null) {
          archive.add(mutatedSolution);
        }
      }
    } while (i < rounds);
    return new Solution(solution);
  }
Example #4
0
  protected void addLastRankedSolutions(Ranking ranking, int rank) throws JMetalException {
    SolutionSet currentRankedFront = ranking.getSubfront(rank);

    currentRankedFront.sort(new CrowdingComparator());

    int i = 0;
    while (population.size() < populationSize) {
      population.add(currentRankedFront.get(i));
      i++;
    }
  }
Example #5
0
  /**
   * Computes the HV contribution of a solutiontype in a solutiontype set. REQUIRES: the
   * solutiontype belongs to the solutiontype set REQUIRES: the HV of the solutiontype set is
   * computed beforehand and its value is passed as third parameter
   *
   * @return The hv contribution of the solutiontype
   */
  public double computeSolutionHVContribution(
      SolutionSet solutionSet, int solutionIndex, double solutionSetHV) {
    double contribution;

    Solution currentPoint = solutionSet.get(solutionIndex);
    solutionSet.remove(solutionIndex);

    if (numberOfObjectives == 2) {
      contribution = solutionSetHV - get2DHV(solutionSet);
    } else {
      Front front = new Front(solutionSet.size(), numberOfObjectives, solutionSet);
      double hv = new WFGHV(numberOfObjectives, solutionSet.size(), referencePoint).getHV(front);
      contribution = solutionSetHV - hv;
    }
    solutionSet.add(solutionIndex, currentPoint);
    solutionSet.get(solutionIndex).setCrowdingDistance(contribution);

    return contribution;
  }
Example #6
0
  /**
   * Computes the HV contribution of the solutions
   *
   * @return
   */
  public void computeHVContributions(SolutionSet solutionSet) {
    double[] contributions = new double[solutionSet.size()];
    double solutionSetHV = 0;

    solutionSetHV = computeHypervolume(solutionSet);

    for (int i = 0; i < solutionSet.size(); i++) {
      Solution currentPoint = solutionSet.get(i);
      solutionSet.remove(i);

      if (numberOfObjectives == 2) {
        contributions[i] = solutionSetHV - get2DHV(solutionSet);
      } else {
        Front front = new Front(solutionSet.size(), numberOfObjectives, solutionSet);
        double hv = new WFGHV(numberOfObjectives, solutionSet.size(), referencePoint).getHV(front);
        contributions[i] = solutionSetHV - hv;
      }
      solutionSet.add(i, currentPoint);
    }

    for (int i = 0; i < solutionSet.size(); i++) {
      solutionSet.get(i).setCrowdingDistance(contributions[i]);
    }
  }