Skip to content

Instantly share code, notes, and snippets.

@fmder
Last active May 31, 2019 09:43
Show Gist options
  • Save fmder/2b106ee2b8e4e2fcffb5fb7492e6edb9 to your computer and use it in GitHub Desktop.
Save fmder/2b106ee2b8e4e2fcffb5fb7492e6edb9 to your computer and use it in GitHub Desktop.
DTLZ1 pymoo
from math import factorial
from pymoo.optimize import minimize
from pymoo.util import plotting
from pymoo.util.reference_direction import UniformReferenceDirectionFactory
from pymop.factory import get_problem
from pymoo.algorithms.nsga3 import nsga3
import matplotlib.pyplot as plt
import numpy
from pymoo.indicators.igd import IGD
PROBLEM = "dtlz1"
NOBJ = 3
K = 5
NDIM = NOBJ + K - 1
P = 12
H = factorial(NOBJ + P - 1) / (factorial(P) * factorial(NOBJ - 1))
MU = int(H + (4 - H % 4))
NGEN = 400
# create the reference directions to be used for the optimization
ref_dirs = UniformReferenceDirectionFactory(NOBJ, n_points=H).do()
# create the algorithm object
method = nsga3(pop_size=MU,
ref_dirs=ref_dirs)
problem = get_problem(PROBLEM, n_var=NDIM, n_obj=NOBJ)
pf = problem.pareto_front(ref_dirs)
# execute the optimization
res = minimize(problem,
method,
termination=('n_gen', NGEN),
pf=pf)
# print(igd(res.F, ref_dirs))
print(IGD(pf).calc(res.F))
print(numpy.min(res.F, axis=0), numpy.max(res.F, axis=0))
ax = plotting.plot(res.F, show=False, alpha=1.0)
ax.view_init(45, 45)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment