-
Notifications
You must be signed in to change notification settings - Fork 0
/
Benchmark.py
120 lines (83 loc) · 2.68 KB
/
Benchmark.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from deap import benchmarks
from math import sin
class Benchmark:
def __init__(self, nvar=2):
self.fitness = None
self.name = None
self.limitInf = None
self.limitSup = None
self.step = None
self.nvar = nvar
def getRosenbrockInfo(self):
self.fitness = self._rosenbrock
self.name = "Rosenbrock"
self.limitInf = [-2]*self.nvar
self.limitSup = [2]*self.nvar
self.step = 0.1
return self
def getSchafferInfo(self):
self.fitness = self._schaffer
self.name = "Schaffer"
self.limitInf = [-100]*self.nvar
self.limitSup = [100]*self.nvar
self.step = 0.25
return self
def getHimmelblauInfo(self):
self.fitness = self._himmelblau
self.name = "Himmelblau"
self.limitInf = [-6]*self.nvar
self.limitSup = [6]*self.nvar
self.step = 0.1
return self
def getSchwefelInfo(self):
self.fitness = self._schwefel
self.name = "Schwefel"
self.limitInf = [-500]*self.nvar
self.limitSup = [500]*self.nvar
self.step = 10
return self
def getRastriginInfo(self):
self.fitness = self._rastrigin
self.name = "Rastrigin"
self.limitInf = [-5]*self.nvar
self.limitSup = [5]*self.nvar
self.step = 0.1
return self
def getBohachevskyInfo(self):
self.fitness = self._bohachevsky
self.name = "Bohachevsky"
self.limitInf = [-100]*self.nvar
self.limitSup = [100]*self.nvar
self.step = 0.5
return self
def getAckleyInfo(self):
self.fitness = self._ackley
self.name = "Ackley"
self.limitInf = [-30]*self.nvar
self.limitSup = [30]*self.nvar
self.step = 0.5
return self
def getHauptInfo(self):
self.fitness = self._haupt
self.name = "Haupt"
self.limitInf = 0
self.limitSup = 10
self.step = 0.05
return self
def _haupt(self, individual):
# y = x1*sin(4*x1) + 1.1*x2*sin(2*x2)
return individual[1] * sin(4 * individual[1]) + 1.1 * individual[0] * sin(2 * individual[0]),
def _schwefel(self, sol):
return benchmarks.schwefel(sol)
def _himmelblau(self, sol):
return benchmarks.himmelblau(sol)
def _rastrigin(self, sol):
return benchmarks.rastrigin(sol)
def _rosenbrock(self, sol):
return benchmarks.rosenbrock(sol)
def _schaffer(self, sol):
return benchmarks.schaffer(sol)
def _ackley(self, sol):
return benchmarks.ackley(sol)
def _bohachevsky(self, sol):
return benchmarks.bohachevsky(sol)