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

📄 opartmatchxover.sci

📁 基于SCILAB的The Genetic Algorithm Toolbox for SCILAB (GATS)工具箱
💻 SCI
字号:
function [c1,c2]= OPartMatchXover(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);
//disp(part1);
//disp(part2);
//halt();
        pm1=part1;
        pm2=part2;
        for i=cut1:cut2
            pm1(find(pm1==part2(i)))=-1;
            pm2(find(pm2==part1(i)))=-1;
        end
        g1=find(pm1>-1);
        g2=find(pm2>-1);
        c1(pfrom:pto)=[part1(g1(1:(cut1-1))) part2(cut1:cut2) part1(g1(cut1:(sz-1-cut2+cut1)))];
        c2(pfrom:pto)=[part2(g2(1:(cut1-1))) part1(cut1:cut2) part2(g2(cut1:(sz-1-cut2+cut1)))];
        end
    end
//disp(p1);
//disp(p2);
//disp(c1);
//disp(c2);
//halt();
endfunction

⌨️ 快捷键说明

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