|
| 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