/** * 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; }
@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; }