SPEA2

Example

[1]:
from jmetal.algorithm.multiobjective.spea2 import SPEA2
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()

max_evaluations = 20000

algorithm = SPEA2(
    problem=problem,
    population_size=40,
    offspring_population_size=40,
    mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
    crossover=SBXCrossover(probability=1.0, distribution_index=20),
    termination_criterion=StoppingByEvaluations(max=max_evaluations)
)

algorithm.run()
solutions = algorithm.get_result()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 15
      7 problem = ZDT1()
      9 max_evaluations = 20000
     11 algorithm = SPEA2(
     12     problem=problem,
     13     population_size=40,
     14     offspring_population_size=40,
---> 15     mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
     16     crossover=SBXCrossover(probability=1.0, distribution_index=20),
     17     termination_criterion=StoppingByEvaluations(max=max_evaluations)
     18 )
     20 algorithm.run()
     21 solutions = algorithm.get_result()

TypeError: unsupported operand type(s) for /: 'float' and 'method'

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='SPEA2-ZDT1')

API

class jmetal.algorithm.multiobjective.spea2.SPEA2(problem: ~jmetal.core.problem.Problem, population_size: int, offspring_population_size: int, mutation: ~jmetal.core.operator.Mutation, crossover: ~jmetal.core.operator.Crossover, termination_criterion: ~jmetal.util.termination_criterion.TerminationCriterion = <jmetal.util.termination_criterion.StoppingByEvaluations object>, population_generator: ~jmetal.util.generator.Generator = <jmetal.util.generator.RandomGenerator object>, population_evaluator: ~jmetal.util.evaluator.Evaluator = <jmetal.util.evaluator.SequentialEvaluator object>, dominance_comparator: ~jmetal.util.comparator.Comparator = <jmetal.util.comparator.DominanceComparator object>)[source]

Bases: GeneticAlgorithm[S, R]

get_name() str[source]
replacement(population: List[S], offspring_population: List[S]) List[List[S]][source]

This method joins the current and offspring populations to produce the population of the next generation by applying the ranking and crowding distance selection.

Parameters:
  • population – Parent population.

  • offspring_population – Offspring population.

Returns:

New population after ranking and crowding distance selection is applied.

result() R[source]