?? orderxover.sci
字號:
function [c1,c2]= OrderXover(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) p1(pfrom:pto)];
part2 = [p2(pfrom:pto) p2(pfrom:pto)];
pm1=part1(cut1:sz+cut1-1);
pm2=part2(cut1:sz+cut1-1);
for i=pfrom+cut1-1:pfrom+cut2-1
pm1=strrep(pm1,p2(i),-1);
pm2=strrep(pm2,p1(i),-1);
end
a=pm1(find(pm1(1:(cut2-cut1+1))>0));
//c=pm1((2+cut2-cut1):end);
//b=pm1(find(c)>0);
b=pm1((cut2-cut1+1)+find(pm1((2+cut2-cut1):end)>0));
c1(pfrom:pto)=[ a part2(cut1:cut2) b ];
a=pm2(find(pm2(1:(cut2-cut1+1))>0));
b=pm2((cut2-cut1+1)+find(pm2((2+cut2-cut1):end)>0));
c2(pfrom:pto)=[ a part1(cut1:cut2) b ];
end
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -