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에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
