How to genetate random number under constraint
Show older comments
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 Comments
Bruno Luong
on 26 Sep 2019
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
on 26 Sep 2019
Adam
on 26 Sep 2019
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
on 26 Sep 2019
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
on 26 Sep 2019
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
on 26 Sep 2019
Accepted Answer
More Answers (2)
Bruno Luong
on 26 Sep 2019
0 votes
Similar question has been answered in this thread
Jos (10584)
on 26 Sep 2019
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
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!