NSGA-II

Common imports for these examples:

from jmetal.algorithm import NSGAII
from jmetal.operator import Polynomial, SBX, BinaryTournamentSelection
from jmetal.component import RankingAndCrowdingDistanceComparator

from jmetal.util import FrontPlot

NSGA-II with plotting

from jmetal.problem import ZDT1

 problem = ZDT1(rf_path='resources/reference_front/ZDT1.pf')

 algorithm = NSGAII(
     problem=problem,
     population_size=100,
     max_evaluations=25000,
     mutation=Polynomial(probability=1.0/problem.number_of_variables, distribution_index=20),
     crossover=SBX(probability=1.0, distribution_index=20),
     selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator())
 )

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

 pareto_front = FrontPlot(plot_title='NSGAII-ZDT1', axis_labels=problem.obj_labels)
 pareto_front.plot(front, reference_front=problem.reference_front)
 pareto_front.to_html(filename='NSGAII-ZDT1')
from jmetal.problem import DTLZ1

 problem = DTLZ1(rf_path='resources/reference_front/DTLZ1.pf')

 algorithm = NSGAII(
     problem=problem,
     population_size=100,
     max_evaluations=50000,
     mutation=Polynomial(probability=1.0/problem.number_of_variables, distribution_index=20),
     crossover=SBX(probability=1.0, distribution_index=20),
     selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator())
 )

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

 pareto_front = FrontPlot(plot_title='NSGAII-DTLZ1', axis_labels=problem.obj_labels)
 pareto_front.plot(front, reference_front=problem.reference_front)
 pareto_front.to_html(filename='NSGAII-DTLZ1')

NSGA-II stopping by time

from jmetal.problem import ZDT1


class NSGA2b(NSGAII):
   def is_stopping_condition_reached(self):
      # Re-define the stopping condition
      return [False, True][self.get_current_computing_time() > 4]

problem = ZDT1()

algorithm = NSGA2b(
   problem=problem,
   population_size=100,
   max_evaluations=25000,
   mutation=Polynomial(probability=1.0/problem.number_of_variables, distribution_index=20),
   crossover=SBX(probability=1.0, distribution_index=20),
   selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator())
)

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