Shuffle vector with constraints
古いコメントを表示
Hi,
I have an array of 50 1's, 50 2's, etc up to 50 8's. I would like to shuffle them with the constraint that two consecutive numbers cannot be the same. I tried several options but most are very cpu intensive or did not yield a good result. Are there computation efficient solutions to this problem?
1 件のコメント
Azzi Abdelmalek
2014 年 1 月 14 日
This is not enough as information. Because you can set them for example [1 2 3 1 2 3 1 2 3 . . .]
採用された回答
その他の回答 (3 件)
Mischa Kim
2014 年 1 月 14 日
編集済み: Mischa Kim
2014 年 1 月 14 日
Since I do not know what techniques you have tried, here's (another) one? Start with sorting the 1's, 2's, etc. in matrix form, i.e.,
1 1 1 1...
2 2 2 2...
3 3 3 3...
and perform permutations on the individual columns (e.g using randperm). Based on the entry of the last row in the first column randomly pick a column vector with a different first row entry and make it the new second column. Using this process work your way through all the columns (you might have to do some more permutations towards the final columns). Once done, transpose and concenate all of the column vectors.
Pieter
2014 年 1 月 14 日
0 投票
1 件のコメント
Mischa Kim
2014 年 1 月 14 日
編集済み: Mischa Kim
2014 年 1 月 14 日
Hello Pieter,
- Understood. I used the permutation for shuffling with a certain level of randomness (while satisfying the constraint).
- You can still use the approach outlined above by randomly tossing in the 30 9's into the vector at the end.
カテゴリ
ヘルプ センター および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!