收藏 分享(赏)

多目标粒子群matlab代码.doc

上传人:tangtianxu2 文档编号:2834370 上传时间:2018-09-28 格式:DOC 页数:27 大小:145.50KB
下载 相关 举报
多目标粒子群matlab代码.doc_第1页
第1页 / 共27页
多目标粒子群matlab代码.doc_第2页
第2页 / 共27页
多目标粒子群matlab代码.doc_第3页
第3页 / 共27页
多目标粒子群matlab代码.doc_第4页
第4页 / 共27页
多目标粒子群matlab代码.doc_第5页
第5页 / 共27页
点击查看更多>>
资源描述

1、% 改进的多目标粒子群算法,包括多个测试函数% 对程序中的部分参数进行修改将更好地求解某些函数% ZDT1NP=cell(1,50);ZDT1FV=cell(1,50);ZDT1T=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(ZDT1,0.1,50,100,2.0,1.0,0.4,200,30,zeros(1,30),ones(1,30);%-ZDT1elapsedTime=toc;ZDT1NP(i)=np;ZDT1FV(i)=fv;ZDT1T(i)=elapsedTime;display(s

2、trcat(ZDT1,num2str(i);endzdt1fv=cell2mat(ZDT1FV);zdt1fv=GetLeastFunctionValue(zdt1fv);ZDT2NP=cell(1,50);ZDT2FV=cell(1,50);ZDT2T=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(ZDT2,0.1,50,100,2.0,1.0,0.4,200,30,zeros(1,30),ones(1,30),1,zeros(1,29);%-ZDT2elapsedTime=toc;ZDT2N

3、P(i)=np;ZDT2FV(i)=fv;ZDT2T(i)=elapsedTime;display(strcat(ZDT2,num2str(i);endzdt2fv=cell2mat(ZDT2FV);zdt2fv=GetLeastFunctionValue(zdt2fv);%5ZDT3NP=cell(1,50);ZDT3FV=cell(1,50);ZDT3T=zeros(1,50);for i=1:50tic;% np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(ZDT3,0.1,50,100,2.0,1.0,0.4,400,30,zeros(1,30

4、),ones(1,30);%-ZDT3elapsedTime=toc;ZDT3NP(i)=np;ZDT3FV(i)=fv;ZDT3T(i)=elapsedTime;display(strcat(ZDT3,num2str(i);endzdt3fv=cell2mat(ZDT3FV);zdt3fv=GetLeastFunctionValue(zdt3fv);ZDT4NP=cell(1,50);ZDT4FV=cell(1,50);ZDT4T=zeros(1,50);for i=1:50tic;% np,nprule,dnp,fv,goals=ParticleSwarmOpt(ZDT4,0.1,50,1

5、00,2.0,1.0,0.4,200,10,0,-5,-5,-5,-5,-5,-5,-5,-5,-5,1,5,5,5,5,5,5,5,5,5,1,0,0,0,0,0,0,0,0,0);%-ZDT4elapsedTime=toc;ZDT4NP(i)=np;ZDT4FV(i)=fv;ZDT4T(i)=elapsedTime;display(strcat(ZDT4,num2str(i);endzdt4fv=cell2mat(ZDT4FV);zdt4fv=GetLeastFunctionValue(zdt4fv);%ZDT6NP=cell(1,50);ZDT6FV=cell(1,50);ZDT6T=z

6、eros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(ZDT6,0.1,50,100,2.0,1.0,0.4,200,10,zeros(1,10),ones(1,10);%-ZDT6elapsedTime=toc;ZDT6NP(i)=np;ZDT6FV(i)=fv;ZDT6T(i)=elapsedTime;display(strcat(ZDT6,num2str(i);endzdt6fv=cell2mat(ZDT6FV);zdt6fv=GetLeastFunctionValue(zdt6fv);CTP1NP

7、=cell(1,50);CTP1FV=cell(1,50);CTP1T=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP1,0.1,50,100,2.0,1.0,0.4,1500,5,0,-5,-5,-5,-5,1,5,5,5,5,struct(isfmopso,false,istargetdis,false,stopatborder,true);%-CTP1elapsedTime=toc;CTP1NP(i)=np;CTP1FV(i)=fv;CTP1T(i)=elapsedTime;displ

8、ay(strcat(CTP1,num2str(i);endctp1fv=cell2mat(CTP1FV);ctp1fv=GetLeastFunctionValue(ctp1fv);CTP1fmNP=cell(1,50);CTP1fmFV=cell(1,50);CTP1fmT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP1,0.1,50,100,2.0,1.0,0.4,400,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 0 0 0,struct(isfmopso,true,i

9、stargetdis,false,stopatborder,true);%-CTP1elapsedTime=toc;CTP1fmNP(i)=np;CTP1fmFV(i)=fv;CTP1fmT(i)=elapsedTime;display(strcat(CTP1fm,num2str(i);endctp1fmfv=cell2mat(CTP1fmFV);ctp1fmfv=GetLeastFunctionValue(ctp1fmfv);CTP2NP=cell(1,50);CTP2FV=cell(1,50);CTP2T=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv

10、,goals,pbest=ParticleSwarmOpt(CTP2,0.1,50,100,2.0,1.0,0.4,1500,5,0,-5,-5,-5,-5,1,5,5,5,5,struct(isfmopso,false,istargetdis,false,stopatborder,true);%-CTP2elapsedTime=toc;CTP2NP(i)=np;CTP2FV(i)=fv;CTP2T(i)=elapsedTime;display(strcat(CTP2,num2str(i);endctp2fv=cell2mat(CTP2FV);ctp2fv=GetLeastFunctionVa

11、lue(ctp2fv);CTP2fmNP=cell(1,50);CTP2fmFV=cell(1,50);CTP2fmT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP2,0.1,50,100,2.0,1.0,0.4,400,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 0 0 0,struct(isfmopso,true,istargetdis,false,stopatborder,true);%-CTP2elapsedTime=toc;CTP2fmNP(i)=np;CTP2f

12、mFV(i)=fv;CTP2fmT(i)=elapsedTime;display(strcat(CTP2fm,num2str(i);endctp2fmfv=cell2mat(CTP2fmFV);ctp2fmfv=GetLeastFunctionValue(ctp2fmfv);CTP3NP=cell(1,50);CTP3FV=cell(1,50);CTP3T=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP3,0.1,50,100,2.0,1.0,0.4,1400,5,0,-5,-5,-5,-5

13、,1,5,5,5,5,struct(isfmopso,false,istargetdis,false,stopatborder,true);%-CTP3elapsedTime=toc;CTP3NP(i)=np;CTP3FV(i)=fv;CTP3T(i)=elapsedTime;display(strcat(CTP3,num2str(i);endctp3fv=cell2mat(CTP3FV);ctp3fv=GetLeastFunctionValue(ctp3fv);CTP3fmNP=cell(1,50);CTP3fmFV=cell(1,50);CTP3fmT=zeros(1,50);for i=

14、1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP3,0.1,50,100,2.0,1.0,0.4,400,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 0 0 0,struct(isfmopso,true,istargetdis,false,stopatborder,true);%-CTP3elapsedTime=toc;CTP3fmNP(i)=np;CTP3fmFV(i)=fv;CTP3fmT(i)=elapsedTime;display(strcat(CTP3fm,num2str(i);endctp3fmfv=

15、cell2mat(CTP3fmFV);ctp3fmfv=GetLeastFunctionValue(ctp3fmfv);CTP4NP=cell(1,50);CTP4FV=cell(1,50);CTP4T=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP4,0.1,50,100,2.0,1.0,0.4,1400,5,0,-5,-5,-5,-5,1,5,5,5,5,struct(isfmopso,false,istargetdis,false,stopatborder,true);%-CTP4el

16、apsedTime=toc;CTP4NP(i)=np;CTP4FV(i)=fv;CTP4T(i)=elapsedTime;display(strcat(CTP4,num2str(i);endctp4fv=cell2mat(CTP4FV);ctp4fv=GetLeastFunctionValue(ctp4fv);CTP4fmNP=cell(1,50);CTP4fmFV=cell(1,50);CTP4fmT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP4,0.1,50,100,2.0,1.0,

17、0.4,400,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 1 0 0,struct(isfmopso,true,istargetdis,false,stopatborder,true);%-CTP4elapsedTime=toc;CTP4fmNP(i)=np;CTP4fmFV(i)=fv;CTP4fmT(i)=elapsedTime;display(strcat(CTP4fm,num2str(i);endctp4fmfv=cell2mat(CTP4fmFV);ctp4fmfv=GetLeastFunctionValue(ctp4fmfv);CTP5NP=cell(1,50);

18、CTP5FV=cell(1,50);CTP5T=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP5,0.1,50,100,2.0,1.0,0.4,200,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 0 0 0);%-CTP5elapsedTime=toc;CTP5NP(i)=np;CTP5FV(i)=fv;CTP5T(i)=elapsedTime;display(strcat(CTP5,num2str(i);endctp5fv=cell2mat(CTP5FV);ctp5fv=

19、GetLeastFunctionValue(ctp5fv);CTP6NP=cell(1,50);CTP6FV=cell(1,50);CTP6T=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP6,0.1,50,100,2.0,1.0,0.4,400,5,0,-5,-5,-5,-5,1,5,5,5,5,0 0 0 0 0);%-CTP6elapsedTime=toc;CTP6NP(i)=np;CTP6FV(i)=fv;CTP6T(i)=elapsedTime;display(strcat(CT

20、P6,num2str(i);endctp6fv=cell2mat(CTP6FV);ctp6fv=GetLeastFunctionValue(ctp6fv);CTP7NP=cell(1,50);CTP7FV=cell(1,50);CTP7T=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP7,0.1,50,100,2.0,1.0,0.4,1000,5,0,-5,-5,-5,-5,1,5,5,5,5,1 0 0 0 0);%-CTP7elapsedTime=toc;CTP7NP(i)=np;CT

21、P7FV(i)=fv;CTP7T(i)=elapsedTime;display(strcat(CTP7,num2str(i);endctp7fv=cell2mat(CTP7FV);ctp7fv=GetLeastFunctionValue(ctp7fv);CONSTRNP=cell(1,50);CONSTRFV=cell(1,50);CONSTRT=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP8,0.1,50,100,2.0,1.0,0.4,200,2,0.1,0,1,5);%-CTP8,

22、CONSTRelapsedTime=toc;CONSTRNP(i)=np;CONSTRFV(i)=fv;CONSTRT(i)=elapsedTime;display(strcat(CTP8,num2str(i);endconstrfv=cell2mat(CONSTRFV);constrfv=GetLeastFunctionValue(constrfv);SRNNP=cell(1,50);SRNFV=cell(1,50);SRNT=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP9,0.1,5

23、0,100,2.0,1.0,0.4,200,2,-20,-20,20,20);%-CTP9,SRNelapsedTime=toc;SRNNP(i)=np;SRNFV(i)=fv;SRNT(i)=elapsedTime;display(strcat(CTP9,num2str(i);endsrnfv=cell2mat(SRNFV);srnfv=GetLeastFunctionValue(srnfv);TNKNP=cell(1,50);TNKFV=cell(1,50);TNKT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=Partic

24、leSwarmOpt(CTP10,0.1,50,100,2.0,1.0,0.4,1300,2,0,0,pi,pi,struct(isfmopso,false,istargetdis,false,stopatborder,false);%-CTP10,TNKelapsedTime=toc;TNKNP(i)=np;TNKFV(i)=fv;TNKT(i)=elapsedTime;display(strcat(CTP10,num2str(i);endtnkfv=cell2mat(TNKFV);tnkfv=GetLeastFunctionValue(tnkfv);TNKfmNP=cell(1,50);T

25、NKfmFV=cell(1,50);TNKfmT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP10,0.1,50,100,2.0,1.0,0.4,300,2,0,0,pi,pi,struct(isfmopso,true,istargetdis,false,stopatborder,false);%-CTP10,TNKelapsedTime=toc;TNKfmNP(i)=np;TNKfmFV(i)=fv;TNKfmT(i)=elapsedTime;display(strcat(CTP10fm

26、,num2str(i);endtnkfmfv=cell2mat(TNKfmFV);tnkfmfv=GetLeastFunctionValue(tnkfmfv);BNHNP=cell(1,50);BNHFV=cell(1,50);BNHT=zeros(1,50);for i=1:50tic;%np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(BNH,0.1,50,100,2.0,1.0,0.4,200,2,zeros(1,2),5,3);%-BNHelapsedTime=toc;BNHNP(i)=np;BNHFV(i)=fv;BNHT(i)=elapse

27、dTime;display(strcat(BNH,num2str(i);endbnhfv=cell2mat(BNHFV);bnhfv=GetLeastFunctionValue(bnhfv);OSYNP=cell(1,50);OSYFV=cell(1,50);OSYT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(OSY,0.1,50,100,2.0,1.0,0.4,1500,6,0,0,1,0,1,0,10,10,5,6,5,10,struct(isfmopso,false,istargetdi

28、s,false,stopatborder,true);%-OSYelapsedTime=toc;OSYNP(i)=np;OSYFV(i)=fv;OSYT(i)=elapsedTime;display(strcat(OSY,num2str(i);endosyfv=cell2mat(OSYFV);osyfv=GetLeastFunctionValue(osyfv);OSYfmNP=cell(1,50);OSYfmFV=cell(1,50);OSYfmT=zeros(1,50);for i=1:50tic;np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(O

29、SY,0.1,50,100,2.0,1.0,0.4,500,6,0,0,1,0,1,0,10,10,5,6,5,10,struct(isfmopso,true,istargetdis,false,stopatborder,true);%-OSYelapsedTime=toc;OSYfmNP(i)=np;OSYfmFV(i)=fv;OSYfmT(i)=elapsedTime;display(strcat(OSYfm,num2str(i);endosyfmfv=cell2mat(OSYfmFV);osyfmfv=GetLeastFunctionValue(osyfmfv);function np,

30、nprule,dnp,fv,goals,pbest = ParticleSwarmOpt(funcname,unfitx,N,Nnp,cmax,cmin,w,M,D,lb,ub,x0,params)%待优化的目标函数:fitness%约束容忍度 unfitx=0.01,逐步降到 0%内部种群( 粒子数目) :N%外部种群( 非劣解集):Nnp%学习因子 1:cmax%学习因子 2:cmin%惯性权重:w%最大迭代次数:M%问题的维数:D%目标函数取最小值时的自变量值:xm%目标函数的最小值:fv%迭代次数:cvformat long;NP=;%非劣解集Dnp=;%非劣解集距离if nargin

31、 1.2 | w1vmax(j) tempv(k,j)=vmax(j);elseif tempv(k,j)0v(i,:)=ttv;endelse%v(i,:)=w1*v(i,:)+c*rand*(pbest(i,:)-x(i,:)+c*rand*(gbest-x(i,:);for j=1:Dif v(i,j)vmax(j) v(i,j)=vmax(j);elseif v(i,j)ub(j)if(randi(0,0,1)=0)x(i,j)=ub(j);v(i,j)=-v(i,j);else x(i,j)=lb(j)+(ub(j)-lb(j)*rand; %随机初始化位置 v(i,j)=(ub(j

32、)-lb(j)*rand*0.5; end endif x(i,j)ub(j)%粒子飞出上边界x(i,j)=x(i,j)-v(i,j);v(i,j)=rand*(ub(j)-x(i,j);x(i,j)=x(i,j)+v(i,j);elseif x(i,j) 0 nprule_out(r1+1,:)=0,faix,0;elsenprule_out(r1+1,:)=0,0,0;endif r1=0dnp_out=0;endfor j=1:r1dnp_out(r1+1,j)=GetDistance(np_out(j,:),x,funcname,params);dnp_out(j,r1+1)=dnp_

33、out(r1+1,j);endif r1=Nnp %未达到非劣解种群极限%-移除密集距离最小的一个-densedis = GetDenseDis(dnp_out); n_min = find(min(densedis)=densedis);%找出密度距离最小的一个tempIndex = randi(1,length(n_min),1); np_out(n_min(tempIndex),:)=;%非劣解剔除该解 nprule_out(n_min(tempIndex),:)=;dnp_out(n_min(tempIndex),:)=;if isempty(dnp_out)dnp_out(:,n_m

34、in(tempIndex)=; endendend%-将粒子维护到外部种群 -%function dis=GetDistance(x,y,funcname,params)%求两向量之间的距离if(params.istargetdis)gx=fitness(x,funcname);gy=fitness(y,funcname);gxy=(gx-gy).2;dis=sqrt(sum(gxy(:);elseg=x-y;dis=sum(sum(g.2);endendfunction densedis = GetDenseDis(dnp)%密集距离r,c = size(dnp);densedis=zero

35、s(1,r);for i=1:rfirstmin=Inf;%secondmin=Inf;for j=1:cif dnp(i,j)=0 elseif faiyfaix v=1;endif v=0 %x、y 构成违反约束支配关系return;endgx = fitness(x,funcname,params);%x 的目标向量gy = fitness(y,funcname,params);%y 的目标向量len = length(gx);if sum(gx=gy)=len%y 的所有目标都比 x 小,y 支配 xv=-1;endend%-比较两粒子的相互支配关系-%function gbest,n

36、prule_out = GetGlobalBest2(x,np,nprule)%按照一定原则随机取一个全局最优r=size(np,2);%非劣解的行列,r:非劣解集个数,c:维数%假定 x 被非劣解集 np 支配IsDominated=true;Mdom=;%支配 x 的集合for i=1:rdomiRel=DominateRel(np(i,:),x,funcname,params);if domiRel=1%np(i)支配 xMdom=Mdom,i;%记下其在非劣解集中的编号elseIsDominated=false;break;endendnprule_out=nprule;if IsDo

37、minated%x 被支配,从 x 的支配集中选出一个作为全局最优intem=randi(1,length(Mdom),1);gbest=np(Mdom(intem),:);nprule_out(Mdom(intem),1)=nprule_out(Mdom(intem),1)+1;else%x 不被支配,从所有非劣解集中选出一个作为全局最优nr=size(np,1);intem=randi(1,nr,1);gbest=np(intem,:);nprule_out(intem,1)=nprule_out(intem,1)+1;endendfunction gbest,nprule_out = G

38、etGlobalBest(np,nprule,dnp_out)%随机取一个全局最优r=size(np,1);%非劣解的行列nprule_out=nprule;intem=1;if(randi(0,3,1)=0) if r=1 gbest = np(1,:);elsesparedis = GetSpareDis(dnp_out);%max1,max2 = find(max(max(dnp_out)=dnp_out);%intem=max1(randi(1,length(max1),1);n_max=find(max(sparedis)=sparedis);intem=n_max(randi(1,

39、length(n_max),1);gbest = np(intem,:); end else %rr=randi(1,r,1);%随机取一个作为全局最优%gbest = np(rr,:);tt=find(min(nprule(:,1)=nprule(:,1); intem=tt(randi(1,length(tt),1); gbest = np(intem,:); endnprule_out(intem,1)=nprule_out(intem,1)+1;end%-从部种群中找到全局最优-%function x,v,pbest,NP,NPRule,Dnp=ReInit(x,v,pbest,NP,

40、NPRule,Dnp,Nnp,D,lb,ub,unfitx,funcname,params)for i=1:10for j=1:Dx(i,j)=(ub(j)-lb(j)*rand; %随机初始化位置 v(i,j)=(ub(j)-lb(j)*rand*0.5; %随机初始化速度pbest(i,j)=x(i,j);endendfor i=1:10faix = GetFai(x(i,:),funcname,params);if faix0.921164494015440)x1=0.280776612246391;elsex1=sqrt(1-y0);endfor i=1:1001x=x0+(x1-x0

41、)/1000*(i-1);y=1-x2;dd(i)=sqrt(x-x0)2+(y-y0)2);end%-ZDT3case ZDT3x1=fzero(x)(1-sqrt(x)-x*sin(10*pi*x)-y0),x0);if(isnan(x1)x1=x0;endfor i=1:1001x=x0+(x1-x0)/1000*(i-1);y=1-sqrt(x)-x*sin(10*pi*x);dd(i)=sqrt(x-x0)2+(y-y0)2);end case CTP1,CTP2,CTP3,CTP4,CTP5,CTP6,CTP7,CTP8,CONSTR,CTP9,SRN,CTP10,TNK,MOP-

42、C4,MOP-C1,BNH,MOP-C2,OSYfvin = stdfv;fvin(:,1) = fvin(:,1)-x0;fvin(:,2) = fvin(:,2)-y0;dd = sqrt(sum(fvin.2,2); endd=min(dd);endfunction GD=GenerationalDistance2(funcname,np)%世代距离 GD(七点法)n=size(np,1);m=size(fitness(np(1,:),funcname),2);f=zeros(n,m);if(n=1)GD=0;return;endfor i=1:nf(i,:)=fitness(np(i,

43、:),funcname);endn,k=size(f);%n:解的个数;k: 解的维数;fmax = max(f);d=zeros(1,n);for i=1:nd(i)=GetSchottDis(fmax,k,f(i,:);endGD=sqrt(sum(d.2)/n;endfunction d = GetSchottDis(fmax,k,x)xmin = zeros(1,k);ds = sqrt(sum(x-xmin).2);%到(0,0,.,0) 点的距离;for i=1:kxk1=x;xk1(i)=xk1(i)-fmax(i)/3;ds=ds+sqrt(sum(xk1-xmin).2);%到(0,0,.,fi/3,.,0)点的距离;xk2=x;xk2(i)=xk2(i)-2*fmax(i)/3;ds=ds+sqrt(sum(xk2-xmin).2);%到(0,0,.,2fi/3,.,0)点的距离;xk3=x;xk3(i)=xk3(i)-fmax(i);ds=ds+sqrt(sum(xk3-xmin).2);%到(0,0,.,fi,.,0)点的距离;endd=ds/(k+1);%x 到这(k+1)个点的距离的平均值end

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 专业基础教材

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报