📄 crossover.asv
字号:
function [newpop]=crossover(oldpop,stringlength,a,b,pc);
pops=size(oldpop,1);
newpop=zeros(size(oldpop));
for i=1:pops/2
if(rand<pc)
cpoint=round(rand*(stringlength-2))+1;
newpop(i,:)=[oldpop(i,1:cpoint),oldpop(pops/2+i,cpoint+1:stringlength),0,0];
newpop(pops/2+i,:)=[oldpop(pops/2+i,1:cpoint),oldpop(i,cpoint+1:stringlength),0,0];
else
newpop(i,:)=oldpop(i,:);
newpop(pops/2+i,:)=oldpop(pops/2+i,:);
end
end
sum=0;
for j=1:stringlength
sum=sum+newpop(:,j)*2^(j-1);
newpop(:,stringlength+1)=sum;%解码
x=newpop(:,stringlength+1);
newpop(:,stringlength+2)=fitness(x,pops,stringlength)
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -