代码拉取完成,页面将自动刷新
function NewChrom=xovmp(OldChrom,Px,Npt,Rs)
[Nind,Lind]=size(OldChrom);
Xops=floor(Nind/2);
DoCross=rand(Xops,1)<Px;
odd=1:2:Nind-1;
even=2:2:Nind;
Mask=~Rs|(OldChrom(odd,:)~=OldChrom(even,:));
Mask=cumsum(Mask')';
xsites(:,1)=Mask(:,Lind);
if Npt>=2,
xsites(:,1)=ceil(xsites(:,1).*rand(Xops,1));
end
xsites(:,2)=rem(xsites+ceil((Mask(:,Lind)-1).*rand(Xops,1))...
.*DoCross-1,Mask(:,Lind))+1;
Mask=(xsites(:,ones(1,Lind))<Mask)==...
(xsites(:,2*ones(1,Lind))<Mask);
if ~Npt,
shuff=rand(Lind,Xops);
[ans,shuff]=sort(shuff);
for i=1:Xops
OldChrom(odd(i),:)=OldChrom(odd(i),shuff(:,i));
OldChrom(even(i),:)=OldChrom(even(i),shuff(:,i));
end
end
NewChrom(odd,:)=(OldChrom(odd,:).*Mask)+(OldChrom(even,:).*(~Mask));
NewChrom(even,:)=(OldChrom(odd,:).*(~Mask))+(OldChrom(even,:).*Mask);
if rem(Nind,2),
NewChrom(Nind,:)=OldChrom(Nind,:);
end
if ~Npt,
[ans,unshuff]=sort(shuff);
for i=1:Xops
NewChrom(odd(i),:)=NewChrom(odd(i),unshuff(:,i));
NewChrom(even(i),:)=NewChrom(even(i),unshuff(:,i));
end
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。