コード例 #1
0
ファイル: SolutionListUtils.java プロジェクト: jMetal/jMetal
  /**
   * This method receives a normalized list of non-dominated solutions and return the inverted one.
   * This operation is needed for minimization problem
   *
   * @param solutionList The front to invert
   * @return The inverted front
   */
  public static <S extends Solution<?>> List<S> selectNRandomDifferentSolutions(
      int numberOfSolutionsToBeReturned, List<S> solutionList) {
    if (null == solutionList) {
      throw new JMetalException("The solution list is null");
    } else if (solutionList.size() == 0) {
      throw new JMetalException("The solution list is empty");
    } else if (solutionList.size() < numberOfSolutionsToBeReturned) {
      throw new JMetalException(
          "The solution list size ("
              + solutionList.size()
              + ") is less than "
              + "the number of requested solutions ("
              + numberOfSolutionsToBeReturned
              + ")");
    }

    JMetalRandom randomGenerator = JMetalRandom.getInstance();
    List<S> resultList = new ArrayList<>(numberOfSolutionsToBeReturned);

    if (solutionList.size() == 1) {
      resultList.add(solutionList.get(0));
    } else {
      Collection<Integer> positions = new HashSet<>(numberOfSolutionsToBeReturned);
      while (positions.size() < numberOfSolutionsToBeReturned) {
        int nextPosition = randomGenerator.nextInt(0, solutionList.size() - 1);
        if (!positions.contains(nextPosition)) {
          positions.add(nextPosition);
          resultList.add(solutionList.get(nextPosition));
        }
      }
    }

    return resultList;
  }
コード例 #2
0
  @Before
  public void setup() {

    random = JMetalRandom.getInstance();
    random.setSeed(2);
    operator = new ExhaustiveSearchMutationOperator(1.0, random, aminoAcidSequence, 40);
    proteinBuilder = new ProteinBuilder();
  }
コード例 #3
0
  /**
   * Checks if the value is between its bounds; if not, a random value between the limits is
   * returned
   *
   * @param value The value to be checked
   * @param lowerBound
   * @param upperBound
   * @return The same value if it is between the limits or a repaired value otherwise
   */
  public double repairSolutionVariableValue(double value, double lowerBound, double upperBound) {
    if (lowerBound > upperBound) {
      throw new JMetalException(
          "The lower bound ("
              + lowerBound
              + ") is greater than the "
              + "upper bound ("
              + upperBound
              + ")");
    }
    double result = value;
    if (value < lowerBound) {
      result = randomGenerator.nextDouble(lowerBound, upperBound);
    }
    if (value > upperBound) {
      result = randomGenerator.nextDouble(lowerBound, upperBound);
    }

    return result;
  }
コード例 #4
0
  int FindNicheReferencePoint() {
    // find the minimal cluster size
    int min_size = Integer.MAX_VALUE;
    for (ReferencePoint<S> referencePoint : this.referencePoints)
      min_size = Math.min(min_size, referencePoint.MemberSize());

    // find the reference points with the minimal cluster size Jmin
    List<Integer> min_rps = new ArrayList<>();

    for (int r = 0; r < this.referencePoints.size(); r += 1) {
      if (this.referencePoints.get(r).MemberSize() == min_size) {
        min_rps.add(r);
      }
    }
    // return a random reference point (j-bar)
    return min_rps.get(
        min_rps.size() > 1 ? JMetalRandom.getInstance().nextInt(0, min_rps.size() - 1) : 0);
  }
コード例 #5
0
 /** Constructor */
 public RepairDoubleSolutionAtRandom() {
   randomGenerator = JMetalRandom.getInstance();
 }