예제 #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));
    }
  }
예제 #2
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++;
    }
  }
예제 #3
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);
    }
  }
예제 #4
0
  /** Updates the reference point */
  private void updateReferencePoint(SolutionSet solutionSet) {
    double[] maxObjectives = new double[numberOfObjectives];
    for (int i = 0; i < numberOfObjectives; i++) {
      maxObjectives[i] = 0;
    }

    for (int i = 0; i < solutionSet.size(); i++) {
      for (int j = 0; j < numberOfObjectives; j++) {
        if (maxObjectives[j] < solutionSet.get(i).getObjective(j)) {
          maxObjectives[j] = solutionSet.get(i).getObjective(j);
        }
      }
    }

    for (int i = 0; i < referencePoint.getNumberOfObjectives(); i++) {
      referencePoint.setObjective(i, maxObjectives[i] + offset);
    }
  }
예제 #5
0
  /** 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);
  }
예제 #6
0
  public double computeHypervolume(SolutionSet solutionSet) {
    double hv;
    if (solutionSet.size() == 0) {
      hv = 0.0;
    } else {
      numberOfObjectives = solutionSet.get(0).getNumberOfObjectives();
      referencePoint = new Solution(numberOfObjectives);
      updateReferencePoint(solutionSet);
      if (numberOfObjectives == 2) {
        solutionSet.sort(new ObjectiveComparator(numberOfObjectives - 1, true));
        hv = get2DHV(solutionSet);
      } else {
        updateReferencePoint(solutionSet);
        Front front = new Front(solutionSet.size(), numberOfObjectives, solutionSet);
        hv = new WFGHV(numberOfObjectives, solutionSet.size(), referencePoint).getHV(front);
      }
    }

    return hv;
  }
예제 #7
0
  public double computeHypervolume(SolutionSet solutionSet, Solution referencePoint) {
    double hv = 0.0;
    if (solutionSet.size() == 0) {
      hv = 0.0;
    } else {
      numberOfObjectives = solutionSet.get(0).getNumberOfObjectives();
      this.referencePoint = referencePoint;

      if (numberOfObjectives == 2) {
        solutionSet.sort(new ObjectiveComparator(numberOfObjectives - 1, true));

        hv = get2DHV(solutionSet);
      } else {
        WFGHV wfg = new WFGHV(numberOfObjectives, solutionSet.size());
        Front front = new Front(solutionSet.size(), numberOfObjectives, solutionSet);
        hv = wfg.getHV(front, referencePoint);
      }
    }

    return hv;
  }
예제 #8
0
 protected void crowdingDistanceSelection(Ranking ranking) {
   population.clear();
   int rankingIndex = 0;
   while (populationIsNotFull()) {
     if (subfrontFillsIntoThePopulation(ranking, rankingIndex)) {
       addRankedSolutionsToPopulation(ranking, rankingIndex);
       rankingIndex++;
     } else {
       computeCrowdingDistance(ranking, rankingIndex);
       addLastRankedSolutions(ranking, rankingIndex);
     }
   }
 }
예제 #9
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]);
    }
  }
예제 #10
0
  /**
   * Computes the HV of a solutiontype set. REQUIRES: The problem is bi-objective REQUIRES: The
   * setArchive is ordered in descending order by the second objective
   *
   * @return
   */
  public double get2DHV(SolutionSet solutionSet) {
    double hv = 0.0;
    if (solutionSet.size() > 0) {
      hv =
          Math.abs(
              (solutionSet.get(0).getObjective(0) - referencePoint.getObjective(0))
                  * (solutionSet.get(0).getObjective(1) - referencePoint.getObjective(1)));

      for (int i = 1; i < solutionSet.size(); i++) {
        double tmp =
            Math.abs(
                (solutionSet.get(i).getObjective(0) - referencePoint.getObjective(0))
                    * (solutionSet.get(i).getObjective(1)
                        - solutionSet.get(i - 1).getObjective(1)));
        hv += tmp;
      }
    }
    return hv;
  }
예제 #11
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;
  }
예제 #12
0
 protected boolean subfrontFillsIntoThePopulation(Ranking ranking, int rank) {
   return ranking.getSubfront(rank).size() < (populationSize - population.size());
 }
예제 #13
0
 protected boolean populationIsNotFull() {
   return population.size() < populationSize;
 }
예제 #14
0
  protected Ranking rankPopulation() throws JMetalException {
    SolutionSet union = population.union(offspringPopulation);

    return new Ranking(union);
  }
예제 #15
0
  protected SolutionSet evaluatePopulation(SolutionSet population) throws JMetalException {
    evaluations += population.size();

    return evaluator.evaluate(population, problem);
  }