コード例 #1
0
  /**
   * Returns {@code true} if all decision variables are assignment-compatible with the specified
   * type; {@code false} otherwise.
   *
   * @param type the type of decision variable
   * @param problem the problem
   * @return {@code true} if all decision variables are assignment-compatible with the specified
   *     type; {@code false} otherwise
   */
  private boolean checkType(Class<? extends Variable> type, Problem problem) {
    Solution solution = problem.newSolution();

    for (int i = 0; i < solution.getNumberOfVariables(); i++) {
      if (!type.isInstance(solution.getVariable(i))) {
        return false;
      }
    }

    return true;
  }
コード例 #2
0
  @Override
  public Solution[] initialize() {
    Solution[] initialPopulation = new Solution[populationSize];

    for (int i = 0; i < populationSize; i++) {
      Solution solution = problem.newSolution();

      for (int j = 0; j < solution.getNumberOfVariables(); j++) {
        solution.getVariable(j).randomize();
      }

      initialPopulation[i] = solution;
    }

    return initialPopulation;
  }