middle=scro(1,chb1+1:chb2);
scro(1,chb1+1:chb2)=scro(2,chb1+1:chb2); scro(2,chb1+1:chb2)=middle; for i=1:chb1
while find(scro(1,chb1+1:chb2)==scro(1,i)) zhi=find(scro(1,chb1+1:chb2)==scro(1,i)); y=scro(2,chb1+zhi); scro(1,i)=y; end
while find(scro(2,chb1+1:chb2)==scro(2,i)) zhi=find(scro(2,chb1+1:chb2)==scro(2,i)); y=scro(1,chb1+zhi); scro(2,i)=y; end end
for i=chb2+1:bn
while find(scro(1,1:chb2)==scro(1,i)) zhi=find(scro(1,1:chb2)==scro(1,i)); y=scro(2,zhi); scro(1,i)=y; end
while find(scro(2,1:chb2)==scro(2,i))
zhi=find(scro(2,1:chb2)==scro(2,i)); y=scro(1,zhi); scro(2,i)=y; end end end end
%-------------------------------------------------- %“变异”操作
function snnew=mut(snew,pm);
bn=size(snew,2); snnew=snew;
pmm=pro(pm); %根据变异概率决定是否进行变异操作,1则是,0则否 if pmm==1
c1=round(rand*(bn-2))+1; %在[1,bn-1]范围内随机产生一个变异位
c2=round(rand*(bn-2))+1; chb1=min(c1,c2);
chb2=max(c1,c2); x=snew(chb1+1:chb2); snnew(chb1+1:chb2)=fliplr(x); end End
六、实验结果:
运行状态: