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

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

%___________________________________________________________________%
% Multi-Objective Grey Wolf Optimizer (MOGWO) ? ? ? ? ? ? ? ? ? ? %
% Source codes demo version 1.0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? %
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? %


clear?all
clc

drawing_flag?=?1;

TestProblem='UF2';
nVar=10;

fobj?=?cec09(TestProblem);

xrange?=?xboundary(TestProblem,?nVar);

% Lower bound and upper bound
lb=xrange(:,1)';
ub=xrange(:,2)';

VarSize=[1?nVar];

GreyWolves_num=100;
MaxIt=1000; ?% Maximum Number of Iterations
Archive_size=100; % Repository Size

alpha=0.1; ?% Grid Inflation Parameter
nGrid=10; % Number of Grids per each Dimension
beta=4;?%=4; ? % Leader Selection Pressure Parameter
gamma=2; ? ?% Extra (to be deleted) Repository Member Selection Pressure

% Initialization

GreyWolves=CreateEmptyParticle(GreyWolves_num);


for?i=1:GreyWolves_num
? ?GreyWolves(i).Velocity=0;
? ?GreyWolves(i).Position=zeros(1,nVar);
? ?for?j=1:nVar
? ? ? ?GreyWolves(i).Position(1,j)=unifrnd(lb(j),ub(j),1);
? ?end
? ?GreyWolves(i).Cost=fobj(GreyWolves(i).Position')';
? ?GreyWolves(i).Best.Position=GreyWolves(i).Position;
? ?GreyWolves(i).Best.Cost=GreyWolves(i).Cost;
end

GreyWolves=DetermineDomination(GreyWolves);

Archive=GetNonDominatedParticles(GreyWolves);

Archive_costs=GetCosts(Archive);
G=CreateHypercubes(Archive_costs,nGrid,alpha);

for?i=1:numel(Archive)
? [Archive(i).GridIndex?Archive(i).GridSubIndex]=GetGridIndex(Archive(i),G);
end

% MOGWO main loop

for?it=1:MaxIt
? ?a=2-it*((2)/MaxIt);
? ?for?i=1:GreyWolves_num
? ? ? ?
? ? ? ?clear?rep2
? ? ? ?clear?rep3
? ? ? ?
? ? ? ?% Choose the alpha, beta, and delta grey wolves
? ? ? ?Delta=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.
? ? ? ?if?size(Archive,1)>1
? ? ? ? ? ?counter=0;
? ? ? ? ? ?for?newi=1:size(Archive,1)
? ? ? ? ? ? ? ?if?sum(Delta.Position~=Archive(newi).Position)~=0
? ? ? ? ? ? ? ? ? ?counter=counter+1;
? ? ? ? ? ? ? ? ? ?rep2(counter,1)=Archive(newi);
? ? ? ? ? ? ? ?end
? ? ? ? ? ?end
? ? ? ? ? ?Beta=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.
? ? ? ?if?size(Archive,1)>2
? ? ? ? ? ?counter=0;
? ? ? ? ? ?for?newi=1:size(rep2,1)
? ? ? ? ? ? ? ?if?sum(Beta.Position~=rep2(newi).Position)~=0
? ? ? ? ? ? ? ? ? ?counter=counter+1;
? ? ? ? ? ? ? ? ? ?rep3(counter,1)=rep2(newi);
? ? ? ? ? ? ? ?end
? ? ? ? ? ?end
? ? ? ? ? ?Alpha=SelectLeader(rep3,beta);
? ? ? ?end
? ? ? ?
? ? ? ?% Eq.(3.4) in the paper
? ? ? ?c=2.*rand(1,?nVar);
? ? ? ?% Eq.(3.1) in the paper
? ? ? ?D=abs(c.*Delta.Position-GreyWolves(i).Position);
? ? ? ?% Eq.(3.3) in the paper
? ? ? ?A=2.*a.*rand(1,?nVar)-a;
? ? ? ?% Eq.(3.8) in the paper
? ? ? ?X1=Delta.Position-A.*abs(D);
? ? ? ?
? ? ? ?
? ? ? ?% Eq.(3.4) in the paper
? ? ? ?c=2.*rand(1,?nVar);
? ? ? ?% Eq.(3.1) in the paper
? ? ? ?D=abs(c.*Beta.Position-GreyWolves(i).Position);
? ? ? ?% Eq.(3.3) in the paper
? ? ? ?A=2.*a.*rand()-a;
? ? ? ?% Eq.(3.9) in the paper
? ? ? ?X2=Beta.Position-A.*abs(D);
? ? ? ?
? ? ? ?
? ? ? ?% Eq.(3.4) in the paper
? ? ? ?c=2.*rand(1,?nVar);
? ? ? ?% Eq.(3.1) in the paper
? ? ? ?D=abs(c.*Alpha.Position-GreyWolves(i).Position);
? ? ? ?% Eq.(3.3) in the paper
? ? ? ?A=2.*a.*rand()-a;
? ? ? ?% Eq.(3.10) in the paper
? ? ? ?X3=Alpha.Position-A.*abs(D);
? ? ? ?
? ? ? ?% Eq.(3.11) in the paper
? ? ? ?GreyWolves(i).Position=(X1+X2+X3)https://blog.csdn.net/qq_59747472/article/details/3;
? ? ? ?
? ? ? ?% Boundary checking
? ? ? ?GreyWolves(i).Position=min(max(GreyWolves(i).Position,lb),ub);
? ? ? ?
? ? ? ?GreyWolves(i).Cost=fobj(GreyWolves(i).Position')';
? ?end
? ?
? ?GreyWolves=DetermineDomination(GreyWolves);
? ?non_dominated_wolves=GetNonDominatedParticles(GreyWolves);
? ?
? ?Archive=[Archive
? ? ? ?non_dominated_wolves];
? ?
? ?Archive=DetermineDomination(Archive);
? ?Archive=GetNonDominatedParticles(Archive);
? ?
? ?for?i=1:numel(Archive)
? ? ? [Archive(i).GridIndex?Archive(i).GridSubIndex]=GetGridIndex(Archive(i),G);
? ?end
? ?
? ?if?numel(Archive)>Archive_size
? ? ? ?EXTRA=numel(Archive)-Archive_size;
? ? ? ?Archive=DeleteFromRep(Archive,EXTRA,gamma);
? ? ? ?
? ? ? ?Archive_costs=GetCosts(Archive);
? ? ? ?G=CreateHypercubes(Archive_costs,nGrid,alpha);
? ? ? ?
? ?end
? ?
? ?disp(['In iteration '?num2str(it)?': Number of solutions in the archive = '?num2str(numel(Archive))]);
? ?save?results
? ?
? ?% Results
? ?
? ?costs=GetCosts(GreyWolves);
? ?Archive_costs=GetCosts(Archive);
? ?
? ?if?drawing_flag==1
? ? ? ?hold?off
? ? ? ?plot(costs(1,:),costs(2,:),'k.');
? ? ? ?hold?on
? ? ? ?plot(Archive_costs(1,:),Archive_costs(2,:),'rd');
? ? ? ?legend('Grey wolves','Non-dominated solutions');
? ? ? ?drawnow
? ?end
? ?
end


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

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

见博客主页

平台注册入口