首先声明,该算法是作者自己借鉴淘金优化器算法来改进的灰狼算法,并没有任何参考文献是这么做的,纯粹是作者自己的改进。
经常有小伙伴后台留言问:
作者改进的算法可不可以用来写论文呀?
回答是:当然可以!
如果我的文章能帮助到大家写论文,那是作者的荣幸!
至于为什么选择淘金优化器,上一期在介绍淘金优化器的时候,作者发现该算法很多公式与灰狼算法很像,但是效果却比灰狼算法好,于是今天借鉴淘金优化器的某些思想来改进一下灰狼算法。
原理详解
强调一下:此程序改进点并不复杂,适合新手。程序没有增加算法复杂度,每次循环只调用一次适应度函数。效率很高!
改进点有四处:
改进点1:混沌映射;
本次改进采用的是tent混沌映射。
改进点2:改进收敛因子;
改进点3:借鉴淘金优化算法中金矿探矿者向金矿的迁移公式,来更新灰狼算法的alpha狼。
改进点4,改进X2的更新公式
结果展示
GGWO是本文改进的算法,大家也可以自行起一个好听点的名字哈!
代码展示
clear
clc
close all
number='F10'; %选定优化函数,自行替换:F1~F23
[lower_bound,upper_bound,variables_no,fobj]=CEC2005(number); % [lb,ub,D,y]:下界、上界、维度、目标函数表达式
pop_size=50; % population members
max_iter=1000; % maximum number of iteration
%% GWO
[Best_score,Best_pos,GWO_cg_curve]=GWO(pop_size,max_iter,lower_bound,upper_bound,variables_no,fobj);
display(['The best optimal value of the objective funciton found by GWO for ' [num2str(number)],' is : ', num2str(Best_score)]);
fprintf ('Best solution obtained by GWO: %s\n', num2str(Best_pos,'%e '));
%% GGWO(改进的灰狼算法)
[Best_score,Best_pos,GGWO_cg_curve]=GGWO(pop_size,max_iter,lower_bound,upper_bound,variables_no,fobj);
display(['The best optimal value of the objective funciton found by GGWO for ' [num2str(number)],' is : ', num2str(Best_score)]);
fprintf ('Best solution obtained by GGWO: %s\n', num2str(Best_pos,'%e '));
%% Figure
figure1 = figure('Color',[1 1 1]);
G1=subplot(1,2,1,'Parent',figure1);
func_plot(number)
title(number)
xlabel('x')
ylabel('y')
zlabel('z')
subplot(1,2,2)
G2=subplot(1,2,2,'Parent',figure1);
CNT=50;
k=round(linspace(1,max_iter,CNT)); %随机选CNT个点
% 注意:如果收敛曲线画出来的点很少,随机点很稀疏,说明点取少了,这时应增加取点的数量,100、200、300等,逐渐增加
% 相反,如果收敛曲线上的随机点非常密集,说明点取多了,此时要减少取点数量
iter=1:1:max_iter;
if ~strcmp(number,'F16')&&~strcmp(number,'F9')&&~strcmp(number,'F11') %这里是因为这几个函数收敛太快,不适用于semilogy,直接plot
semilogy(iter(k),GWO_cg_curve(k),'m-*','linewidth',1);
hold on
semilogy(iter(k),GGWO_cg_curve(k),'k-o','linewidth',1);
else
plot(iter(k),GWO_cg_curve(k),'m-*','linewidth',1);
hold on
plot(iter(k),GGWO_cg_curve(k),'k-o','linewidth',1);
end
grid on;
title('收敛曲线')
xlabel('迭代次数');
ylabel('适应度值');
box on
legend('GWO','GGWO')
set (gcf,'position', [300,300,800,330])
完整代码获取方式,后台回复关键词。关键词:
GGWO