Skip to content

Instantly share code, notes, and snippets.

@dhadka
Last active December 20, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhadka/5fe6946b4b6403b0c8fc to your computer and use it in GitHub Desktop.
Save dhadka/5fe6946b4b6403b0c8fc to your computer and use it in GitHub Desktop.
Creating an instance of NSGA-III
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 = 5;
} 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;
}
}));
}
Variation variation = OperatorFactory.getInstance().getVariation(null,
properties, problem);
return new NSGAII(problem, population, null, selection, variation,
initialization);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment