Пример #1
0
 def test_should_constructor_create_a_valid_problem_with_default_settings(self) -> None:
     problem = ZDT6()
     self.assertEqual(10, problem.number_of_variables)
     self.assertEqual(2, problem.number_of_objectives)
     self.assertEqual(0, problem.number_of_constraints)
     self.assertEqual(10 * [0.0], problem.lower_bound)
     self.assertEqual(10 * [1.0], problem.upper_bound)
Пример #2
0
 def test_should_create_solution_create_a_valid_float_solution(self) -> None:
     problem = ZDT6()
     solution = problem.create_solution()
     self.assertEqual(10, solution.number_of_variables)
     self.assertEqual(10, len(solution.variables))
     self.assertEqual(2, solution.number_of_objectives)
     self.assertEqual(2, len(solution.objectives))
     self.assertEqual(0, problem.number_of_constraints)
     self.assertEqual(10 * [0.0], problem.lower_bound)
     self.assertEqual(10 * [1.0], problem.upper_bound)
     self.assertTrue(all(value >= 0.0 for value in solution.variables))
     self.assertTrue(all(value <= 1.0 for value in solution.variables))
Пример #3
0
 def test_should_get_name_return_the_right_name(self):
     problem = ZDT6()
     self.assertEqual("ZDT6", problem.get_name())
Пример #4
0
 def test_should_constructor_create_a_non_null_object(self) -> None:
     problem = ZDT6()
     self.assertIsNotNone(problem)
Пример #5
0
# Solving SCH Problem using NSGAII
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import SBXCrossover, PolynomialMutation
from jmetal.util.termination_criterion import StoppingByEvaluations
from jmetal.util.observer import ProgressBarObserver, VisualizerObserver
from jmetal.lab.visualization import Plot, InteractivePlot
from jmetal.problem.multiobjective.zdt import ZDT6
if __name__ == '__main__':
  problem = ZDT6()
  max_evaluations = 20000
  algorithm = NSGAII(
    problem = problem,
    population_size = 100,
    offspring_population_size = 100,
    mutation=PolynomialMutation(probability=0.05, distribution_index=20),
    crossover=SBXCrossover(probability=1.0, distribution_index=20),
    termination_criterion=StoppingByEvaluations(max=max_evaluations)
  )
  algorithm.observable.register(observer=ProgressBarObserver(max=max_evaluations))
  algorithm.observable.register(observer=VisualizerObserver(reference_front=problem.reference_front))

  algorithm.run()
  front = algorithm.get_result()

  # Plot front
  plot_front = Plot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels)
  plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name())

  # Plot interactive front
  plot_front = InteractivePlot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels)
  plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name())