100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 【优化求解】基于灰狼算法求解多目标问题matlab代码

【优化求解】基于灰狼算法求解多目标问题matlab代码

时间:2021-09-22 21:06:16

相关推荐

【优化求解】基于灰狼算法求解多目标问题matlab代码

1 简介

灰狼群体具有严格的社会支配等级且其等级划分呈金字塔形式,在捕捉猎物时,灰狼是通过相交流共享的体制来模拟的。其他智能算法类似的是,每一个可能解都由每头灰狼的位置来对应。种群的发展需要不断地更新,为了选出 3 只头狼,种群内的狼将被逐一进行评价,在这个过程中,算法起到评价的作用。接下来前进的方向将由这 3只头狼的位置所决定。由于灰狼算法参数较少,收敛较快,所以广泛应用于众多领域,尤其是实际工程领域应用最广。在该算法中,狼群通过竞选选出α 狼作为头狼,就意味着 α 狼将处于金字塔顶端的位置,同时 α 狼群做的所有决定都将代表整个狼群,但这并非表示狼群是全部专制的,在某种程度上也有一定的民主,比如狼群中有时也会存在其他的狼。当有任务需要执行时,α 狼将发号施令,其余狼群只需配合执行即可,因此 α 狼也就当之无愧的成为了狼群中最主要的狼。当狼群需要交配时,只能选择在自己的群体中进行交配。值得一提的是,α 狼之所以成为最主要的狼,其原因并不在于 α狼是最强的,而在于它拥有其他狼所不具备的优越的组织管理的能力。在狼群中 β 狼的地位近乎于 α 狼,这一点可以从狼群执行的其他群体活动中看出,β 狼是第二决策者。 β 狼在活动中都需要听从α 狼的指挥,同时其他更低级别的狼群也要听从它的指挥。在灰狼群体中,位于第三等级是 δ 狼,在严格的等级制度中,δ 狼必须遵从 α 狼和 β 狼的命令,δ 狼不是最低一级,在它的下一级还存在着 ω 狼,ω 狼在整个群体中担任侦查和围捕猎物的责任,也是灰狼群体中等级最低的。虽然它们看起来无足轻重,但一旦失去它们这一群体,整个灰狼种群都将面临着基层缺失的危险,所以也可以看出它们是狼群的重要组成部分。

2 部分代码

