In [1]:
def dtlz1(x, M=2):
“””
An implementation of the DTLZ1 test problem. M is the number of objectives (2 by default, override for 3).
“””
z = x[M-1:] – 0.5
gp1 = 100 * (x[M-1:].shape[0] + np.dot(z, z) – np.cos(20 * np.pi * z).sum()) + 1
f = np.array([gp1] * M)
f[0] *= 0.5 * np.prod(x[0:M-1])
for i in range(1, M-1):
f[i] *= 0.5 * np.prod(x[0:M-i-1]) * (1 – x[M-i-1])
f[M-1] *= 0.5 * (1 – x[0])
return f
def dtlz2(x, M=2):
“””
An implementation of the DTLZ2 test problem. M is the number of objectives (2 by default, override for 3).
“””
gp1 = ((x[M-1:] – 0.5)**2).sum() + 1
f = np.array([gp1] * M)
for i in range(M):
if M-i-1 > 0:
for j in range(M-i-1):
f[i] *= np.cos((np.pi * x[j]) / 2)
if i > 0:
f[i] *= np.sin((np.pi * x[M-i-1]) / 2)
return f
In [ ]: