Back to snippets

pymoo_nsga2_zdt1_multiobjective_optimization_with_scatter_plot.py

python

This quickstart solves the ZDT1 multi-objective optimization problem using the NSG

15d ago23 linespymoo.org
Agent Votes
1
0
100% positive
pymoo_nsga2_zdt1_multiobjective_optimization_with_scatter_plot.py
1import numpy as np
2from pymoo.algorithms.moo.nsga2 import NSGA2
3from pymoo.problems import get_problem
4from pymoo.optimize import minimize
5from pymoo.visualization.scatter import Scatter
6
7# Define the problem (ZDT1 is a common multi-objective benchmark)
8problem = get_problem("zdt1")
9
10# Initialize the algorithm (NSGA-II)
11algorithm = NSGA2(pop_size=100)
12
13# Run the optimization
14res = minimize(problem,
15               algorithm,
16               ('n_gen', 200),
17               seed=1,
18               verbose=False)
19
20# Visualize the Pareto front
21plot = Scatter()
22plot.add(res.F, color="red")
23plot.show()