-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
95 lines (69 loc) · 1.88 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
import numpy as np
from math import cos, pi
def benchmark_func(array):
fitness = three_deceptive(array)
return fitness
def branin(array, *args, **kwargs):
a = 1
b = 5.1 / (4 * pi ** 2)
c = 5 / pi
r = 6
s = 10
t = 1 / (8 * pi)
x1 = array[0]
x2 = array[1]
return (a * (x2 - b * x1 ** 2 + c * x1 - r) ** 2 + s * (1 - t) * cos(x1) + s) * -1
def schwefel(array):
sum = 0
fitness = 0
for x in array:
sum = sum + x * np.sin(np.sqrt(np.abs(x)))
fitness = 418.9829 * len(array) - sum
return fitness
def sphere(array):
fitness = 0
for i in range(len(array)):
fitness = fitness + array[i] ** 2
return fitness
def rastrigin(array):
sum = 0
fitness = 0
for x in array:
sum = sum + x ** 2 - 10 * np.cos(2 * np.pi * x)
fitness = 10.0 * len(array) + sum
return fitness
def eggholder(array):
z = -(array[1] + 47) * np.sin(np.sqrt(abs(array[1] + (array[0] / 2) + 47))) - array[
0
] * np.sin(np.sqrt(abs(array[0] - (array[1] + 47))))
return z
def matyas(array):
z = 0.26 * (array[0] ** 2 + array[1] ** 2) - (0.48 * array[0] * array[1])
return z
def levin13(array):
x = array[0]
y = array[1]
z = np.sin(3 * np.pi * x) ** 2 + (
(x - 1) ** 2 * (1 + np.sin(3 * np.pi * y) ** 2)
+ ((y - 1) ** 2 * (1 + np.sin(2 * np.pi * y) ** 2))
)
return z
def three_deceptive(array):
count = len([e for e in array if e == 1])
if count == 0:
return 0.9
if count == 1:
return 0.8
if count == 2:
return 0
return 1
def trap5(array):
count = len([e for e in array if e == 1])
if count < 5:
return 4 - count
return 5
def six_bipolar(array):
count = len([e for e in array if e == 1])
return three_deceptive(abs(3 - count))
def one_max(array):
return len([e for e in array if e == 1])