Esempio n. 1
0
  /**
   * Evaluates a solution.
   *
   * @param solution The solution to evaluate.
   * @throws JMException
   */
  public void evaluate(Solution solution) throws JMException {
    Variable[] decisionVariables = solution.getDecisionVariables();

    double[] x = new double[numberOfVariables_];
    for (int i = 0; i < numberOfVariables_; i++) x[i] = decisionVariables[i].getValue();

    int count1, count2;
    double prod1, prod2;
    double sum1, sum2, yj, hj, pj;
    sum1 = sum2 = 0.0;
    count1 = count2 = 0;
    prod1 = prod2 = 1.0;

    for (int j = 2; j <= numberOfVariables_; j++) {
      yj = x[j - 1] - Math.sin(6.0 * Math.PI * x[0] + j * Math.PI / numberOfVariables_);
      pj = Math.cos(20.0 * yj * Math.PI / Math.sqrt(j));
      if (j % 2 == 0) {
        sum2 += yj * yj;
        prod2 *= pj;
        count2++;
      } else {
        sum1 += yj * yj;
        prod1 *= pj;
        count1++;
      }
    }
    hj = 2.0 * (0.5 / N_ + epsilon_) * Math.sin(2.0 * N_ * Math.PI * x[0]);
    if (hj < 0.0) hj = 0.0;

    solution.setObjective(0, x[0] + hj + 2.0 * (4.0 * sum1 - 2.0 * prod1 + 2.0) / (double) count1);
    solution.setObjective(
        1, 1.0 - x[0] + hj + 2.0 * (4.0 * sum2 - 2.0 * prod2 + 2.0) / (double) count2);
  } // evaluate
Esempio n. 2
0
 // constriction coefficient (M. Clerc)
 private double constrictionCoefficient(double c1, double c2) {
   double rho = c1 + c2;
   // rho = 1.0 ;
   if (rho <= 4) {
     return 1.0;
   } else {
     return 2 / (2 - rho - Math.sqrt(Math.pow(rho, 2.0) - 4.0 * rho));
   }
 } // constrictionCoefficient
Esempio n. 3
0
  /**
   * Returns the distance between two solutions in objective space.
   *
   * @param solutionI The first <code>Solution</code>.
   * @param solutionJ The second <code>Solution</code>.
   * @return the distance between solutions in objective space.
   */
  public double distanceBetweenObjectives(Solution solutionI, Solution solutionJ) {
    double diff; // Auxiliar var
    double distance = 0.0;
    // -> Calculate the euclidean distance
    for (int nObj = 0; nObj < solutionI.numberOfObjectives(); nObj++) {
      diff = solutionI.getObjective(nObj) - solutionJ.getObjective(nObj);
      distance += Math.pow(diff, 2.0);
    } // for

    // Return the euclidean distance
    return Math.sqrt(distance);
  } // distanceBetweenObjectives.
Esempio n. 4
0
  /**
   * Returns the distance between two solutions in the search space.
   *
   * @param solutionI The first <code>Solution</code>.
   * @param solutionJ The second <code>Solution</code>.
   * @return the distance between solutions.
   * @throws JMException
   */
  public double distanceBetweenSolutions(Solution solutionI, Solution solutionJ)
      throws JMException {
    // ->Obtain his decision variables
    Variable[] decisionVariableI = solutionI.getDecisionVariables();
    Variable[] decisionVariableJ = solutionJ.getDecisionVariables();

    double diff; // Auxiliar var
    double distance = 0.0;
    // -> Calculate the Euclidean distance
    for (int i = 0; i < decisionVariableI.length; i++) {
      diff = decisionVariableI[i].getValue() - decisionVariableJ[i].getValue();
      distance += Math.pow(diff, 2.0);
    } // for

    // -> Return the euclidean distance
    return Math.sqrt(distance);
  } // distanceBetweenSolutions