Example #1
0
  @Override
  public void evaluate(Solution solution) {
    double[] x = EncodingUtils.getReal(solution);
    double[] psum = new double[numberOfObjectives];
    double[] zz = new double[numberOfVariables];

    // apply transform to convert from UF11 to DTLZ2
    CEC2009.transform(
        x,
        zz,
        psum,
        numberOfVariables == 10 ? M_10D : M_30D,
        numberOfVariables == 10 ? lamda_l_10D : lamda_l_30D,
        numberOfVariables,
        numberOfObjectives);

    // evaluate the transformed solution with DTLZ2
    Solution transformedSolution = problem.newSolution();
    EncodingUtils.setReal(transformedSolution, zz);
    problem.evaluate(transformedSolution);

    // convert the DTLZ2 results back to UF11
    for (int i = 0; i < numberOfObjectives; i++) {
      solution.setObjective(
          i, 2.0 / (1.0 + Math.exp(-psum[i])) * (transformedSolution.getObjective(i) + 1));
    }
  }
Example #2
0
  @Override
  public Solution newSolution() {
    Solution solution = new Solution(2, 3, 2);

    solution.setVariable(0, EncodingUtils.newReal(-10.0, 10.0));
    solution.setVariable(1, EncodingUtils.newReal(-10.0, 10.0));

    return solution;
  }
Example #3
0
  @Override
  public Solution generate() {
    Solution solution = newSolution();

    EncodingUtils.setReal(solution.getVariable(0), 3.0);
    EncodingUtils.setReal(solution.getVariable(1), 0.5);

    evaluate(solution);
    return solution;
  }
Example #4
0
  @Override
  public void evaluate(Solution solution) {
    double x = EncodingUtils.getReal(solution.getVariable(0));
    double y = EncodingUtils.getReal(solution.getVariable(1));
    double f1 = 1.5 - x * (1.0 - y);
    double f2 = 2.25 - x * (1.0 - Math.pow(y, 2.0));
    double f3 = 2.625 - x * (1.0 - Math.pow(y, 3.0));
    double c1 = -Math.pow(x, 2.0) - Math.pow(y - 0.5, 2.0) + 9.0;
    double c2 = Math.pow(x - 1.0, 2.0) + Math.pow(y - 0.5, 2.0) - 6.25;

    solution.setObjective(0, f1);
    solution.setObjective(1, f2);
    solution.setObjective(2, f3);
    solution.setConstraint(0, c1 <= 0.0 ? 0.0 : c1);
    solution.setConstraint(1, c2 <= 0.0 ? 0.0 : c2);
  }
Example #5
0
    /**
     * Extracts the decision variables from the solution, evaluates the Rosenbrock function, and
     * saves the resulting objective value back to the solution.
     */
    @Override
    public void evaluate(Solution solution) {
      double[] x = EncodingUtils.getReal(solution);
      double[] f = new double[numberOfObjectives];

      int k = numberOfVariables - numberOfObjectives + 1;

      double g = 0.0;
      for (int i = numberOfVariables - k; i < numberOfVariables; i++) {
        g += Math.pow(x[i] - 0.5, 2.0);
      }

      for (int i = 0; i < numberOfObjectives; i++) {
        f[i] = 1.0 + g;

        for (int j = 0; j < numberOfObjectives - i - 1; j++) {
          f[i] *= Math.cos(0.5 * Math.PI * x[j]);
        }

        if (i != 0) {
          f[i] *= Math.sin(0.5 * Math.PI * x[numberOfObjectives - i - 1]);
        }
      }

      solution.setObjectives(f);
    }
Example #6
0
  @Override
  public void evaluate(Solution solution) {
    double[] theta = new double[numberOfObjectives - 1];

    double[] f = new double[numberOfObjectives];
    double[] x = EncodingUtils.getReal(solution);

    int k = numberOfVariables - numberOfObjectives + 1;

    double g = 0.0;
    for (int i = numberOfVariables - k; i < numberOfVariables; i++) {
      g += java.lang.Math.pow(x[i], 0.1);
    }

    double t = java.lang.Math.PI / (4.0 * (1.0 + g));
    theta[0] = x[0] * java.lang.Math.PI / 2;
    for (int i = 1; i < (numberOfObjectives - 1); i++) {
      theta[i] = t * (1.0 + 2.0 * g * x[i]);
    }

    for (int i = 0; i < numberOfObjectives; i++) {
      f[i] = 1.0 + g;

      for (int j = 0; j < numberOfObjectives - (i + 1); j++) {
        f[i] *= java.lang.Math.cos(theta[j]);
      }
      if (i != 0) {
        int aux = numberOfObjectives - (i + 1);
        f[i] *= java.lang.Math.sin(theta[aux]);
      }

      solution.setObjective(i, f[i]);
    }
  }
Example #7
0
    @Override
    public Solution newSolution() {
      Solution solution = new Solution(1, 1);

      solution.setVariable(0, EncodingUtils.newPermutation(instance.getDimension()));

      return solution;
    }
Example #8
0
  /**
   * Saves a {@link Tour} into a MOEA Framework solution.
   *
   * @param solution the MOEA Framework solution
   * @param tour the tour
   */
  public static void fromTour(Solution solution, Tour tour) {
    int[] permutation = tour.toArray();

    // decrement values to get permutation
    for (int i = 0; i < permutation.length; i++) {
      permutation[i]--;
    }

    EncodingUtils.setPermutation(solution.getVariable(0), permutation);
  }
Example #9
0
  /**
   * Converts a MOEA Framework solution to a {@link Tour}.
   *
   * @param solution the MOEA Framework solution
   * @return the tour defined by the solution
   */
  public static Tour toTour(Solution solution) {
    int[] permutation = EncodingUtils.getPermutation(solution.getVariable(0));

    // increment values since TSP nodes start at 1
    for (int i = 0; i < permutation.length; i++) {
      permutation[i]++;
    }

    return Tour.createTour(permutation);
  }
Example #10
0
  @Override
  public void evaluate(Solution solution) {
    double[] x = EncodingUtils.getReal(solution);
    double x1 = Math.cos(Math.PI / 12.0) * x[0] - Math.sin(Math.PI / 12.0) * x[1];
    double x2 = Math.sin(Math.PI / 12.0) * x[0] + Math.cos(Math.PI / 12.0) * x[1];

    solution.setObjective(0, x1);
    solution.setObjective(
        1,
        Math.sqrt(2.0 * Math.PI)
            - Math.sqrt(Math.abs(x1))
            + 2.0 * Math.pow(Math.abs(x2 - 3.0 * Math.cos(x1) - 3), 1.0 / 3.0));
  }