/**
   * Returns a new {@link DBEA} instance.
   *
   * @param properties the properties for customizing the new {@code DBEA} instance
   * @param problem the problem
   * @return a new {@code DBEA} instance
   */
  private Algorithm newDBEA(TypedProperties properties, Problem problem) {
    int divisionsOuter = 4;
    int divisionsInner = 0;

    if (properties.contains("divisionsOuter") && properties.contains("divisionsInner")) {
      divisionsOuter = (int) properties.getDouble("divisionsOuter", 4);
      divisionsInner = (int) properties.getDouble("divisionsInner", 0);
    } else if (properties.contains("divisions")) {
      divisionsOuter = (int) properties.getDouble("divisions", 4);
    } else if (problem.getNumberOfObjectives() == 1) {
      divisionsOuter = 100;
    } else if (problem.getNumberOfObjectives() == 2) {
      divisionsOuter = 99;
    } else if (problem.getNumberOfObjectives() == 3) {
      divisionsOuter = 12;
    } else if (problem.getNumberOfObjectives() == 4) {
      divisionsOuter = 8;
    } else if (problem.getNumberOfObjectives() == 5) {
      divisionsOuter = 6;
    } else if (problem.getNumberOfObjectives() == 6) {
      divisionsOuter = 4;
      divisionsInner = 1;
    } else if (problem.getNumberOfObjectives() == 7) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 8) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 9) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 10) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else {
      divisionsOuter = 2;
      divisionsInner = 1;
    }

    int populationSize =
        (int)
            (CombinatoricsUtils.binomialCoefficient(
                    problem.getNumberOfObjectives() + divisionsOuter - 1, divisionsOuter)
                + (divisionsInner == 0
                    ? 0
                    : CombinatoricsUtils.binomialCoefficient(
                        problem.getNumberOfObjectives() + divisionsInner - 1, divisionsInner)));

    Initialization initialization = new RandomInitialization(problem, populationSize);

    Variation variation = OperatorFactory.getInstance().getVariation(null, properties, problem);

    return new DBEA(problem, initialization, variation, divisionsOuter, divisionsInner);
  }
 @Test
 public void testJacobiEvaluationAt1() {
   for (int v = 0; v < 10; ++v) {
     for (int w = 0; w < 10; ++w) {
       for (int i = 0; i < 10; ++i) {
         PolynomialFunction jacobi = PolynomialsUtils.createJacobiPolynomial(i, v, w);
         double binomial = CombinatoricsUtils.binomialCoefficient(v + i, i);
         Assert.assertTrue(Precision.equals(binomial, jacobi.value(1.0), 1));
       }
     }
   }
 }
