Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<random> uniform_real_distribution with minimum distance between points

Tags:

c++

random

I am generating a list of coordinates on a square using

#include <random>
using namespace std;

int main(){

random_device rd;
long int seed = rd();
default_random_engine gen(seed);

double max=10.0, min=-10.0;
uniform_real_distribution<double> uni_real(min,max);

double random_x = uni_real(gen);
double random_y = uni_real(gen);

return 0;
}

I would like to ensure that there is a minimum distance between any two points. For my usage, this must hold when periodic boundary conditions are applied.

  • Preferred solution would be a built in method in the <random> library to this. Is there any?
  • Second best, any other package containing a fast way to perform the check (as long as it is easy to make use of).
  • Worst case, I can write my own basic script which would be O(n^2) as I am not too concerned with efficiency right now. Unless, there is some easy algorithm to implement that can do this.

Other questions around where either dealing with the third point or with other environment from <random>.

like image 868
Three Diag Avatar asked Jul 25 '15 11:07

Three Diag


1 Answers

While such sampling (which is equivalent to non-overlapping circles generation) is discussed on math.stackexchange, see https://mathematica.stackexchange.com/questions/2594/efficient-way-to-generate-random-points-with-a-predefined-lower-bound-on-their-p and https://mathematica.stackexchange.com/questions/69649/generate-nonoverlapping-random-circles, I would like to point out to another potential solution which involves quasi-random numbers. For quasi-random Sobol sequences there is a statement which says that there is minimum positive distance between points which amounts to 0.5*sqrt(d)/N, where d is dimension of the problem, and N is number of points sampled in hypercube. Paper from the man himself http://www.sciencedirect.com/science/article/pii/S0378475406002382

like image 116
Severin Pappadeux Avatar answered Nov 13 '22 04:11

Severin Pappadeux