%HDE+SPX+archive
function [vp,result,count,record]=evolve1(pop,NP)
global bound lk NN maxfe%lk为变量个数,bound为边界矩阵
count=0;%记录进化过的代数
vp=ones(NP,1);
record=zeros(maxfe,2);
record(:,1)=1:maxfe;
gen=1;
blogo=0;
Afactor = 1;
archive.NP = ceil(Afactor * NP); % the maximum size of the archive
archive.pop = zeros(0, lk); % the solutions stored in te archive
SL=zeros(NP,1);
%---------------------------
F=0.5;
CR=0.9;
%---------------------------
for i=1:NP
count=count+1;
vp(i)=fun(pop(i,:));
record(count,2)=min(vp(1:i));
end
for c=gen:NN-1
%--------------------------------PCX搜索---------------------
for i=1:1%搜索次数
[v1,r1]=min(vp);
while 1
r2=max(1,ceil(rand*NP));
r3=max(1,ceil(rand*NP));
if r2~=r3&&r1~=r3&&r1~=r2
break
end
end
x1=pop(r1,:);x2=pop(r2,:);x3=pop(r3,:);
Y=SPX(x1,x2,x3);
count=count+1;
vy=fun(Y);
if vy<v1
vp(r1)=vy;
pop(r1,:)=Y;
end
record(count,2)=min(vp);
end
%---------------------------------------------------------------
pop1=pop;
vp1=vp;
popall=[pop;archive.pop];
for j=1:NP
while 1
r=[max(1,ceil(NP*rand)),max(1,ceil(NP*rand)),max(1,ceil(size(popall,1)*rand))];
if length(r)==length(unique(r))
break
end
end
temp=pop(r(1),:)+F*(pop(r(2),:)-popall(r(3),:));
child=pop(j,:);
rj=max(1,ceil(lk*rand));
for jj=1:lk
if rand<=CR||jj==rj
child(jj)=temp(jj);
end
end
%---------------------------边界处理--------------
for jj=1:lk
while child(jj)<bound(jj,1)||child(jj)>bound(jj,2);
if child(jj)<bound(jj,1)
child(jj)=2*bound(jj,1)-child(jj);
end
if child(jj)>bound(jj,2)
child(jj)=2*bound(jj,2)-child(jj);
end
end
end
% for jj=1:lk
% if child(jj)<bound(jj,1)
% child(jj)=bound(jj,1);
% end
% if child(jj)>bound(jj,2)
% child(jj)=bound(jj,2);
% end
% end
% for jj=1:lk
% if child(jj)<bound(jj,1)||child(jj)>bound(jj,2);
% child(jj)=bound(jj,1)+rand*(bound(jj,2)-bound(jj,1));
% end
% end
%-------------------------------------------------------
count=count+1;
vc=fun(child);
if vc<vp(j)
pop1(j,:)=child;
vp1(j)=vc;
SL(j)=1;
else
SL(j)=0;
end
record(count,2)=min(vp1);
if count>=maxfe
blogo=1;
break
end
end
archive = updateArchive(archive, pop(SL==1, :));
pop=pop1;
vp=vp1;
gen=gen+1;
if blogo==1
break
end
end
%----------------------------退出,将种群排序并保存-------
[vp,I]=sort(vp);
result=pop(I,:);
评论0