⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocyclexover.sci

📁 基于SCILAB的The Genetic Algorithm Toolbox for SCILAB (GATS)工具箱
💻 SCI
字号:
function [c1,c2] = OCycleXover(p1,p2,bounds,Ops)
// Cyclic crossover takes two parents P1,P2 and performs cyclic
// crossover by Davis on permutation strings.  
//
// function [c1,c2] = cyclicXover(p1,p2,bounds,Ops)
// p1      - the first parent ( [solution string function value] )
// p2      - the second parent ( [solution string function value] )
// bounds  - the bounds matrix for the solution space
// Ops     - Options matrix for simple crossover [gen #SimpXovers].

rng         = (bounds(:,2)-bounds(:,1))';         // The variable ranges'
numArranges     = rng + 1; 		          // Number of each arrages
cumArranges = cumsum([0 numArranges]);
xZomeLength = sum(numArranges)+1; 		  // Length of string is numVar + fit
c1=p1;
c2=p2;
if(p1(1:xZomeLength)==p2(1:xZomeLength)),return,end;
for i= 1:size(numArranges,2)
    sz=numArranges(i);
    pfrom=(cumArranges(i)+1);
    pto=cumArranges(i+1);
    pbegin = ceil(rand(1)*sz);                       // Generate random cut point U(1,n)
    pcurrent=pbegin;
    changeps=[];
    part1 = p1(pfrom:pto);
    part2 = p2(pfrom:pto);
    while ~(part1(pbegin)==part2(pcurrent))
        pcurrent=find(part1==part2(pcurrent));
        changeps=[changeps pcurrent];
    end;
    if ~isempty(changeps)
        changeps=[pbegin changeps];
        c1(pfrom-1+changeps)=p2(pfrom-1+changeps);
        c2(pfrom-1+changeps)=p1(pfrom-1+changeps);
    end
      

end

⌨️ 快捷键说明

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