白鲨智能优化算法(White Shark Optimizer,WSO)是期刊“KNOWLEDGE-BASED SYSTEMS”(中科院一区期刊 IF=8.6)的2022年智能优化算法
01.引言
白鲨智能优化算法(White Shark Optimizer,WSO)的核心理念和基础灵感来自大白鲨的行为,包括它们在导航和觅食时非凡的听觉和嗅觉。行为的这些方面被数学建模,以适应对WSO的探索和利用之间的充分平衡,并协助搜索代理探索和利用搜索空间的每个潜在区域,以实现优化。WSO的搜索代理会根据目前最佳的解决方案随机更新自己的位置,最终得到最优的结果。在CEC-2017测试套件的29个测试功能的基础上,对WSO的性能进行了多个维度的综合基准测试。进一步将WSO应用于CEC-2011进化算法竞赛的基准问题,证明其可靠性和对现实问题的适用性。对计算结果和收敛结果进行了全面分析,以阐明WSO的有效性和稳定性水平。基于生成的解,将WSO在几种统计方法下的性能得分与9种成熟的元启发式方法进行比较。Friedman和Holm对结果的测试表明,与其他现有的元启发式方法相比,WSO在全局最优性、避免局部最小值和解决方案质量方面揭示了合理的解决方案。
02.优化算法的流程
03.论文中算法对比图
04.部分代码
function [fmin0,gbest,ccurve]=WSO(whiteSharks,itemax,lb,ub,dim,fobj)
%% Convergence curve
ccurve=zeros(1,itemax);
%% Show the convergence curve
% figure (1);
% set(gcf,'color','w');
% hold on
% xlabel('Iteration','interpreter','latex','FontName','Times','fontsize',10)
% ylabel('fitness value','interpreter','latex','FontName','Times','fontsize',10);
% grid;
%% Start the WSO Algorithm
% Generation of initial solutions
WSO_Positions=initialization(whiteSharks,dim,ub,lb);% Initial population
% initial velocity
v=0.0*WSO_Positions;
%% Evaluate the fitness of the initial population
fit=zeros(whiteSharks,1);
for i=1:whiteSharks
fit(i,1)=fobj(WSO_Positions(i,:));
end
%% Initalize the parameters of WSO
fitness=fit; % Initial fitness of the random positions of the WSO
[fmin0,index]=min(fit);
wbest = WSO_Positions; % Best position initialization
gbest = WSO_Positions(index,:); % initial global position
%% WSO Parameters
fmax=0.75; % Maximum frequency of the wavy motion
fmin=0.07; % Minimum frequency of the wavy motion
tau=4.11;
mu=2/abs(2-tau-sqrt(tau^2-4*tau));
pmin=0.5;
pmax=1.5;
a0=6.250;
a1=100;
a2=0.0005;
%% Start the iterative process of WSO
for ite=1:itemax
mv=1/(a0+exp((itemax/2.0-ite)/a1));
s_s=abs((1-exp(-a2*ite/itemax))) ;
p1=pmax+(pmax-pmin)*exp(-(4*ite/itemax)^2);
p2=pmin+(pmax-pmin)*exp(-(4*ite/itemax)^2);
%% Update the speed of the white sharks in water
nu=floor((whiteSharks).*rand(1,whiteSharks))+1;
for i=1:size(WSO_Positions,1)
rmin=1; rmax=3.0;
rr=rmin+rand()*(rmax-rmin);
wr=abs(((2*rand()) - (1*rand()+rand()))/rr);
v(i,:)= mu*v(i,:) + wr *(wbest(nu(i),:)-WSO_Positions(i,:));
%% or
% v(i,:)= mu*(v(i,:)+ p1*(gbest-WSO_Positions(i,:))*rand+....
% + p2*(wbest(nu(i),:)-WSO_Positions(i,:))*rand);
end
%% Update the white shark position
for i=1:size(WSO_Positions,1)
f =fmin+(fmax-fmin)/(fmax+fmin);
a=sign(WSO_Positions(i,:)-ub)>0;
b=sign(WSO_Positions(i,:)-lb)<0;
wo=xor(a,b);
% locate the prey based on its sensing (sound, waves)
if rand<mv
WSO_Positions(i,:)= WSO_Positions(i,:).*(~wo) + (ub.*a+lb.*b); % random allocation
else
WSO_Positions(i,:) = WSO_Positions(i,:)+ v(i,:)/f; % based on the wavy motion
end
end
%% Update the position of white sharks consides_sng fishing school
for i=1:size(WSO_Positions,1)
for j=1:size(WSO_Positions,2)
if rand<s_s
Dist=abs(rand*(gbest(j)-1*WSO_Positions(i,j)));
if(i==1)
WSO_Positions(i,j)=gbest(j)+rand*Dist*sign(rand-0.5);
else
WSO_Pos(i,j)= gbest(j)+rand*Dist*sign(rand-0.5);
WSO_Positions(i,j)=(WSO_Pos(i,j)+WSO_Positions(i-1,j))/2*rand;
end
end
end
end
%
%% Update global, best and new positions
for i=1:whiteSharks
% Handling boundary violations
if WSO_Positions(i,:)>=lb & WSO_Positions(i,:)<=ub%
% Find the fitness
fit(i)=fobj(WSO_Positions(i,:));
% Evaluate the fitness
if fit(i)<fitness(i)
wbest(i,:) = WSO_Positions(i,:); % Update the best positions
fitness(i)=fit(i); % Update the fitness
end
%% Finding out the best positions
if (fitness(i)<fmin0)
fmin0=fitness(i);
gbest = wbest(index,:); % Update the global best positions
end
end
end
%% Obtain the results
% outmsg = ['Iteration# ', num2str(ite) , ' Fitness= ' , num2str(fmin0)];
% disp(outmsg);
ccurve(ite)=fmin0; % Best found value until iteration ite
% if ite>2
% line([ite-1 ite], [ccurve(ite-1) ccurve(ite)],'Color','b');
% title({'Convergence characteristic curve'},'interpreter','latex','FontName','Times','fontsize',12);
% xlabel('Iteration');
% ylabel('Best score obtained so far');
% drawnow
% end
end
end
04.本代码效果图
获取代码请关注MATLAB科研小白的个人公众号(即文章下方二维码),并回复智能优化算法本公众号致力于解决找代码难,写代码怵。各位有什么急需的代码,欢迎后台留言~不定时更新科研技巧类推文,可以一起探讨科研,写作,文献,代码等诸多学术问题,我们一起进步。