当前位置: 灰狼 >> 灰狼的种类 >> 智能优化算法基于灰狼算法求解带约束的
Mirjalili等人提出了一种新的群体智能算法———灰狼优化算法(GWO),并通过多个基准测试函数进行测试,从结果上验证了该算法的可行性,通过对比,GWO算法已被证明在算法对函数求解精度和稳定性上要明显优于PSO、DE和GSA算法。
生物在自然界严酷环境下,即使并不具有人类的高智能,但在相同的目标,即食物的激励下,通过不断地适应与集体合作都表现出了令人惊叹的群体智能。文献[6]基于狼群严密的组织系统及其精妙的协作捕猎方式,提出了一种新的群体智能算法———灰狼优化算法。
2部分代码%GreyWolfOptimizer
function[Alpha_score,Alpha_pos,Convergence_curve]=GWO(SearchAgents_no,Max_iter,lb,ub,dim,fhandle,fnonlin)
%initializealpha,beta,anddelta_pos
Alpha_pos=zeros(1,dim);
Alpha_score=inf;%changethisto-infformaximizationproblems
Beta_pos=zeros(1,dim);
Beta_score=inf;%changethisto-infformaximizationproblems
Delta_pos=zeros(1,dim);
Delta_score=inf;%changethisto-infformaximizationproblems
%Initializethepositionsofsearchagents
Positions=initialization(SearchAgents_no,ub,lb);
Convergence_curve=zeros(1,Max_iter);
l=0;%Loopcounter
%Mainloop
whilelMax_iter
fori=1:size(Positions,1)
%Returnbackthesearchagentsthatgobeyondtheboundariesofthesearchspace
Flag4ub=Positions(i,:)ub;
Flag4lb=Positions(i,:)lb;
Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
%%Calculateobjectivefunctionforeachsearchagent
fitness=Fun(fhandle,fnonlin,Positions(i,:));
%%UpdateAlpha,Beta,andDelta
iffitnessAlpha_score
Alpha_score=fitness;%Updatealpha
Alpha_pos=Positions(i,:);
end
iffitnessAlpha_scorefitnessBeta_score
Beta_score=fitness;%Updatebeta
Beta_pos=Positions(i,:);
end
iffitnessAlpha_scorefitnessBeta_scorefitnessDelta_score
Delta_score=fitness;%Updatedelta
Delta_pos=Positions(i,:);
end
end
a=2-l*((2)/Max_iter);%adecreaseslinearlyfron2to0
%UpdatethePositionofsearchagentsincludingomegas
fori=1:size(Positions,1)
forj=1:size(Positions,2)
r1=rand();%r1isarandomnumberin[0,1]
r2=rand();%r2isarandomnumberin[0,1]
A1=2*a*r1-a;%Equation(3.3)
C1=2*r2;%Equation(3.4)
D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j));%Equation(3.5)-part1
X1=Alpha_pos(j)-A1*D_alpha;%Equation(3.6)-part1
r1=rand();
r2=rand();
A2=2*a*r1-a;%Equation(3.3)
C2=2*r2;%Equation(3.4)
D_beta=abs(C2*Beta_pos(j)-Positions(i,j));%Equation(3.5)-part2
X2=Beta_pos(j)-A2*D_beta;%Equation(3.6)-part2
r1=rand();
r2=rand();
A3=2*a*r1-a;%Equation(3.3)
C3=2*r2;%Equation(3.4)
D_delta=abs(C3*Delta_pos(j)-Positions(i,j));%Equation(3.5)-part3
X3=Delta_pos(j)-A3*D_delta;%Equation(3.5)-part3
Positions(i,j)=(X1+X2+X3)/3;%Equation(3.7)
end
end
l=l+1;
Convergence_curve(l)=Alpha_score;
end
3仿真结果4参考文献[1]龙文l,赵东泉,徐松金.求解约束优化问是一页的改L井灰狼优化算法.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。部分理论引用网络文献,若有侵权联系博主删除。
天天Matlab