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

📄 oslidexover.sci

📁 基于SCILAB的The Genetic Algorithm Toolbox for SCILAB (GATS)工具箱
💻 SCI
字号:
function [c1,c2]= OSlideXover(p1,p2,bounds,Ops)
// Orderbased crossover takes two parents P1,P2 and performs  order
// based crossover by Davis.  
//
// function [c1,c2] = orderbasedXover(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);
    cut1 = ceil(rand(1)*sz);             // Generate random cut point U(1,n)
    cut2 = ceil(rand(1)*sz);             // Generate random cut point U(1,n)
    if ( (~(cut1==cut2)) & abs(cut1-cut2)<(sz-1) )
        if (cut1>cut2)
            temp=cut2;
            cut2=cut1;
            cut1=temp;
        end
        part1 = p1(pfrom:pto);
        part2 = p2(pfrom:pto);
        pm1=part1;
        pm2=part2;
        for i=cut1:cut2
            pm1=strrep(pm1,part2(i),-1);
            pm2=strrep(pm2,part1(i),-1);
        end
        g1=[find(pm1(cut1:end)>-1) find(pm1(1:cut1)>-1)];
        g2=[find(pm2(cut1:end)>-1) find(pm1(1:cut1)>-1)];
        c1(pfrom:pto)=[pm2(cut1:cut2) pm1(g1)];
        c2(pfrom:pto)=[pm1(cut1:cut2) pm2(g2)];
        end
    end

end

⌨️ 快捷键说明

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