【优化求解】一种非线性动态自适应惯性权重PSO算法(IPSO)Matlab代码
一种非线性动态自适应惯性权重PSO算法(IPSO)Matlab代码
[1]王生亮,刘根友.一种非线性动态自适应惯性权重PSO算法[J].计算机仿真,2021,38(04):249-253+451.


部分代码:
function [gbest,gbestval,fitcount]= CLPSO_new_func(fhd,Max_Gen,Max_FES,Particle_Number,Dimension,VRmin,VRmax,varargin)
%[gbest,gbestval,fitcount]= CLPSO_new_func('f8',3500,200000,30,30,-5.12,5.12)
rand('state',sum(100*clock));
me=Max_Gen;
ps=Particle_Number;
D=Dimension;
cc=[1 1]; %acceleration constants
t=0:1/(ps-1):1;t=5.*t;
Pc=0.0+(0.5-0.0).*(exp(t)-exp(t(1)))./(exp(t(ps))-exp(t(1)));
% Pc=0.5.*ones(1,ps);
m=0.*ones(ps,1);
iwt=0.9-(1:me)*(0.7/me);
% iwt=0.729-(1:me)*(0.0/me);
cc=[1.49445 1.49445];
if length(VRmin)==1VRmin=repmat(VRmin,1,D);VRmax=repmat(VRmax,1,D);
end
mv=0.2*(VRmax-VRmin);
VRmin=repmat(VRmin,ps,1);
VRmax=repmat(VRmax,ps,1);
Vmin=repmat(-mv,ps,1);
Vmax=-Vmin;
pos=VRmin+(VRmax-VRmin).*rand(ps,D);for i=1:ps;e(i,1)=feval(fhd,pos(i,:),varargin{:});
endfitcount=ps;
vel=Vmin+2.*Vmax.*rand(ps,D);%initialize the velocity of the particles
pbest=pos;
pbestval=e; %initialize the pbest and the pbest's fitness value
[gbestval,gbestid]=min(pbestval);
gbest=pbest(gbestid,:);%initialize the gbest and the gbest's fitness value
gbestrep=repmat(gbest,ps,1);stay_num=zeros(ps,1);ai=zeros(ps,D);
f_pbest=1:ps;f_pbest=repmat(f_pbest',1,D);
for k=1:psar=randperm(D);ai(k,ar(1:m(k)))=1;fi1=ceil(ps*rand(1,D));fi2=ceil(ps*rand(1,D));fi=(pbestval(fi1)<pbestval(fi2))'.*fi1+(pbestval(fi1)>=pbestval(fi2))'.*fi2;bi=ceil(rand(1,D)-1+Pc(k));if bi==zeros(1,D),rc=randperm(D);bi(rc(1))=1;endf_pbest(k,:)=bi.*fi+(1-bi).*f_pbest(k,:);
endstop_num=0;
i=1;while i<=me&fitcount<=Max_FESi=i+1;for k=1:psif stay_num(k)>=5% if round(i/10)==i/10%|stay_num(k)>=5stay_num(k)=0;ai(k,:)=zeros(1,D);f_pbest(k,:)=k.*ones(1,D);ar=randperm(D);ai(k,ar(1:m(k)))=1;fi1=ceil(ps*rand(1,D));fi2=ceil(ps*rand(1,D));fi=(pbestval(fi1)<pbestval(fi2))'.*fi1+(pbestval(fi1)>=pbestval(fi2))'.*fi2;bi=ceil(rand(1,D)-1+Pc(k));if bi==zeros(1,D),rc=randperm(D);bi(rc(1))=1;endf_pbest(k,:)=bi.*fi+(1-bi).*f_pbest(k,:);endfor dimcnt=1:Dpbest_f(k,dimcnt)=pbest(f_pbest(k,dimcnt),dimcnt);endaa(k,:)=cc(1).*(1-ai(k,:)).*rand(1,D).*(pbest_f(k,:)-pos(k,:))+cc(2).*ai(k,:).*rand(1,D).*(gbestrep(k,:)-pos(k,:));%~~~~~~~~~~~~~~~~~~~~~~vel(k,:)=iwt(i).*vel(k,:)+aa(k,:);vel(k,:)=(vel(k,:)>mv).*mv+(vel(k,:)<=mv).*vel(k,:);vel(k,:)=(vel(k,:)<(-mv)).*(-mv)+(vel(k,:)>=(-mv)).*vel(k,:);pos(k,:)=pos(k,:)+vel(k,:);if (sum(pos(k,:)>VRmax(k,:))+sum(pos(k,:)<VRmin(k,:)))==0;e(k,1)=feval(fhd,pos(k,:),varargin{:});fitcount=fitcount+1;tmp=(pbestval(k)<=e(k));if tmp==1stay_num(k)=stay_num(k)+1;endtemp=repmat(tmp,1,D);pbest(k,:)=temp.*pbest(k,:)+(1-temp).*pos(k,:);pbestval(k)=tmp.*pbestval(k)+(1-tmp).*e(k);%update the pbestif pbestval(k)<gbestvalgbest=pbest(k,:);gbestval=pbestval(k);gbestrep=repmat(gbest,ps,1);%update the gbestendendend% if round(i/100)==i/100% plot(pos(:,D-1),pos(:,D),'b*');hold on;% for k=1:floor(D/2)% plot(gbest(:,2*k-1),gbest(:,2*k),'r*');% end% hold off% title(['PSO: ',num2str(i),' generations, Gbestval=',num2str(gbestval)]);% axis([VRmin(1,D-1),VRmax(1,D-1),VRmin(1,D),VRmax(1,D)])% drawnow% endif fitcount>=Max_FESbreak;endif (i==me)&(fitcount<Max_FES)i=i-1;end
end
gbestval
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
