单峰测试函数
Sphere Function
$$ f_1(x)=\sum_{i=1}^{30}x_i^2\\ -100\leq x_i\leq100, \quad \min(f_1)=f_1(0,\ldots,0)=0 $$
def fun1(x):
y = np.sum(x * x)
return y
Schwefel’s Problem 2.22
$$ f_2(x)=\sum_{i=1}^{30}|x_i|+\prod_{i=1}^{30}|x_i|\\ -10\leq x_i\leq10,\quad \min(f_2)=f_2(0,\ldots,0)=0 $$
def fun2(x):
y = np.sum(np.abs(x)) + np.prod(np.abs(x))
return y
Schwefel’s Problem 1.2
$$ f_3(x)=\sum_{i=1}^{30}\left(\sum_{j=1}^ix_j\right)^2\\ -100\leq x_i\leq100,\quad\min(f_3)=f_3(0,\ldots,0)=0 $$
def fun3(x):
y = 0
for i in range(len(x)):
y = O + np.square(np.sum(x[0:i + 1]))
return y
Schwefel’s Problem 2.21
$$ f_4(x)=\max_i(|x_i|,1\leq i\leq30)\\ -100\leq x_i\leq100,\quad \min(f_4)=f_4(0,\ldots,0)=0 $$
def fun4(x):
y = np.max(np.abs(x))
return y
Generalized Rosenbrock’s Function
$$ f_5(x)=\sum_{i=1}^{29}\big[100\big(x_{i+1}-x_{i}^2\big)^2+(x_{i}-1)^2\big]\\ -30\leq x_{i}\leq30,\quad\min(f_5)=f_5(1,\ldots,1)=0 $$
def fun5(x):
x_len = len(x)
y = np.sum(100 * np.square(x[1:x_len] - np.square(x[0:x_len - 1]))) + np.sum(np.square(x[0:x_len - 1] - 1))
return y
Step Function
$$ f_6(x)=\sum_{i=1}^{30}(\lfloor x_{i}+0.5\rfloor)^2\\ -100\leq x_{i}\leq100,\quad\min(f_6)=f_6(0,\ldots,0)=0 $$
def fun6(x):
y = np.sum(np.square(np.abs(x + 0.5)))
return y
Quartic Function i.e. Noise
$$ f_7(x)=\sum_{i=1}^{30}ix_{i}^4+random[0,1)\\ -1.28\leq x_{i}\leq 1.28,\quad\min(f_7)=f_7(0,\ldots,0)=0 $$
def fun7(x):
i = np.arange(1, len(x) + 1)
y = np.sum(i * (x ** 4)) + np.random.random()
return y
多峰测试函数
Generalized Schwefel’s Problem 2.26
$$ f_{8}(x)=-\sum_{i=1}^{30}\left(x_{i}\sin(\sqrt{|x_{i}|})\right)\\ 500\leq x_{i}\leq500,\quad\min(f_8)=f_8(420.9687,\ldots,420.9687)=-12569.5 $$
def fun8(x):
y = np.sum(-x * np.sin(np.sqrt(np.abs(x))))
return y
Generalized Rastrigin’s Function
$$ f_9(x)=\sum_{i=1}^{30}\big[x_{i}^2-10\cos(2\pi x_{i})+10)\big]\\ 5.12\leq x_{i}\leq5.12,\quad \min(f_9)=f_9(0,\ldots,0)=0 $$
def fun9(x):
dim = len(x)
y = np.sum(x ** 2 - 10 * np.cos(2 * np.pi * x)) + 10 * dim
return y
Ackley’s Function
$$ f_{10}(x)=-20\exp\left(-0.2\sqrt{\frac{1}{30}\sum_{i=1}^{30}x_{i}^{2}}\right)-\exp\left(\frac{1}{30}\sum_{i=1}^{30}\cos2\pi x_{i}\right)+20+c\\ -32\leq x_{i}\leq32,\quad\operatorname*{min}(f_{10})=f_{10}(0,\ldots,0)=0. $$
def fun10(x):
dim = len(x)
a, b, c = 20, 0.2, 2 * np.pi
sum_1 = -a * np.exp(-b * np.sqrt(np.sum(x ** 2) / dim))
sum_2 = np.exp(np.sum(np.cos(c * x)) / dim)
y = sum_1 - sum_2 + a + np.exp(1)
return y
Generalized Griewank’s Function
$$ f_{11}(x)=\frac{1}{4000}\sum_{i=1}^{30}x_{i}^{2}-\prod_{i=1}^{30}\cos\biggl(\frac{x_{i}}{\sqrt{i}}\biggr)+1,\\ -600\leq x_{i}\leq600,\quad\min(f_{11})=f_{11}(0,\ldots,0)=0 $$
def fun11(x):
dim = len(x)
i = np.arange(1, dim + 1)
y = np.sum(x ** 2) / 4000 - np.prod(np.cos(x / np.sqrt(i))) + 1
return y
Generalized Penalized Function 1
$$ f_{12}(x)=\frac{\pi}{30}\left(10\sin^2(\pi y_1)+\sum_{i=1}^{29}(y_{i}-1)^2\cdot[1+10\sin^2(\pi y_{i+1})]+(y_{n}-1)^2\right)+\sum_{i=1}^{30}u(x_{i},10,100,4)\\ -50\leq x_{i}\leq50,\quad\min(f_{12})=f_{12}(1,\ldots,1)=0 $$
def Ufun(x, a, k, m):
dim = len(x)
U = np.zeros(dim)
for i in range(len(x)):
if x[i] > a:
U[i] = k * ((x[i] - a) ** m)
elif x[i] < -a:
U[i] = k * ((-x[i] - a) ** m)
else:
U[i] = y
return U
def fun12(x):
dim = len(x)
pi = np.pi
sum_1 = (np.pi / dim) * (10 * ((np.sin(pi * (1 + (x[0] + 1) / 4))) ** 2)
+ np.sum((((x[:dim - 2] + 1) / 4) ** 2) *
(1 + 10 * ((np.sin(pi * (1 + (x[1:dim - 1] + 1) / 4)))) ** 2))
+ ((x[dim - 1]) / 4) ** 2)
sum_2 = np.sum(Ufun(x, 10, 100, 4))
y = sum_1 + sum_2
return y
Generalized Penalized Function 2
$$ f_{13}(x)=0.1\left(\sin^{2}(\pi3x_{1})+\sum_{i=1}^{29}(x_{i}-1)^{2}[1+\sin^{2}\\ \cdot(3\pi x_{i+1})]+(x_{n}-1)^{2}[1+\sin^{2}(2\pi x_{30})\right)\\ +\sum_{i=1}^{30}u(x_{i},5,100,4),\quad-50\leq x_{i}\leq50,\quad\min(f_{13})=f_{13}(1,\ldots,1)=0\\ \text{where} \quad u(x_i,a,k,m)=\begin{cases}k(x_i-a)^m,&x_i>a,\\ 0,&-a\leq x_i\leq a,\\ k(-x_i-a)^m,&x_i<-a.\end{cases}\\ y_i=1+\frac{1}{4}(x_i+1) $$
def fun13(x):
dim = len(x)
pi = np.pi
y = 0.1 * ((np.sin(3 * pi * x[0])) ** 2 + np.sum(((x[0:dim - 2]) - 1) ** 2 * (1 + (np.sin(3 * pi * x[1:dim - 1])) ** 2)))+((x[dim - 1] - 1) ** 2) * (1 + (np.sin(2 * pi * x[dim - 1])) ** 2) + np.sum(Ufun(x, 5, 100, 4))
return y
固定多峰测试函数
Shekel’s Foxholes Function
$$ f_{14}(x)=\left[\frac{1}{500}+\sum_{j=1}^{25}\frac{1}{j+\sum_{i=1}^{2}(x_{i}-a_{ij})^{6}}\right]^{-1}\\ -65.536\leq x_{i}\leq65.536,\quad \min(f_{14})=f_{14}(-32,-32)\approx1\\ \text{where}\quad (a_{ij})=\begin{pmatrix} -32&-16&0&16&32&-32&\cdots&0&16&32\\ -32&-32&-32&-32&-32&-16&\cdots&32&-32&-32 \end{pmatrix} $$
def fun14(x):
aS = np.array(
[[-32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32],
[-32, -32, -32, -32, -32, -16, -16, -16, -16, -16, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32]])
bS = np.zeros(25)
for j in range(0, 25):
bS[j] = np.sum((x.T - aS[:, j]) ** 6)
y = (1 / 500 + np.sum(1 / (np.arange(1, 25 + 1) + bS))) ** (-1)
return y
Kowalik’s Function
$$ f_{15}(x)=\sum_{i=1}^{11}\left[a_{i}-\frac{x_{1}\big(b_{i}^{2}+b_{i}x_{2}\big)}{b_{i}^{2}+b_{i}x_{3}+x_{4}}\right]^{2}\\ -5\leq x_{i}\leq5,\quad \operatorname*{min}(f_{15})\approx f_{15}(0.1928,0.1908,0.1231,0.1358)\approx0.0003075\\ \text{where}\quad \begin{array}{c|c|c}\hline\text{i}&a_i&b_i^{-1}\\ \hline1&0.1957&0.25\\ 2&0.1947&0.5\\ 3&0.1735&1\\ 4&0.1600&2\\ 5&0.0844&4\\ 6&0.0627&6\\ 7&0.0456&8\\ 8&0.0342&10\\ 9&0.0323&12\\ 10&0.0235&14\\ 11&0.0246&16\\ \hline\end{array} $$
def fun15(x):
aK = np.array([0.1957, 0.1947, 0.1735, 0.16, 0.0844, 0.0627, 0.0456, 0.0342, 0.0323, 0.0235, 0.0246])
bK = np.array([0.25, 0.5, 1, 2, 4, 6, 8, 10, 12, 14, 16])
bK = 1 / bK
y = np.sum((aK - ((x[0] * (bK ** 2 + x[1] * bK)) / (bK ** 2 + x[2] * bK + x[3]))) ** 2)
return y
Six-Hump Camel-Back Function
$$ f_{16}=4x_1^2-2.1x_1^4+\frac{1}{3}x_1^6+x_1x_2-4x_2^2+4x_2^4\\ x_{\mathrm{min}} =(0.08983,-0.7126),(-0.08983,0.7126),\\ \quad- 5\leq x_{i}\leq5,\quad\min(f_{16})=-1.0316285 $$
def fun16(x):
y = 4 * (x[0] ** 2) - 2.1 * (x[0] ** 4) + (x[0] ** 6) / 3 + x[0] * x[1] - 4 * (x[1] ** 2) + 4 * (x[1] ** 4)
return y
Branin Function
$$ f_{17}(x)=\left(x_2-\frac{5.1}{4\pi^{2}}x_1^2+\frac{5}{\pi}x_1-6\right)^2+10\biggl(1-\frac{1}{8\pi}\biggr)\cos x_1+10\\ x_{\mathrm{min}}=(-3.14212.275),(3.142,2.275),(9.425,2.425),\\ -5\leq x_{1}\leq10,\quad0\leq x_{2}\leq15,\quad\min(f_{17})=0.398.\\ $$
def fun17(x):
pi = np.pi
y = ((x[1]) - (x[0] ** 2) * 5.1 / (4 * (pi ** 2)) + 5 / pi * x[0] - 6) ** 2 + 10 * (1 - 1 / (8 * pi)) * np.cos(x[0]) + 10
return y
Goldstein-Price Function
$$ f_{18}(x) =\bigl[1+(x_1+x_2+1)^2\bigl(19-14x_1+3x_1^2-14x_2\bigr]+6x_1x_2+3x_2^2)]\ \times\left[30+(2x_1-3x_2)^2\right] \times\left(18-32x_1+12x_1^2+48x_2-36x_1x_2+27x_2^2\right)]\\ -2\leq x_{i}\leq2,\quad\min(f_{18})=f_{18}(0,-1)=3 $$
def fun18(x):
y = (1 + ((x[0] + x[1] + 1) ** 2) * (19 - 14 * x[0] + 3 * (x[0] ** 2) - 14 * x[1] + 6 * x[0] * x[1] + 3 * (x[1] ** 2))) * (30 + (2 * x[0] - 3 * x[1]) ** 2 * (18 - 32 * x[0] + 12 * (x[0] ** 2) + 48 * x[1] - 36 * x[0] * x[1] + 27 * (x[1] ** 2)))
return y
Hartman’s Family
$$ f(x)=-\sum_{i=1}^4c_i\exp\left[-\sum_{j=1}^na_{ij}(x_j-p_{ij})^2\right]\\ 0\leq x_{i}\leq1,\quad\min(f_{19})=f(0.114,0.556,0.852)=-3.86\\ \min(f_{20})=f(0.201,0.150,0.477,0.275,0.311,0.657)=-3.32\\ \text{where}\quad \begin{array}{c|c|c|c} \hline \text{i}&a_{ij},j=1,2,3&c_i&p_{ij},j=1,2,3\\ \hline 1&3\quad10\quad30&1&0.3689\quad0.1170\quad0.2673\\ 2&0.1\quad10\quad35&1.2&0.4699\quad0.4387\quad0.7470\\ 3&3\quad10\quad30&3&0.1091\quad0.8732\quad0.5547\\ 4&0.1\quad10\quad35&3.2&0.038150\quad0.5743\quad0.8828\\ \hline \end{array} $$
def fun19(x):
aH = np.array([[3, 10, 30], [0.1, 10, 35], [3, 10, 30], [0.1, 10, 35]])
cH = np.array([1, 1.2, 3, 3.2])
pH = np.array([[0.3689, 0.117, 0.2673], [0.4699, 0.4387, 0.747], [0.1091, 0.8732, 0.5547], [0.03815, 0.5743, 0.8828]])
y = 0
for i in range(0, 4):
y = y - cH[i] * np.exp(-(np.sum(aH[i] * ((x - pH[i]) ** 2))))
return y
def fun20(x):
aH = np.array([[10, 3, 17, 3.5, 1.7, 8], [0.05, 10, 17, 0.1, 8, 14], [3, 3.5, 1.7, 10, 17, 8],[17, 8, 0.05, 10, 0.1, 14]])
cH = np.array([1, 1.2, 3, 3.2])
pH = np.array(
[[0.1312, 0.1696, 0.5569, 0.0124, 0.8283, 0.5886], [0.2329, 0.413, 0.8307, 0.3736, 0.1004, 0.9991],[0.2348, 0.1415, 0.3522, 0.2883, 0.3047, 0.6650], [0.4047, 0.8828, 0.8732, 0.5743, 0.1091, 0.0381]])
y = 0
for i in range(0, 4):
y = y - cH[i] * np.exp(-(np.sum(aH[i] * ((x - pH[i]) ** 2))))
return y
Shekel’s Family
$$ f(x)=-\sum_{i=1}^m[(x-a_i)(x-a_i)^T+c_i]^{-1}\\ 0\leq x_{i}\leq10,\quad\min(f_{21,22,23})=-10\\ \text{where}\quad \begin{array} {c|c|c} \hline \text{i}&a_{ij},j=1,\cdots,4&c_i\\ \hline1&4\quad4\quad4\quad4&0.1\\ 2&1\quad1\quad1\quad1&0.2\\ 3&8\quad8\quad8\quad8&0.2\\ 4&6\quad6\quad6\quad6&0.4\\ 5&3\quad7\quad3\quad7&0.4\\ \hline 6&2\quad9\quad2\quad9&0.6\\ 7&5\quad5\quad3\quad3&0.3\\ \hline 8&8\quad1\quad8\quad1&0.7\\ 9&6\quad2\quad6\quad2&0.5\\ 10&7\quad3.6\quad7\quad3.6&0.5\\ \hline \end{array} $$
def fun21(x):
aSH = np.array([[4, 4, 4, 4], [1, 1, 1, 1], [8, 8, 8, 8], [6, 6, 6, 6], [3, 7, 3, 7],
[2, 9, 2, 9], [5, 5, 3, 3], [8, 1, 8, 1], [6, 2, 6, 2], [7, 3.6, 7, 3.6]])
cSH = np.array([[0.1], [0.2], [0.2], [0.4], [0.4],
[0.6], [0.3], [0.7], [0.5], [0.5]])
y = 0
for i in range(0, 5):
y = y - (np.sum((x - aSH[i]) ** 2) + cSH[i]) ** (-1)
return y
def fun22(x):
aSH = np.array([[4, 4, 4, 4], [1, 1, 1, 1], [8, 8, 8, 8], [6, 6, 6, 6], [3, 7, 3, 7],[2, 9, 2, 9], [5, 5, 3, 3], [8, 1, 8, 1], [6, 2, 6, 2], [7, 3.6, 7, 3.6]])
cSH = np.array([[0.1], [0.2], [0.2], [0.4], [0.4],[0.6], [0.3], [0.7], [0.5], [0.5]])
y = 0
for i in range(0, 7):
y = y - (np.sum((x - aSH[i]) ** 2) + cSH[i]) ** (-1)
return y
def fun23(x):
aSH = np.array([[4, 4, 4, 4], [1, 1, 1, 1], [8, 8, 8, 8], [6, 6, 6, 6], [3, 7, 3, 7],[2, 9, 2, 9], [5, 5, 3, 3], [8, 1, 8, 1], [6, 2, 6, 2], [7, 3.6, 7, 3.6]])
cSH = np.array([[0.1], [0.2], [0.2], [0.4], [0.4],[0.6], [0.3], [0.7], [0.5], [0.5]])
y = 0
for i in range(0, 10):
y = y - (np.sum((x - aSH[i]) ** 2) + cSH[i]) ** (-1)
return y
函数参数
函数 | 函数名 | 搜索范围 | 维数 | 理论最优值 |
---|---|---|---|---|
F1 | Sphere Function | [-100, 100] | 30 | 0 |
F2 | Schwefel’s Problem 2.22 | [-10, 10] | 30 | 0 |
F3 | Schwefel’s Problem 1.2 | [-100, 100] | 30 | 0 |
F4 | Schwefel’s Problem 2.21 | [-100, 100] | 30 | 0 |
F5 | Generalized Rosenbrock’s Function | [-30, 30] | 30 | 0 |
F6 | Step Function | [-100, 100] | 30 | 0 |
F7 | Quartic Function i.e. Noise | [-1.28, 1.28] | 30 | 0 |
F8 | Generalized Schwefel’s Problem 2.26 | [-500, 500] | 30 | -12569.5 |
F9 | Generalized Rastrigin’s Function | [-5.12, 5.12] | 30 | 0 |
F10 | Ackley’s Function | [-32, 32] | 30 | 0 |
F11 | Generalized Griewank’s Function | [-600, 600] | 30 | 0 |
F12 | Generalized Penalized Function 1 | [-50, 50] | 30 | 0 |
F13 | Generalized Penalized Function 2 | [-50, 50] | 30 | 0 |
F14 | Shekel’s Foxholes Function | [-65.536, 65.536] | 2 | 0.99800383 |
F15 | Kowalik’s Function | [-5, 5] | 4 | 0.0003075 |
F16 | Six-Hump Camel-Back Function | [-5, 5] | 2 | -1.03162845 |
F17 | Branin Function | [-5, 10] * [0, 15] | 2 | 0.39788735 |
F18 | Goldstein-Price Function | [-2, 2] | 2 | 2.99999999 |
F19 | Hartman’s Family | [0, 1] | 3 | -3.86278214 |
F20 | Hartman’s Family | [0, 1] | 6 | -3.32199517 |
F21 | Shekel’s Family | [0, 10] | 4 | -10 |
F22 | Shekel’s Family | [0, 10] | 4 | -10 |
F23 | Shekel’s Family | [0, 10] | 4 | -10 |