MATLAB: Problem of PSO code: ab=1/sqrt(​2)*ones(2,​G*T);

pso optimization unit commitment

swarm=zeros(NP,G*T);%
ab=1/sqrt(2)*ones(2,G*T);
for n=1:NP
swarml=initial(G,T);
[swarm(n,:),swarmTOFF(:,:,n)]=Verify(swarml,G,T,x0,MUT,MDT,InitialTON,InitialTOFF,PMAX,PD,SR,h);
[fitness(n)]=ObjectFitness(swarm(n,:),G,T,x0,MDT,PMAX,PMIN,PD,a,b,c,SUH,SUC,Tcold,swarmTOFF(:,:,n));
end
Gmbest=swarm(1,:);
Gfitness=fitness(1);
for n=1:NP
Pmbest(n,:)=swarm(n,:);
Pfitness(n)=fitness(n);
if Gfitness>Pfitness(n)
Gmbest=Pmbest(n,:);
Gfitness=Pfitness(n);
end
end
for n=1:NP
ab1(:,:,n)=ab;
end
for k=1:ITERmax
for n=1:NP [swarm(n,:),ab1(:,:,n)]=Update(swarm(n,:),G,T,Pmbest(n,:),Gmbest,fitness(n),Pfitness(n),Gfitness,Zmax,Zmin,k,ITERmax,ab1(:,:,n));
[swarm(n,:),swarmTOFF(:,:,n)]=Verify(swarm(n,:),G,T,x0,MUT,MDT,InitialTON,InitialTOFF,PMAX,PD,SR,h);
[fitness(n)]=ObjectFitness(swarm(n,:),G,T,x0,MDT,PMAX,PMIN,PD,a,b,c,SUH,SUC,Tcold,swarmTOFF(:,:,n));
% end
% for n=1:NP
if Pfitness(n)>=fitness(n)
Pmbest(n,:)=swarm(n,:);
% Ptmbest(:,:,n)=Mp(:,:,n);
Pfitness(n)=fitness(n);
end
if Gfitness>Pfitness(n)
Gmbest=Pmbest(n,:);
% Gptbest=Ptmbest(:,:,n);
Gfitness=Pfitness(n);
end
end
end
does the ab(ab=1/sqrt(2)*ones(2,G*T);) means V(i,j)of PSO? what kind of matrix “ab”create? and what's ab1(:,:,n)=ab; means?

Best Answer

  • does the ab(ab=1/sqrt(2)*ones(2,G*T);) means V(i,j)of PSO
Not exactly, but close enough.
  • what kind of matrix “ab”create?
A double precision matrix with 2 rows and G*T columns
  • and what's ab1(:,:,n)=ab; means
Copy the entire matrix ab into the two-dimensional slice #n of ab1. Those three lines of code make a three-dimensional matrix ab1 in which every layer is a copy of ab. The "for" loop could be replaced with
ab1 = repmat(ab, 1, 1, NP);