-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmarks.py
217 lines (191 loc) · 5 KB
/
benchmarks.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# -*- coding: utf-8 -*-
"""
Created on Tue May 17 12:46:20 2016
@author: Hossam Faris
"""
import numpy
import math
# define the function blocks
def prod(it):
p = 1
for n in it:
p *= n
return p
def Ufun(x, a, k, m):
y = k * ((x - a) ** m) * (x > a) + k * ((-x - a) ** m) * (x < (-a))
return y
#sphere
def F1(x):
s = numpy.sum(x ** 2)
return s
#schwefel`s 2.22
def F2(x):
o = sum(abs(x)) + prod(abs(x))
return o
#schwefel`s 1.2
def F3(x):
dim = len(x) + 1
o = 0
for i in range(1, dim):
o = o + (numpy.sum(x[0:i])) ** 2
return o
#schewefel`s 2.21
def F4(x):
o = max(abs(x))
return o
#Rosenbrock
def F5(x):
dim = len(x)
o = numpy.sum(
100 * (x[1:dim] - (x[0 : dim - 1] ** 2)) ** 2 + (x[0 : dim - 1] - 1) ** 2
)
return o
#step
def F6(x):
o = numpy.sum(abs((x + 0.5)) ** 2)
return o
#quartic
def F7(x):
dim = len(x)
w = [i for i in range(len(x))]
for i in range(0, dim):
w[i] = i + 1
o = numpy.sum(w * (x ** 4)) + numpy.random.uniform(0, 1)
return o
#powell sum
def F8(x):
dim = len(x)
for i in range(1,dim):
o = numpy.sum(abs(x) ** (i+1))
return o
def F9(x):
dim = len(x)
for i in range(0, dim):
o = numpy.sum(x**2) + (numpy.sum(0.5 * i * x)) ** 2 + (numpy.sum(0.5 * (i + 1) * x)) ** 4
return o
def getFunctionDetails(a):
# [name, lb, ub, dim]
param = {
"F1": ["F1", -100, 100, 30],
"F2": ["F2", -10, 10, 30],
"F3": ["F3", -100, 100, 30],
"F4": ["F4", -100, 100, 30],
"F5": ["F5", -30, 30, 30],
"F6": ["F6", -100, 100, 30],
"F7": ["F7", -1.28, 1.28, 30],
"F8": ["F8", -500, 500, 30],
"F9": ["F9", -5.12, 5.12, 30],
}
return param.get(a, "nothing")
def getFunctionSet(function_name):
# 假设您有一个将函数名映射到函数对象的字典
# 注意:这个字典需要您自己定义,因为Python不会自动为您创建它
# 这里的示例仅用于说明如何构造和使用这样的字典
function_objects = {
"F1": ["F1", -100, 100, 30],
"F2": ["F2", -10, 10, 30],
"F3": ["F3", -100, 100, 30],
"F4": ["F4", -100, 100, 30],
"F5": ["F5", -30, 30, 30],
"F6": ["F6", -100, 100, 30],
"F7": ["F7", -1.28, 1.28, 30],
"F8": ["F8", -500, 500, 30],
"F9": ["F9", -5.12, 5.12, 30],
}
# 检索函数对象
return function_objects.get(function_name, None)
'''
# ESAs space mission design benchmarks https://www.esa.int/gsp/ACT/projects/gtop/
from fcmaes.astro import (
MessFull,
Messenger,
Gtoc1,
Cassini1,
Cassini2,
Rosetta,
Tandem,
Sagas,
)
def Ca1(x):
return Cassini1().fun(x)
def Ca2(x):
return Cassini2().fun(x)
def Ros(x):
return Rosetta().fun(x)
def Tan(x):
return Tandem(5).fun(x)
def Sag(x):
return Sagas().fun(x)
def Mef(x):
return MessFull().fun(x)
def Mes(x):
return Messenger().fun(x)
def Gt1(x):
return Gtoc1().fun(x)
def getFunctionDetails(a):
# [name, lb, ub, dim]
param = {
"F1": ["F1", -100, 100, 30],
"F2": ["F2", -10, 10, 30],
"F3": ["F3", -100, 100, 30],
"F4": ["F4", -100, 100, 30],
"F5": ["F5", -30, 30, 30],
"F6": ["F6", -100, 100, 30],
"F7": ["F7", -1.28, 1.28, 30],
"F8": ["F8", -500, 500, 30],
"F9": ["F9", -5.12, 5.12, 30],
"F10": ["F10", -32, 32, 30],
"F11": ["F11", -600, 600, 30],
"F12": ["F12", -50, 50, 30],
"F13": ["F13", -50, 50, 30],
"F14": ["F14", -65.536, 65.536, 2],
"F15": ["F15", -5, 5, 4],
"F16": ["F16", -5, 5, 2],
"F17": ["F17", -5, 15, 2],
"F18": ["F18", -2, 2, 2],
"F19": ["F19", 0, 1, 3],
"F20": ["F20", 0, 1, 6],
"F21": ["F21", 0, 10, 4],
"F22": ["F22", 0, 10, 4],
"F23": ["F23", 0, 10, 4],
"Ca1": [
"Ca1",
Cassini1().bounds.lb,
Cassini1().bounds.ub,
len(Cassini1().bounds.lb),
],
"Ca2": [
"Ca2",
Cassini2().bounds.lb,
Cassini2().bounds.ub,
len(Cassini2().bounds.lb),
],
"Gt1": ["Gt1", Gtoc1().bounds.lb, Gtoc1().bounds.ub, len(Gtoc1().bounds.lb)],
"Mes": [
"Mes",
Messenger().bounds.lb,
Messenger().bounds.ub,
len(Messenger().bounds.lb),
],
"Mef": [
"Mef",
MessFull().bounds.lb,
MessFull().bounds.ub,
len(MessFull().bounds.lb),
],
"Sag": ["Sag", Sagas().bounds.lb, Sagas().bounds.ub, len(Sagas().bounds.lb)],
"Tan": [
"Tan",
Tandem(5).bounds.lb,
Tandem(5).bounds.ub,
len(Tandem(5).bounds.lb),
],
"Ros": [
"Ros",
Rosetta().bounds.lb,
Rosetta().bounds.ub,
len(Rosetta().bounds.lb),
],
}
return param.get(a, "nothing")
'''