Пример #1
0
  /**
   * Evolves the specified variables using the SSX operator.
   *
   * @param s1 the first subset
   * @param s2 the second subset
   */
  public static void evolve(Subset s1, Subset s2) {
    int k = s1.getK();
    Set<Integer> p1set = s1.getSet();
    Set<Integer> p2set = s2.getSet();

    for (int i = 0; i < k; i++) {
      if (!p1set.contains(s2.get(i)) && !p2set.contains(s1.get(i)) && PRNG.nextBoolean()) {
        int temp = s1.get(i);
        s1.set(i, s2.get(i));
        s2.set(i, temp);
      }
    }
  }
Пример #2
0
  @Override
  public Solution generate() {
    Solution solution = newSolution();

    for (int i = 0; i < numberOfObjectives - 1; i++) {
      ((RealVariable) solution.getVariable(i)).setValue(PRNG.nextDouble());
    }

    for (int i = numberOfObjectives - 1; i < numberOfVariables; i++) {
      ((RealVariable) solution.getVariable(i)).setValue(0);
    }

    evaluate(solution);

    return solution;
  }
Пример #3
0
  @Override
  protected void iterate() {
    ReferenceVectorGuidedPopulation population = getPopulation();
    Population offspring = new Population();
    int populationSize = population.size();

    // update the scaling factor for computing the angle-penalized distance
    population.setScalingFactor(Math.min(generation / (double) maxGeneration, 1.0));

    // create a random permutation of the population indices
    List<Integer> indices = new ArrayList<Integer>();

    for (int i = 0; i < populationSize; i++) {
      indices.add(i);
    }

    PRNG.shuffle(indices);

    // add an extra entry so the number of indices is even
    if (indices.size() % 2 == 1) {
      indices.add(indices.get(0));
    }

    // generate the offspring
    for (int i = 0; i < indices.size(); i += 2) {
      Solution[] parents =
          new Solution[] {population.get(indices.get(i)), population.get(indices.get(i + 1))};
      Solution[] children = variation.evolve(parents);

      offspring.addAll(children);
    }

    evaluateAll(offspring);

    // select the survivors
    population.addAll(offspring);
    population.truncate();

    // periodically normalize the reference vectors
    if ((generation > 0) && (generation % adaptFrequency == 0)) {
      population.adapt();
    }

    generation++;
  }
Пример #4
0
  @Override
  public Solution[] evolve(Solution[] parents) {
    Solution result1 = parents[0].copy();
    Solution result2 = parents[1].copy();

    for (int i = 0; i < result1.getNumberOfVariables(); i++) {
      Variable variable1 = result1.getVariable(i);
      Variable variable2 = result2.getVariable(i);

      if ((PRNG.nextDouble() <= probability)
          && (variable1 instanceof Subset)
          && (variable2 instanceof Subset)) {
        evolve((Subset) variable1, (Subset) variable2);
      }
    }

    return new Solution[] {result1, result2};
  }