Exemplo n.º 1
0
  public List<Integer> tour_selection(int depth) {

    // selection based on utility
    List<Integer> selected = new ArrayList<Integer>();
    List<Integer> candidate = new ArrayList<Integer>();

    for (int k = 0; k < problem_.getNumberOfObjectives(); k++) {
      selected.add(
          k); // WARNING! HERE YOU HAVE TO USE THE WEIGHT PROVIDED BY QINGFU (NOT SORTED!!!!)
    }

    for (int n = problem_.getNumberOfObjectives(); n < populationSize; n++) {
      candidate.add(n); // set of unselected weights
    }
    while (selected.size() < (int) (populationSize / 5.0)) {
      // int best_idd = (int) (rnd_uni(&rnd_uni_init)*candidate.size()), i2;
      int best_idd = (int) (PseudoRandom.randDouble() * candidate.size());
      // System.out.println(best_idd);
      int i2;
      int best_sub = candidate.get(best_idd);
      int s2;
      for (int i = 1; i < depth; i++) {
        i2 = (int) (PseudoRandom.randDouble() * candidate.size());
        s2 = candidate.get(i2);
        // System.out.println("Candidate: "+i2);
        if (utility_[s2] > utility_[best_sub]) {
          best_idd = i2;
          best_sub = s2;
        }
      }
      selected.add(best_sub);
      candidate.remove(best_idd);
    }
    return selected;
  }
Exemplo n.º 2
0
  /**
   * @author Juanjo This method selects N solutions from a set M, where N <= M using the same method
   *     proposed by Qingfu Zhang, W. Liu, and Hui Li in the paper describing MOEA/D-DRA (CEC 09
   *     COMPTETITION) An example is giving in that paper for two objectives. If N = 100, then the
   *     best solutions attenting to the weights (0,1), (1/99,98/99), ...,(98/99,1/99), (1,0) are
   *     selected.
   *     <p>Using this method result in 101 solutions instead of 100. We will just compute 100 even
   *     distributed weights and used them. The result is the same
   *     <p>In case of more than two objectives the procedure is: 1- Select a solution at random 2-
   *     Select the solution from the population which have maximum distance to it (whithout
   *     considering the already included)
   * @param n: The number of solutions to return
   * @return A solution set containing those elements
   */
  SolutionSet finalSelection(int n) throws JMException {
    SolutionSet res = new SolutionSet(n);
    if (problem_.getNumberOfObjectives() == 2) { // subcase 1
      double[][] intern_lambda = new double[n][2];
      for (int i = 0; i < n; i++) {
        double a = 1.0 * i / (n - 1);
        intern_lambda[i][0] = a;
        intern_lambda[i][1] = 1 - a;
      } // for

      // we have now the weights, now select the best solution for each of them
      for (int i = 0; i < n; i++) {
        Solution current_best = population.get(0);
        int index = 0;
        double value = fitnessFunction(current_best, intern_lambda[i]);
        for (int j = 1; j < n; j++) {
          double aux =
              fitnessFunction(
                  population.get(j), intern_lambda[i]); // we are looking the best for the weight i
          if (aux < value) { // solution in position j is better!
            value = aux;
            current_best = population.get(j);
          }
        }
        res.add(new Solution(current_best));
      }

    } else { // general case (more than two objectives)

      Distance distance_utility = new Distance();
      int random_index = PseudoRandom.randInt(0, population.size() - 1);

      // create a list containing all the solutions but the selected one (only references to them)
      List<Solution> candidate = new LinkedList<Solution>();
      candidate.add(population.get(random_index));

      for (int i = 0; i < population.size(); i++) {
        if (i != random_index) {
          candidate.add(population.get(i));
        }
      } // for

      while (res.size() < n) {
        int index = 0;
        Solution selected = candidate.get(0); // it should be a next! (n <= population size!)
        double distance_value =
            distance_utility.distanceToSolutionSetInObjectiveSpace(selected, res);
        int i = 1;
        while (i < candidate.size()) {
          Solution next_candidate = candidate.get(i);
          double aux =
              distance_value =
                  distance_utility.distanceToSolutionSetInObjectiveSpace(next_candidate, res);
          if (aux > distance_value) {
            distance_value = aux;
            index = i;
          }
          i++;
        }

        // add the selected to res and remove from candidate list
        res.add(new Solution(candidate.remove(index)));
      } //
    }
    return res;
  }