コード例 #1
0
ファイル: DTLZ6.java プロジェクト: fmaziere/hcsp-chc
  /**
   * Evaluates a solution
   *
   * @param solution The solution to evaluate
   * @throws JMException
   */
  public void evaluate(Solution solution) throws JMException {
    DecisionVariables gen = solution.getDecisionVariables();

    double[] x = new double[numberOfVariables_];
    double[] f = new double[numberOfObjectives_];
    double[] theta = new double[numberOfObjectives_ - 1];
    int k = numberOfVariables_ - numberOfObjectives_ + 1;

    for (int i = 0; i < numberOfVariables_; i++) x[i] = gen.variables_[i].getValue();

    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 i = 0; i < numberOfObjectives_; i++) {
      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]);
      } // if
    } // for

    for (int i = 0; i < numberOfObjectives_; i++) solution.setObjective(i, f[i]);
  } // evaluate
コード例 #2
0
ファイル: ZZJ07_F5.java プロジェクト: fmaziere/hcsp-chc
  /**
   * Evaluates a solution
   *
   * @param solution The solution to evaluate
   * @throws JMException
   */
  public void evaluate(Solution solution) throws JMException {
    DecisionVariables decisionVariables = solution.getDecisionVariables();

    double[] x = new double[numberOfVariables_];
    double[] fx = new double[numberOfVariables_];
    double g;
    double h;
    double sum;
    for (int i = 0; i < numberOfVariables_; i++) x[i] = decisionVariables.variables_[i].getValue();

    fx[0] = x[0];

    sum = 0.0;
    for (int i = 1; i < numberOfVariables_; i++) sum += (x[i] * x[i] - x[0]) * (x[i] * x[i] - x[0]);

    g = 1.0 + 9.0 * sum / (numberOfVariables_ - 1.0);
    h = 1.0 - Math.sqrt(x[0] / g);

    fx[1] = g * h;

    solution.setObjective(0, fx[0]);
    solution.setObjective(1, fx[1]);
  } // evaluate
コード例 #3
0
ファイル: DPX.java プロジェクト: fmaziere/hcsp-chc
  /**
   * Perform the crossover operation
   *
   * @param probability Crossover probability
   * @param parent1 The first parent
   * @param parent2 The second parent
   * @return Two offspring solutions
   * @throws JMException
   */
  public Solution[] doCrossover(double probability, Solution parent1, Solution parent2)
      throws JMException {

    Solution[] offspring = new Solution[2];

    offspring[0] = new Solution(parent1);
    offspring[1] = new Solution(parent2);

    if (PseudoRandom.randDouble() < probability) {
      int crosspoint1;
      int crosspoint2;
      int chromosomeLength;
      DecisionVariables parent1Vars;
      DecisionVariables parent2Vars;
      DecisionVariables offspring1Vars;
      DecisionVariables offspring2Vars;

      // permutationLength = ((Permutation)parent1.getDecisionVariables().variables_[0]).getLength()
      // ;
      chromosomeLength = parent1.getDecisionVariables().size();
      parent1Vars = parent1.getDecisionVariables();
      parent2Vars = parent2.getDecisionVariables();
      offspring1Vars = offspring[0].getDecisionVariables();
      offspring2Vars = offspring[1].getDecisionVariables();

      // STEP 1: Get two cutting points
      crosspoint1 = PseudoRandom.randInt(0, chromosomeLength - 1);
      crosspoint2 = PseudoRandom.randInt(0, chromosomeLength - 1);

      while (crosspoint2 == crosspoint1)
        crosspoint2 = PseudoRandom.randInt(0, chromosomeLength - 1);

      if (crosspoint1 > crosspoint2) {
        int swap;
        swap = crosspoint1;
        crosspoint1 = crosspoint2;
        crosspoint2 = swap;
      } // if

      //        // STEP 2: Obtain the two children
      //
      //        for(int k = 0; k < crosspoint1; k++) {
      //        	offspring1Vars.variables_[k] = parent1Vars.variables_[k];
      //        	offspring2Vars.variables_[k] = parent2Vars.variables_[k];
      //        }
      //
      //       for(int k = crosspoint1; k < crosspoint2; k++) {
      //    	   offspring2Vars.variables_[k] = parent1Vars.variables_[k];
      //       	   offspring1Vars.variables_[k] = parent2Vars.variables_[k];
      //        } // for
      //
      //       for(int k = crosspoint2; k < chromosomeLength; k++) {
      //       	offspring1Vars.variables_[k] = parent1Vars.variables_[k];
      //       	offspring2Vars.variables_[k] = parent2Vars.variables_[k];
      //       }

      // STEP 2: Obtain the two children

      for (int k = 0; k < crosspoint1; k++) {
        offspring1Vars.variables_[k] = parent1Vars.variables_[k].deepCopy();
        offspring2Vars.variables_[k] = parent2Vars.variables_[k].deepCopy();
      }

      for (int k = crosspoint1; k < crosspoint2; k++) {
        offspring2Vars.variables_[k] = parent1Vars.variables_[k].deepCopy();
        offspring1Vars.variables_[k] = parent2Vars.variables_[k].deepCopy();
      } // for

      for (int k = crosspoint2; k < chromosomeLength; k++) {
        offspring1Vars.variables_[k] = parent1Vars.variables_[k].deepCopy();
        offspring2Vars.variables_[k] = parent2Vars.variables_[k].deepCopy();
      }

      Comparator dominance = new DominanceComparator();

      if (((dominance.compare(parent1, parent2) != -1)
              && (crosspoint2 - crosspoint1 >= chromosomeLength / 2))
          || ((dominance.compare(parent1, parent2) == -1)
              && (crosspoint2 - crosspoint1 < chromosomeLength / 2))) {
        offspring[0].setDecisionVariables(offspring1Vars);
        offspring[1].setDecisionVariables(offspring2Vars);
      } else if (((dominance.compare(parent2, parent1) != -1)
              && (crosspoint2 - crosspoint1 >= chromosomeLength / 2))
          || ((dominance.compare(parent2, parent1) == -1)
              && (crosspoint2 - crosspoint1 < chromosomeLength / 2))) {
        offspring[1].setDecisionVariables(offspring1Vars);
        offspring[0].setDecisionVariables(offspring2Vars);
      }

      //    else
      //    {
      //      Configuration.logger_.severe("TwoPointsCrossover.doCrossover: invalid " +
      //          "type" +
      //          parent1.getDecisionVariables().variables_[0].getVariableType());
      //      Class cls = java.lang.String.class;
      //      String name = cls.getName();
      //      throw new JMException("Exception in " + name + ".doCrossover()") ;
      //    } // else

    }

    return offspring;
  } // makeCrossover