%___________________________________________________________________%% Multi-Objective Grey Wolf Optimizer (MOGWO) %% Source codes demo version 1.0 %%clearallclcdrawing_flag=1;TestProblem='UF2';nVar=10;fobj=cec09(TestProblem);xrange=xboundary(TestProblem,nVar);% Lower bound and upper boundlb=xrange(:,1)';ub=xrange(:,2)';VarSize=[1nVar];GreyWolves_num=100;MaxIt=1000; % Maximum Number of IterationsArchive_size=100; % Repository Sizealpha=0.1; % Grid Inflation ParameternGrid=10; % Number of Grids per each Dimensionbeta=4;%=4; % Leader Selection Pressure Parametergamma=2; % Extra (to be deleted) Repository Member Selection Pressure% InitializationGreyWolves=CreateEmptyParticle(GreyWolves_num);fori=1:GreyWolves_numGreyWolves(i).Velocity=0;GreyWolves(i).Position=zeros(1,nVar);forj=1:nVarGreyWolves(i).Position(1,j)=unifrnd(lb(j),ub(j),1);endGreyWolves(i).Cost=fobj(GreyWolves(i).Position')';GreyWolves(i).Best.Position=GreyWolves(i).Position;GreyWolves(i).Best.Cost=GreyWolves(i).Cost;endGreyWolves=DetermineDomination(GreyWolves);Archive=GetNonDominatedParticles(GreyWolves);Archive_costs=GetCosts(Archive);G=CreateHypercubes(Archive_costs,nGrid,alpha);fori=1:numel(Archive)[Archive(i).GridIndexArchive(i).GridSubIndex]=GetGridIndex(Archive(i),G);end% MOGWO main loopforit=1:MaxIta=2-it*((2)/MaxIt);fori=1:GreyWolves_numclearrep2clearrep3% Choose the alpha, beta, and delta grey wolvesDelta=SelectLeader(Archive,beta);Beta=SelectLeader(Archive,beta);Alpha=SelectLeader(Archive,beta);% If there are less than three solutions in the least crowded% hypercube, the second least crowded hypercube is also found% to choose other leaders from.ifsize(Archive,1)>1counter=0;fornewi=1:size(Archive,1)ifsum(Delta.Position~=Archive(newi).Position)~=0counter=counter+1;rep2(counter,1)=Archive(newi);endendBeta=SelectLeader(rep2,beta);end% This scenario is the same if the second least crowded hypercube% has one solution, so the delta leader should be chosen from the% third least crowded hypercube.ifsize(Archive,1)>2counter=0;fornewi=1:size(rep2,1)ifsum(Beta.Position~=rep2(newi).Position)~=0counter=counter+1;rep3(counter,1)=rep2(newi);endendAlpha=SelectLeader(rep3,beta);end% Eq.(3.4) in the paperc=2.*rand(1,nVar);% Eq.(3.1) in the paperD=abs(c.*Delta.Position-GreyWolves(i).Position);% Eq.(3.3) in the paperA=2.*a.*rand(1,nVar)-a;% Eq.(3.8) in the paperX1=Delta.Position-A.*abs(D);% Eq.(3.4) in the paperc=2.*rand(1,nVar);% Eq.(3.1) in the paperD=abs(c.*Beta.Position-GreyWolves(i).Position);% Eq.(3.3) in the paperA=2.*a.*rand()-a;% Eq.(3.9) in the paperX2=Beta.Position-A.*abs(D);% Eq.(3.4) in the paperc=2.*rand(1,nVar);% Eq.(3.1) in the paperD=abs(c.*Alpha.Position-GreyWolves(i).Position);% Eq.(3.3) in the paperA=2.*a.*rand()-a;% Eq.(3.10) in the paperX3=Alpha.Position-A.*abs(D);% Eq.(3.11) in the paperGreyWolves(i).Position=(X1+X2+X3)./3;% Boundary checkingGreyWolves(i).Position=min(max(GreyWolves(i).Position,lb),ub);GreyWolves(i).Cost=fobj(GreyWolves(i).Position')';endGreyWolves=DetermineDomination(GreyWolves);non_dominated_wolves=GetNonDominatedParticles(GreyWolves);Archive=[Archivenon_dominated_wolves];Archive=DetermineDomination(Archive);Archive=GetNonDominatedParticles(Archive);fori=1:numel(Archive)[Archive(i).GridIndexArchive(i).GridSubIndex]=GetGridIndex(Archive(i),G);endifnumel(Archive)>Archive_sizeEXTRA=numel(Archive)-Archive_size;Archive=DeleteFromRep(Archive,EXTRA,gamma);Archive_costs=GetCosts(Archive);G=CreateHypercubes(Archive_costs,nGrid,alpha);enddisp(['In iteration 'num2str(it)': Number of solutions in the archive = 'num2str(numel(Archive))]);saveresults% Resultscosts=GetCosts(GreyWolves);Archive_costs=GetCosts(Archive);ifdrawing_flag==1holdoffplot(costs(1,:),costs(2,:),'k.');holdonplot(Archive_costs(1,:),Archive_costs(2,:),'rd');legend('Grey wolves','Non-dominated solutions');drawnowendend

3 仿真结果

4 参考文献

[1]孟安波, and 林艺城. "一种基于多目标的改进灰狼优化算法.", CN107067121A. .​

部分理论引用网络文献,若有侵权联系博主删除。

5 MATLAB代码与数据下载地址

见博客主页

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。