Ejemplo n.º 3
0
 @Override
 public final IFuzzyValue<Boolean> execute(
     final IContext p_context,
     final boolean p_parallel,
     final List<ITerm> p_argument,
     final List<ITerm> p_return,
     final List<ITerm> p_annotation) {
   CCommon.flatcollection(p_argument)
       .stream()
       .map(i -> CombinatoricsUtils.factorial(i.<Number>raw().intValue()))
       .map(CRawTerm::from)
       .forEach(p_return::add);
   return CFuzzyValue.from(true);
 }
  /**
   * Returns a new {@link RVEA} instance.
   *
   * @param properties the properties for customizing the new {@code RVEA} instance
   * @param problem the problem
   * @return a new {@code RVEA} instance
   */
  private Algorithm newRVEA(TypedProperties properties, Problem problem) {
    int divisionsOuter = 4;
    int divisionsInner = 0;

    if (problem.getNumberOfObjectives() < 2) {
      throw new FrameworkException("RVEA requires at least two objectives");
    }

    if (properties.contains("divisionsOuter") && properties.contains("divisionsInner")) {
      divisionsOuter = (int) properties.getDouble("divisionsOuter", 4);
      divisionsInner = (int) properties.getDouble("divisionsInner", 0);
    } else if (properties.contains("divisions")) {
      divisionsOuter = (int) properties.getDouble("divisions", 4);
    } else if (problem.getNumberOfObjectives() == 1) {
      divisionsOuter = 100;
    } else if (problem.getNumberOfObjectives() == 2) {
      divisionsOuter = 99;
    } else if (problem.getNumberOfObjectives() == 3) {
      divisionsOuter = 12;
    } else if (problem.getNumberOfObjectives() == 4) {
      divisionsOuter = 8;
    } else if (problem.getNumberOfObjectives() == 5) {
      divisionsOuter = 6;
    } else if (problem.getNumberOfObjectives() == 6) {
      divisionsOuter = 4;
      divisionsInner = 1;
    } else if (problem.getNumberOfObjectives() == 7) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 8) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 9) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 10) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else {
      divisionsOuter = 2;
      divisionsInner = 1;
    }

    // compute number of reference vectors
    int populationSize =
        (int)
            (CombinatoricsUtils.binomialCoefficient(
                    problem.getNumberOfObjectives() + divisionsOuter - 1, divisionsOuter)
                + (divisionsInner == 0
                    ? 0
                    : CombinatoricsUtils.binomialCoefficient(
                        problem.getNumberOfObjectives() + divisionsInner - 1, divisionsInner)));

    Initialization initialization = new RandomInitialization(problem, populationSize);

    ReferenceVectorGuidedPopulation population =
        new ReferenceVectorGuidedPopulation(
            problem.getNumberOfObjectives(),
            divisionsOuter,
            divisionsInner,
            properties.getDouble("alpha", 2.0));

    if (!properties.contains("sbx.swap")) {
      properties.setBoolean("sbx.swap", false);
    }

    if (!properties.contains("sbx.distributionIndex")) {
      properties.setDouble("sbx.distributionIndex", 30.0);
    }

    if (!properties.contains("pm.distributionIndex")) {
      properties.setDouble("pm.distributionIndex", 20.0);
    }

    Variation variation = OperatorFactory.getInstance().getVariation(null, properties, problem);

    int maxGenerations = (int) (properties.getDouble("maxEvaluations", 10000) / populationSize);
    int adaptFrequency = (int) properties.getDouble("adaptFrequency", maxGenerations / 10);

    return new RVEA(problem, population, variation, initialization, maxGenerations, adaptFrequency);
  }
  /**
   * Returns a new {@link NSGAIII} instance.
   *
   * @param properties the properties for customizing the new {@code NSGAIII} instance
   * @param problem the problem
   * @return a new {@code NSGAIII} instance
   */
  private Algorithm newNSGAIII(TypedProperties properties, Problem problem) {
    int divisionsOuter = 4;
    int divisionsInner = 0;

    if (properties.contains("divisionsOuter") && properties.contains("divisionsInner")) {
      divisionsOuter = (int) properties.getDouble("divisionsOuter", 4);
      divisionsInner = (int) properties.getDouble("divisionsInner", 0);
    } else if (properties.contains("divisions")) {
      divisionsOuter = (int) properties.getDouble("divisions", 4);
    } else if (problem.getNumberOfObjectives() == 1) {
      divisionsOuter = 100;
    } else if (problem.getNumberOfObjectives() == 2) {
      divisionsOuter = 99;
    } else if (problem.getNumberOfObjectives() == 3) {
      divisionsOuter = 12;
    } else if (problem.getNumberOfObjectives() == 4) {
      divisionsOuter = 8;
    } else if (problem.getNumberOfObjectives() == 5) {
      divisionsOuter = 6;
    } else if (problem.getNumberOfObjectives() == 6) {
      divisionsOuter = 4;
      divisionsInner = 1;
    } else if (problem.getNumberOfObjectives() == 7) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 8) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 9) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else if (problem.getNumberOfObjectives() == 10) {
      divisionsOuter = 3;
      divisionsInner = 2;
    } else {
      divisionsOuter = 2;
      divisionsInner = 1;
    }

    int populationSize;

    if (properties.contains("populationSize")) {
      populationSize = (int) properties.getDouble("populationSize", 100);
    } else {
      // compute number of reference points
      populationSize =
          (int)
              (CombinatoricsUtils.binomialCoefficient(
                      problem.getNumberOfObjectives() + divisionsOuter - 1, divisionsOuter)
                  + (divisionsInner == 0
                      ? 0
                      : CombinatoricsUtils.binomialCoefficient(
                          problem.getNumberOfObjectives() + divisionsInner - 1, divisionsInner)));

      // round up to a multiple of 4
      populationSize = (int) Math.ceil(populationSize / 4d) * 4;
    }

    Initialization initialization = new RandomInitialization(problem, populationSize);

    ReferencePointNondominatedSortingPopulation population =
        new ReferencePointNondominatedSortingPopulation(
            problem.getNumberOfObjectives(), divisionsOuter, divisionsInner);

    Selection selection = null;

    if (problem.getNumberOfConstraints() == 0) {
      selection =
          new Selection() {

            @Override
            public Solution[] select(int arity, Population population) {
              Solution[] result = new Solution[arity];

              for (int i = 0; i < arity; i++) {
                result[i] = population.get(PRNG.nextInt(population.size()));
              }

              return result;
            }
          };
    } else {
      selection =
          new TournamentSelection(
              2,
              new ChainedComparator(
                  new AggregateConstraintComparator(),
                  new DominanceComparator() {

                    @Override
                    public int compare(Solution solution1, Solution solution2) {
                      return PRNG.nextBoolean() ? -1 : 1;
                    }
                  }));
    }

    // disable swapping variables in SBX operator to remain consistent with
    // Deb's implementation (thanks to Haitham Seada for identifying this
    // discrepancy)
    if (!properties.contains("sbx.swap")) {
      properties.setBoolean("sbx.swap", false);
    }

    if (!properties.contains("sbx.distributionIndex")) {
      properties.setDouble("sbx.distributionIndex", 30.0);
    }

    if (!properties.contains("pm.distributionIndex")) {
      properties.setDouble("pm.distributionIndex", 20.0);
    }

    Variation variation = OperatorFactory.getInstance().getVariation(null, properties, problem);

    return new NSGAII(problem, population, null, selection, variation, initialization);
  }