Matlab中的单点有序分频器 [英] Single point ordered crossover in matlab

查看:177
本文介绍了Matlab中的单点有序分频器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在matlab中创建有序交叉.我的父母P1和P2如下:

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].

第一个1 [在P1(2,2)和P2(2,2)处]是我的交叉点.现在我需要后代如下:

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

推荐答案

要找到交叉点,请在父级的第二行使用逻辑AND运算符:

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)];

希望这会有所帮助!

这篇关于Matlab中的单点有序分频器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