I need to create ordered crossover in matlab. I have parents P1 and P2 as follow:
P1=[1 2 3 4 ; 0 1 1 0],
P2=[3 2 1 4 ; 0 1 0 0].
First 1 [at place P1(2,2) and P2(2,2)] is my crossover point. now I need to offsprings as follow:
O1=[1 2 3 4 ; 0 1 0 0],
O2=[3 2 1 4 ; 0 1 0 0].
Can you please help me? Best, Elnaz
To find the crossover point, use a logical AND operator on the second line of the parents:
idx = find(P1(2, :) & P2(2, :));
Then we create the offsprings by switching values between parents after the crossover point:
O1 = [P1(:, 1:idx), P2(:, idx + 1:end)];
O2 = [P2(:, 1:idx), P1(:, idx + 1:end)];
Hope this helps!
来源:https://stackoverflow.com/questions/16302382/single-point-ordered-crossover-in-matlab