?? ocyclexover.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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -