How to genetate random number under constraint
古いコメントを表示
I want to genetate two vector X(size=37x1) and Y(size=37x1) of random numbers between
100 to 1900 such that difference between any two numbers of one vector X or Y should be greater than 200.
I have tried generating random number again and again while rejecting if they dont met constraint.
but it make infinte loop.
Actually X and Y are cordinates of turbines. Constraint is no turbine can be in the 200 meter radius of any other turbine. Any idea for doing this very fast? Thanks

6 件のコメント
Bruno Luong
2019 年 9 月 26 日
Let see so you have 37 numbers and they must be separate by at least by a distance of 200, so you need a total length of 200x36 = 7200 which is larger than 1800. So you requirement simply is not possible to meet.
Muhammad Nabeel Hussain
2019 年 9 月 26 日
Adam
2019 年 9 月 26 日
Do they have to be random? You can create a regular grid that would put them maximal distance apart far more easily than you could create random locations. Or you can use a regular grid as a start point and add random perturbations from that if you wish. As ever when people ask for something random though the question is 'How random?' There's lots of different ways to produce a set of random numbers, that may all be considered 'random' by some criterion.
Bruno Luong
2019 年 9 月 26 日
Then your description "such that difference between any two numbers of one vector X or Y should be greater than 200." is incorrect. The two points
(100,1000)
(150, 100)
are separated by a distance larger than 200. But it is not satisfied what you have originally stated: since the difference of X is 50.
Please clarify your question.
Adam Danz
2019 年 9 月 26 日
This is actually fairly easy to do if you just monitor the distance between the turbines rather than the distance between each x and y coordinate.
Your question states "any two numbers of one vector X or Y should be greater than 200." In that case, the turbines cannot be any closer than 200*sqrt(2).
Instead of choosing values of x and y individually that have a minimum distance of 200, you just need to monitor the distance between the turbine coordinates.
Adam Danz
2019 年 9 月 26 日
採用された回答
その他の回答 (2 件)
Bruno Luong
2019 年 9 月 26 日
0 投票
Similar question has been answered in this thread
Jos (10584)
2019 年 9 月 26 日
Brute force attempt:
N = 20 ;
xyRange = [100 1900] ;
minimumDistance = 200 ;
attempt_counter = 1 ;
Distances = 0 ;
while any(Distances < minimumDistance) && attempt_counter < 10000
attempt_counter = attempt_counter + 1 ;
Pxy = randi(xyRange, N, 2) ;
Distances = pdist(Pxy) ;
end
if attempt_counter < 1000
plot(Pxy(:,1), Pxy(:,2),'bo') ;
else
disp('No positions found.') ;
end
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
