@Override public void assignObjectives( MOOptimisationProblem problem, List<SinglePopulationBasedAlgorithm> populations) { if (problem.size() > populations.size()) { throw new IllegalArgumentException( "There are more objectives than the number of populations required to solve this multi-objective problem."); } for (int i = 0; i < populations.size(); ++i) { CriterionBasedMOProblemAdapter problemAdapter = new CriterionBasedMOProblemAdapter(problem); problemAdapter.setActiveOptimisationProblem(problem.get(i % problem.size())); populations.get(i).setOptimisationProblem(problemAdapter); } }
/** {@inheritDoc} */ @Override public int compare(E o1, E o2) { SinglePopulationBasedAlgorithm populationBasedAlgorithm = (SinglePopulationBasedAlgorithm) AbstractAlgorithm.getAlgorithmList().index(0); MOOptimisationProblem problem = ((MOOptimisationProblem) populationBasedAlgorithm.getOptimisationProblem()); Particle p1 = (Particle) o1; Particle p2 = (Particle) o2; MOFitness fitness1 = ((MOFitness) problem.getFitness(p1.getBestPosition())); MOFitness fitness2 = ((MOFitness) problem.getFitness(p2.getBestPosition())); int value = fitness1.compareTo(fitness2); if (fitness1.compareTo(fitness2) == 0) { int random = Rand.nextInt(20); if (random > 10) value *= -1; } return value; }