cxcrossover.m
来自「基于信息熵的免疫算法」· M 代码 · 共 40 行
M
40 行
function [childpath1,childpath2]=CXCrossover(parentpath1,parentpath2,Pc)
%循环交叉
tempP=rand(1);
if(tempP<Pc)
col=length(parentpath1);
A=zeros(1,col);
i=1;
A(i)=1;
k=1;
childpath1(1)=parentpath1(1);
[rwoindex,colindex]=find(parentpath1(1)==parentpath2);
k=colindex;
while(not(length(find(k==A))))
childpath1(colindex)=parentpath1(colindex);
i=i+1;
A(i)=k;
[rwoindex,colindex]=find(parentpath1(colindex)==parentpath2);
k=colindex;
end
for j=1:col
if(not(length(find(j==A))))
childpath1(j)=parentpath2(j);
end
end
childpath2=parentpath2;
for j=1:col
if(not(length(find(j==A))))
childpath2(j)=parentpath1(j);
end
end
else
childpath1=parentpath1;
childpath2=parentpath2;
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?