crossover.asv
来自「用matlab编写的采用遗传算法进行图像分割的一个程序」· ASV 代码 · 共 21 行
ASV
21 行
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 + =
减小字号Ctrl + -
显示快捷键?