/**
   * Returns the Euclidean distance in objective space between the specified solution and the
   * nearest solution in the population.
   *
   * @param problem the problem
   * @param solution the solution
   * @param population the population
   * @return the Euclidean distance in objective space between the specified solution and the
   *     nearest solution in the population
   */
  public static double distanceToNearestSolution(
      Problem problem, Solution solution, NondominatedPopulation population) {
    double minimum = Double.POSITIVE_INFINITY;

    for (int i = 0; i < population.size(); i++) {
      minimum = Math.min(minimum, euclideanDistance(problem, solution, population.get(i)));
    }

    return minimum;
  }
  @Override
  public double evaluate(NondominatedPopulation approximationSet) {
    int count = 0;

    for (Solution solution1 : referenceSet) {
      boolean match = false;

      for (Solution solution2 : approximationSet) {
        if (comparator == null) {
          double distance =
              MathArrays.distance(solution1.getObjectives(), solution2.getObjectives());

          if (distance < Settings.EPS) {
            match = true;
            break;
          }
        } else {
          comparator.compare(solution1, solution2);

          if (comparator.isSameBox()) {
            match = true;
            break;
          }
        }
      }

      if (match) {
        count++;
      }
    }

    return count / (double) referenceSet.size();
  }
Beispiel #3
0
  public static void main(String[] args) {
    Properties properties = new Properties();
    properties.setProperty("populationSize", "10");

    Problem problem = new OneMax(100);
    Algorithm algorithm =
        AlgorithmFactory.getInstance().getAlgorithm("NSGAII", properties, problem);

    while (!algorithm.isTerminated()) {
      algorithm.step();

      NondominatedPopulation population = algorithm.getResult();

      if (population.get(0).getObjective(0) == 0) {
        // if all bits are 1
        System.out.println(
            "Found optimal solution after " + algorithm.getNumberOfEvaluations() + " evaluations!");
        break;
      }
    }
  }
  /**
   * Constructs the contribution indicator using the specified reference set and &epsilon;-box
   * dominance comparator. Solutions residing in the same &epsilon;-box are considered to be
   * equivalent.If the comparator is {@code null}, exact matching is used.
   *
   * @param referenceSet the reference set
   * @param comparator the &epsilon;-box dominance comparator used to determine if solutions in the
   *     reference set are covered by solutions in the approximation set; or {@code null} if exact
   *     matching is used
   * @throws IllegalArgumentException if the reference set is empty
   */
  public Contribution(
      NondominatedPopulation referenceSet, EpsilonBoxDominanceComparator comparator) {
    super();
    this.comparator = comparator;

    if (referenceSet.isEmpty()) {
      throw new IllegalArgumentException("reference set is empty");
    }

    if (comparator == null) {
      this.referenceSet = referenceSet;
    } else {
      this.referenceSet = new EpsilonBoxDominanceArchive(comparator, referenceSet);
    }
  }