一、麻雀搜索算法SSA求解cec2013
cec2013函数简介
CEC 2013 Special Session on Real-Parameter Optimization中共有28个测试函数维度可选择为10/30/50/100。
每个测试函数的详细信息如下表所示:
参考文献:[1] Liang J J , Qu B Y , Suganthan P N , et al. Problem Definitions and Evaluation Criteria for the CEC 2013 Special Session on Real-Parameter Optimization. 2013.
部分代码
from CEC2013.cec2013 import * from SSA import SSA import matplotlib.pyplot as plt import numpy as np #主程序 function_name =18 #测试函数1-28 SearchAgents_no = 50#种群大小 Max_iter = 100#迭代次数 dim=10#维度 10/30/50/100 lb=-100*np.ones(dim)#下限 ub=100*np.ones(dim)#上限 cec_functions = cec2013(dim,function_name) fobj=cec_functions.func#目标函数 BestX,BestF,curve = SSA(SearchAgents_no, Max_iter,lb,ub,dim,fobj)#问题求解 #画收敛曲线图 if BestF>0: plt.semilogy(curve,color='r',linewidth=2,label='SSA') else: plt.plot(curve,color='r',linewidth=2,label='SSA') plt.xlabel("Iteration") plt.ylabel("Fitness") plt.xlim(0,Max_iter) plt.title("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))
部分结果