if i have two vector how to perform single crossover?

6 ビュー (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 5 月 9 日
コメント済み: ALA SHARAF 2019 年 5 月 9 日
if i have
p1 = [ 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1]
p2 = [ 0 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 0 0]
how to perform single crossover
c1 = [ 1 0 1 1 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 0]
c2 = [ 0 0 0 0 1 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 1]

採用された回答

Star Strider
Star Strider 2016 年 5 月 9 日
This is how I do it in genetic algorithm programming:
p1 = [ 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1];
p2 = [ 0 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 0 0];
CrossoverIndex = 12; % This Would Usually Be Random
c1 = [p1(1:CrossoverIndex) p2(CrossoverIndex+1:end)];
c2 = [p2(1:CrossoverIndex) p1(CrossoverIndex+1:end)];
Producing:
c1 = 1 0 1 1 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 0
c2 = 0 0 0 0 1 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 1
  4 件のコメント
Md. Kawsar Ahmed Asif
Md. Kawsar Ahmed Asif 2018 年 5 月 26 日
Thanks a lot once again Star Strider. Now i've got it... But what about for 2-point crossover like Partially Mapped or Matched Crossover (PMX). Suppose i have two parents as following, (here i'm taking two crossover point at 3rd and 4th position)
P1 = [3 1 2 5 4]
P2 = [2 1 5 4 3] , will produce the 1st Offspring as
C1 = [4 1 2 5 3]
Again,
P2 = [2 1 5 4 3]
P1 = [3 1 2 5 4] , wili produce the remaining 2nd Offspring as
C2 = [3 1 5 4 2]
Now how can i get these Two Offspring proceeding by 'Position Wise Exchanging'? (Where two parents are mapped to each other).
Thank You
ALA SHARAF
ALA SHARAF 2019 年 5 月 9 日
Is this two point crossover. Here actually no crossover between parents. only swapping first and last element of a parent and producing a new child.

サインインしてコメントする。

その他の回答 (1 件)

Hassan Sarfraz
Hassan Sarfraz 2018 年 9 月 6 日
Thanks... but how to get these parents from these childs again?

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by