多目标粒子群matlab代码.doc_第1页
多目标粒子群matlab代码.doc_第2页
多目标粒子群matlab代码.doc_第3页
多目标粒子群matlab代码.doc_第4页
多目标粒子群matlab代码.doc_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

% 改进的多目标粒子群算法,包括多个测试函数% 对程序中的部分参数进行修改将更好地求解某些函数% ZDT1NP=cell(1,50);ZDT1FV=cell(1,50);ZDT1T=zeros(1,50);for i=1:50 tic; %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);%-ZDT1 elapsedTime=toc; ZDT1NP(i)=np; ZDT1FV(i)=fv; ZDT1T(i)=elapsedTime;display(strcat(ZDT1,num2str(i);endzdt1fv=cell2mat(ZDT1FV);zdt1fv=GetLeastFunctionValue(zdt1fv);ZDT2NP=cell(1,50);ZDT2FV=cell(1,50);ZDT2T=zeros(1,50);for i=1:50 tic; %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);%-ZDT2 elapsedTime=toc; ZDT2NP(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:50 tic;% np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(ZDT3,0.1,50,100,2.0,1.0,0.4,400,30,zeros(1,30),ones(1,30);%-ZDT3 elapsedTime=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:50 tic;% np,nprule,dnp,fv,goals=ParticleSwarmOpt(ZDT4,0.1,50,100,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);%-ZDT4 elapsedTime=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=zeros(1,50);for i=1:50 tic; %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);%-ZDT6 elapsedTime=toc; ZDT6NP(i)=np; ZDT6FV(i)=fv; ZDT6T(i)=elapsedTime;display(strcat(ZDT6,num2str(i);endzdt6fv=cell2mat(ZDT6FV);zdt6fv=GetLeastFunctionValue(zdt6fv);CTP1NP=cell(1,50);CTP1FV=cell(1,50);CTP1T=zeros(1,50);for i=1:50 tic; 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);%-CTP1 elapsedTime=toc; CTP1NP(i)=np; CTP1FV(i)=fv; CTP1T(i)=elapsedTime;display(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:50 tic; 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,istargetdis,false,stopatborder,true);%-CTP1 elapsedTime=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:50 tic; np,nprule,dnp,fv,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);%-CTP2 elapsedTime=toc; CTP2NP(i)=np; CTP2FV(i)=fv; CTP2T(i)=elapsedTime;display(strcat(CTP2,num2str(i);endctp2fv=cell2mat(CTP2FV);ctp2fv=GetLeastFunctionValue(ctp2fv);CTP2fmNP=cell(1,50);CTP2fmFV=cell(1,50);CTP2fmT=zeros(1,50);for i=1:50 tic; 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);%-CTP2 elapsedTime=toc; CTP2fmNP(i)=np; CTP2fmFV(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:50 tic; 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,1,5,5,5,5,struct(isfmopso,false,istargetdis,false,stopatborder,true);%-CTP3 elapsedTime=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=1:50 tic; 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);%-CTP3 elapsedTime=toc; CTP3fmNP(i)=np; CTP3fmFV(i)=fv; CTP3fmT(i)=elapsedTime;display(strcat(CTP3fm,num2str(i);endctp3fmfv=cell2mat(CTP3fmFV);ctp3fmfv=GetLeastFunctionValue(ctp3fmfv);CTP4NP=cell(1,50);CTP4FV=cell(1,50);CTP4T=zeros(1,50);for i=1:50 tic; 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);%-CTP4 elapsedTime=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:50 tic; np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP4,0.1,50,100,2.0,1.0,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);%-CTP4 elapsedTime=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);CTP5FV=cell(1,50);CTP5T=zeros(1,50);for i=1:50 tic; %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);%-CTP5 elapsedTime=toc; CTP5NP(i)=np; CTP5FV(i)=fv; CTP5T(i)=elapsedTime;display(strcat(CTP5,num2str(i);endctp5fv=cell2mat(CTP5FV);ctp5fv=GetLeastFunctionValue(ctp5fv);CTP6NP=cell(1,50);CTP6FV=cell(1,50);CTP6T=zeros(1,50);for i=1:50 tic; %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);%-CTP6 elapsedTime=toc; CTP6NP(i)=np; CTP6FV(i)=fv; CTP6T(i)=elapsedTime;display(strcat(CTP6,num2str(i);endctp6fv=cell2mat(CTP6FV);ctp6fv=GetLeastFunctionValue(ctp6fv);CTP7NP=cell(1,50);CTP7FV=cell(1,50);CTP7T=zeros(1,50);for i=1:50 tic; %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);%-CTP7 elapsedTime=toc; CTP7NP(i)=np; CTP7FV(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:50 tic; %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,CONSTR elapsedTime=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:50 tic; %np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(CTP9,0.1,50,100,2.0,1.0,0.4,200,2,-20,-20,20,20);%-CTP9,SRN elapsedTime=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:50 tic; np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(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,TNK elapsedTime=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);TNKfmFV=cell(1,50);TNKfmT=zeros(1,50);for i=1:50 tic; 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,TNK elapsedTime=toc; TNKfmNP(i)=np; TNKfmFV(i)=fv; TNKfmT(i)=elapsedTime;display(strcat(CTP10fm,num2str(i);endtnkfmfv=cell2mat(TNKfmFV);tnkfmfv=GetLeastFunctionValue(tnkfmfv);BNHNP=cell(1,50);BNHFV=cell(1,50);BNHT=zeros(1,50);for i=1:50 tic; %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);%-BNH elapsedTime=toc; BNHNP(i)=np; BNHFV(i)=fv; BNHT(i)=elapsedTime;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:50 tic; 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,istargetdis,false,stopatborder,true);%-OSY elapsedTime=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:50 tic; np,nprule,dnp,fv,goals,pbest=ParticleSwarmOpt(OSY,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);%-OSY elapsedTime=toc; OSYfmNP(i)=np; OSYfmFV(i)=fv; OSYfmT(i)=elapsedTime;display(strcat(OSYfm,num2str(i);endosyfmfv=cell2mat(OSYfmFV);osyfmfv=GetLeastFunctionValue(osyfmfv);function np,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 13 params = struct(isfmopso,false,istargetdis,false,stopatborder,true);endif (nargin 12 | isempty(x0) x0=lb+(ub-lb).*rand(1,D);endT=size(fitness(x0,funcname),2);goals=zeros(M,N,T);%记下N个粒子M次迭代T维目标变化%-初始化种群的个体-/第1步/x(1,:)=x0;v(1,:)=(ub-lb).*rand(1,D)*0.5;for i=2:N for j=1:D x(i,j)=lb(j)+(ub(j)-lb(j)*rand; %随机初始化位置 v(i,j)=(ub(j)-lb(j)*rand*0.5; %随机初始化速度 endend%-计算目标向量-%-速度控制vmax=(ub-lb)*0.5;vmin= -vmax;%-求出初始NP-/第2步/NP(1,:)=x(1,:);%第一个默认加入NPNPRule=0,0,0;%非劣解集参数Dnp(1,1)=0;for i=2:N faix = GetFai(x(i,:),funcname,params); if faix=unfitx NP,NPRule,Dnp = compare(x(i,:),NP,NPRule,Dnp,Nnp,funcname,params); endend%-初始自身最好位置-/第3步/pbest = x;%自身最优解%-在确定每个粒子所对就的目标方格-/第4步/%-进入主要循环,按照公式依次迭代-for t=1:M if mod(t,100)=0 unfitx = 0.01-0.01*(t+200)/M; if unfitx 1.2 | w1vmax(j) tempv(k,j)=vmax(j); elseif tempv(k,j)vmin(j) tempv(k,j)=vmin(j); end end tempx(k,:)=x(i,:)+tempv(k,:); faix = GetFai(x(i,:),funcname,params); if faix0 v(i,:)=ttv; end else% v(i,:)=w1*v(i,:)+c*rand*(pbest(i,:)-x(i,:)+c*rand*(gbest-x(i,:); for j=1:D if 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)-lb(j)*rand*0.5; end end if 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)lb(j)%粒子飞出下边界 x(i,j)=x(i,j)-v(i,j); v(i,j)=rand*(x(i,j)-lb(j); x(i,j)=x(i,j)-v(i,j); end end end% %-每个粒子的目标向量-/第8步/ goals(t,i,:)=fitness(x(i,:),funcname,params);%-调整自身-/第10步/ domiRel = DominateRel(pbest(i,:),x(i,:),funcname,params);%x,y的支配关系 if domiRel=1%pbest支配新解 continue; else if domiRel=-1%新解支配pbest pbest(i,:) = x(i,:); elseif(randi(0,1,1)=0)%新解与pbest互相不支配 pbest(i,:) = x(i,:); end%-对NP进行更新和维护-/第9步/ faix = GetFai(x(i,:),funcname,params); if faix 0 nprule_out(r1+1,:)=0,faix,0;else nprule_out(r1+1,:)=0,0,0;endif r1=0 dnp_out=0;endfor j=1:r1 dnp_out(r1+1,j)=GetDistance(np_out(j,:),x,funcname,params); dnp_out(j,r1+1)=dnp_out(r1+1,j);endif r1=Nnp %未达到非劣解种群极限 %-移除密集距离最小的一

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论