[1]:
from jmetal.algorithm.multiobjective.hype import HYPE
from jmetal.core.solution import FloatSolution
from jmetal.operator.crossover import SBXCrossover
from jmetal.operator.mutation import PolynomialMutation
from jmetal.problem import ZDT1
from jmetal.util.termination_criterion import StoppingByEvaluations
problem = ZDT1()
reference_point = FloatSolution([0], [1], problem.number_of_objectives, )
reference_point.objectives = [1., 1.] # Mandatory for HYPE
algorithm = HYPE(
problem=problem,
reference_point=reference_point,
population_size=100,
offspring_population_size=100,
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
crossover=SBXCrossover(probability=1.0, distribution_index=20),
termination_criterion=StoppingByEvaluations(2500)
)
algorithm.run()
solutions = algorithm.get_result()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 10
6 from jmetal.util.termination_criterion import StoppingByEvaluations
8 problem = ZDT1()
---> 10 reference_point = FloatSolution([0], [1], problem.number_of_objectives, )
11 reference_point.objectives = [1., 1.] # Mandatory for HYPE
13 algorithm = HYPE(
14 problem=problem,
15 reference_point=reference_point,
(...)
20 termination_criterion=StoppingByEvaluations(2500)
21 )
File ~/anaconda3/envs/jmetalpy/lib/python3.9/site-packages/jmetal/core/solution.py:76, in FloatSolution.__init__(self, lower_bound, upper_bound, number_of_objectives, number_of_constraints)
69 def __init__(
70 self,
71 lower_bound: List[float],
(...)
74 number_of_constraints: int = 0
75 ):
---> 76 super(FloatSolution, self).__init__(len(lower_bound), number_of_objectives, number_of_constraints)
77 self.lower_bound = lower_bound
78 self.upper_bound = upper_bound
File ~/anaconda3/envs/jmetalpy/lib/python3.9/site-packages/jmetal/core/solution.py:15, in Solution.__init__(self, number_of_variables, number_of_objectives, number_of_constraints)
13 def __init__(self, number_of_variables: int, number_of_objectives: int, number_of_constraints: int = 0):
14 self.variables = [[] for _ in range(number_of_variables)]
---> 15 self.objectives = [0.0 for _ in range(number_of_objectives)]
16 self.constraints = [0.0 for _ in range(number_of_constraints)]
17 self.attributes = {}
TypeError: 'method' object cannot be interpreted as an integer
We can now visualize the Pareto front approximation:
[ ]:
from jmetal.lab.visualization.plotting import Plot
from jmetal.util.solution import get_non_dominated_solutions
front = get_non_dominated_solutions(solutions)
plot_front = Plot(plot_title='Pareto front approximation', axis_labels=['x', 'y'])
plot_front.plot(front, label='HYPE-ZDT1')
Bases: GeneticAlgorithm
[S
, R
]