Пример #1
0
  private void prepareSetupBestSolutions() {

    bestDecisionVariables_ = new DecisionVariables[numberOfSolutions_];
    // Assign the best DVs of another islands
    int[] indices = RandomVector.getRandomVector_Int(numberOfSolutions_, population_.size());
    for (int i = 0; i < numberOfSolutions_; ++i)
      bestDecisionVariables_[i] = population_.get(indices[i]).getDecisionVariables();
  } // prepareBestSolutions
Пример #2
0
  private void prepareBestSolutions() {
    bestDecisionVariables_ = new DecisionVariables[numberOfSolutions_];
    Ranking ranking = new Ranking(population_);
    int remain;

    SolutionSet subfront = ranking.getSubfront(0);
    int sz = subfront.size();
    int rest = population_.size() - sz;
    int i;
    if ((sz >= bestSolutionsFirstLevel_)
        && (ranking.getNumberOfSubfronts() > 1)
        && (rest >= (numberOfSolutions_ - bestSolutionsFirstLevel_))) {
      // Subfront is enought big and the remain is assured
      int[] indices = RandomVector.getRandomVector_Int(bestSolutionsFirstLevel_, sz);
      for (i = 0; i < bestSolutionsFirstLevel_; ++i)
        bestDecisionVariables_[i] = subfront.get(indices[i]).getDecisionVariables();
      remain = numberOfSolutions_ - bestSolutionsFirstLevel_;
    } // if
    else if (rest < (numberOfSolutions_ - bestSolutionsFirstLevel_)) {
      // The rest of subfronts are so little
      int[] indices = RandomVector.getRandomVector_Int(numberOfSolutions_, sz);
      for (i = 0; i < numberOfSolutions_; ++i)
        bestDecisionVariables_[i] = subfront.get(indices[i]).getDecisionVariables();
      remain = 0;
    } // else if
    else if (numberOfSolutions_ == 1) {
      int[] indices = RandomVector.getRandomVector_Int(bestSolutionsFirstLevel_, sz);
      bestDecisionVariables_[0] = subfront.get(indices[0]).getDecisionVariables();
      remain = 0;
      i = 1;
    } // else if
    else {
      int[] indices = RandomVector.getRandomVector_Int(sz, sz);
      for (i = 0; i < sz; ++i)
        bestDecisionVariables_[i] = subfront.get(indices[i]).getDecisionVariables();
      remain = numberOfSolutions_ - sz;
    } // else

    int index = 1;
    while ((index < ranking.getNumberOfSubfronts()) && (remain > 0)) {
      subfront = ranking.getSubfront(index);
      sz = subfront.size();
      if (sz >= remain) {
        int[] indices = RandomVector.getRandomVector_Int(remain, sz);
        for (int j = 0; j < remain; ++j, ++i)
          bestDecisionVariables_[i] = subfront.get(indices[j]).getDecisionVariables();
        remain = 0;
      } // if
      else {
        int[] indices = RandomVector.getRandomVector_Int(sz, sz);
        for (int j = 0; j < sz; ++j, ++i, --remain)
          bestDecisionVariables_[i] = subfront.get(indices[j]).getDecisionVariables();
      } // else
      ++index;
    } // while
  } // prepareBestSolutions