一、CEC2017简介
参考文献:
[1]Awad, N. H., Ali, M. Z., Liang, J. J., Qu, B. Y., & Suganthan, P. N. (2016). “Problem definitions and evaluation criteria for the CEC2017 special session and competition on single objective real-parameter numerical optimization,” Technical Report. Nanyang Technological University, Singapore.
二、灰狼优化算法GWO求解CEC2017
(1)部分Python代码
from GWO import GWO
import matplotlib.pyplot as plt
import numpy as np
import cec2017.functions as functions
#主程序
function_name =1 #测试函数 1-29
SearchAgents_no = 50#种群大小
Max_iter = 100#最大迭代次数
dim=30;#维度只能是 10/30/50/100
lb = -100*np.ones(dim)#下界
ub = 100*np.ones(dim)#上界
fobj= functions.all_functions[function_name-1]
BestX,BestF,curve = GWO(SearchAgents_no, Max_iter,lb,ub,dim,fobj)#问题求解
#画收敛曲线图
if BestF>0:
plt.semilogy(curve,color='k',linewidth=3,label='GWO')
else:
plt.plot(curve,color='k',linewidth=3,label='GWO')
plt.xlabel("Iteration")
plt.ylabel("Fitness")
plt.xlim(0,Max_iter)
plt.title("CEC2017-F"+str(function_name))
plt.legend()
plt.savefig(str(function_name)+'.png')
plt.show()
print('\nThe best solution is:\n'+str(BestX))
print('\nThe best optimal value of the objective funciton is:\n'+str(BestF))