crossover.asv

来自「使用遗传算法解决TSP问题的MATLAB源代码。」· ASV 代码 · 共 21 行

ASV
21
字号
function [childpath1,childpath2]=Crossover(parentpath1,parentpath2,Pc)
[row,col]=size(path);
tempP=rand(1);
if(tempP<Pc)
    point=randperm(col-1);
    point1=min(point(1),point(2));
    point2=max(point(1),point(2));
    for j=point1+1:point2
w        [rowindex,colindex]=find(parentpath1(j)==parentpath2);
        childpath1(j)=parentpath1(colindex);
        childpath1(colindex)=parentpath1(j);
        [rowindex,colindex]=find(parentpath2(j)==parentpath1);
        childpath2(j)=parentpath2(colindex);
        childpath2(colindex)=parentpath2(j);
        parentpath1=childpath1;
        parentpath2=childpath2;
    end
else
    childpath1=parentpath1;
    childpath2=parentpath2;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?