Single point ordered crossover in matlab

青春壹個敷衍的年華 提交于 2019-12-01 06:32:27

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!