-
Notifications
You must be signed in to change notification settings - Fork 21
/
moo_functions.py
67 lines (53 loc) · 1.73 KB
/
moo_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
from math import sqrt, sin, pi, cos, exp
from utils import FitObjPair
# these implementations are based on those from the deap library
# https://github.com/DEAP/deap/
def get_function_by_name(name):
if name == 'ZDT1':
return zdt1
if name == 'ZDT2':
return zdt2
if name == 'ZDT3':
return zdt3
if name == 'ZDT4':
return zdt4
if name == 'ZDT6':
return zdt6
raise RuntimeError(f'Specified benchmark function ({name}) not found.')
opt_hvs = {
'ZDT1': 120.0 + 2/3,
'ZDT2': 120.0 + 1/3,
'ZDT3': 128.77811613069076060,
'ZDT4': 120.0 + 2/3,
'ZDT6': 117.51857519692037009,
}
def get_opt_hypervolume(name):
if name in opt_hvs.keys():
return opt_hvs[name]
raise RuntimeError(f'Specified benchmark function ({name}) not found.')
def zdt1(individual):
g = 1.0 + 9.0*sum(individual.x[1:])/(len(individual.x)-1)
f1 = individual.x[0]
f2 = g * (1 - sqrt(f1/g))
return (f1, f2)
def zdt2(individual):
g = 1.0 + 9.0*sum(individual.x[1:])/(len(individual.x)-1)
f1 = individual.x[0]
f2 = g * (1 - (f1/g)**2)
return (f1, f2)
def zdt3(individual):
g = 1.0 + 9.0*sum(individual.x[1:])/(len(individual.x)-1)
f1 = individual.x[0]
f2 = g * (1 - sqrt(f1/g) - f1/g * sin(10*pi*f1))
return (f1, f2)
def zdt4(individual):
g = 1 + 10*(len(individual.x)-1) + sum(xi**2 - 10*cos(4*pi*xi) for xi in individual.x[1:])
f1 = individual.x[0]
f2 = g * (1 - sqrt(f1/g))
return (f1, f2)
def zdt6(individual):
g = 1 + 9 * (sum(individual.x[1:]) / (len(individual.x)-1))**0.25
f1 = 1 - exp(-4*individual.x[0]) * sin(6*pi*individual.x[0])**6
f2 = g * (1 - (f1/g)**2)
return (f1, f2)