How to use crossover and mutation ?

2 ビュー (過去 30 日間)
Mira le
Mira le 2019 年 12 月 20 日
回答済み: Star Strider 2019 年 12 月 20 日
my population is lake that
p1 = [ 9 3 6 0 0]
p2 = [1 0 2 5 0 ]
how to use crossover and mutation to obtain new solution?

採用された回答

Star Strider
Star Strider 2019 年 12 月 20 日
There are many possibilities.
Likely the simplest:
p1 = [ 9 3 6 0 0] % Parent
p2 = [1 0 2 5 0 ] % Parent
idx = randi(numel(p1)-1);
p1x = [p1(1:idx) p2(idx+1:end)] % Crossover
p2x = [p2(1:idx) p1(idx+1:end)] % Crossover
idx = randi(numel(p1));
p1m = p1;
p2m = p2;
p1m(idx) = randi(9) % Mutatiion
p2m(idx) = randi(9) % Mutatiion
producing (in this run):
p1 =
9 3 6 0 0
p2 =
1 0 2 5 0
idx =
3
p1x =
9 3 6 5 0
p2x =
1 0 2 0 0
idx =
3
p1m =
9 3 8 0 0
p2m =
1 0 1 5 0
The ‘idx’ values both just happened to be the same this time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by