Skip to content

Commit 23a185c

Browse files
committed
Add example of NSGA-III with a 4D problem
1 parent 29adfd3 commit 23a185c

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from jmetal.algorithm.multiobjective.nsgaiii import (
2+
NSGAIII,
3+
UniformReferenceDirectionFactory,
4+
)
5+
from jmetal.operator.crossover import SBXCrossover
6+
from jmetal.operator.mutation import PolynomialMutation
7+
from jmetal.problem import DTLZ2
8+
from jmetal.util.solution import (
9+
get_non_dominated_solutions,
10+
print_function_values_to_file,
11+
print_variables_to_file,
12+
read_solutions,
13+
)
14+
from jmetal.util.termination_criterion import StoppingByEvaluations
15+
16+
if __name__ == "__main__":
17+
problem = DTLZ2(12, 4)
18+
19+
max_evaluations = 30000
20+
21+
algorithm = NSGAIII(
22+
problem=problem,
23+
population_size=100,
24+
reference_directions=UniformReferenceDirectionFactory(4, n_points=100),
25+
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables(), distribution_index=20),
26+
crossover=SBXCrossover(probability=1.0, distribution_index=20),
27+
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
28+
)
29+
30+
algorithm.run()
31+
front = get_non_dominated_solutions(algorithm.result())
32+
33+
# Save results to file
34+
print_function_values_to_file(front, "FUN." + algorithm.label)
35+
print_variables_to_file(front, "VAR." + algorithm.label)
36+
37+
print(f"Algorithm: {algorithm.get_name()}")
38+
print(f"Problem: {problem.name()}")
39+
print(f"Computing time: {algorithm.total_computing_time}")

0 commit comments

Comments
 (0)