Skip to main content
added 5 characters in body
Source Link
Daniel Lichtblau
  • 60.3k
  • 2
  • 105
  • 201

Here is an outline of a fairly efficient way to do this.

Say you want to generate $m$ points with a minimum separation of $d$, in a box of size $s \times s$. Let $d_2=\max(d,\sqrt{m}/s)$. Partition your box into subsquares of size $d_2 x d_2$$d_2 \times d_2$; these will be used as bins. We will generate, say, $3m$ random points in the full box. Now place each in its appropriate bin. This can be done in $\mathcal{O}(m)$.

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, see if it is within distance $d$ of the candidate point and has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is $\mathcal{O}(1)$).

We stop once we have $m$ points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoof-print is $\mathcal{O}(d_2^2)$. The speed will typically be $\mathcal{O}(m)$ unless the sizes of $d$ and $s$ make it either difficult or impossible to have $m$ points inside with minimal separation of distance $d$.

Here is an outline of a fairly efficient way to do this.

Say you want to generate $m$ points with a minimum separation of $d$, in a box of size $s \times s$. Let $d_2=\max(d,\sqrt{m}/s)$. Partition your box into subsquares of size $d_2 x d_2$; these will be used as bins. We will generate, say, $3m$ random points in the full box. Now place each in its appropriate bin. This can be done in $\mathcal{O}(m)$.

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, see if it is within distance $d$ of the candidate point and has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is $\mathcal{O}(1)$).

We stop once we have $m$ points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoof-print is $\mathcal{O}(d_2^2)$. The speed will typically be $\mathcal{O}(m)$ unless the sizes of $d$ and $s$ make it either difficult or impossible to have $m$ points inside with minimal separation of distance $d$.

Here is an outline of a fairly efficient way to do this.

Say you want to generate $m$ points with a minimum separation of $d$, in a box of size $s \times s$. Let $d_2=\max(d,\sqrt{m}/s)$. Partition your box into subsquares of size $d_2 \times d_2$; these will be used as bins. We will generate, say, $3m$ random points in the full box. Now place each in its appropriate bin. This can be done in $\mathcal{O}(m)$.

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, see if it is within distance $d$ of the candidate point and has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is $\mathcal{O}(1)$).

We stop once we have $m$ points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoof-print is $\mathcal{O}(d_2^2)$. The speed will typically be $\mathcal{O}(m)$ unless the sizes of $d$ and $s$ make it either difficult or impossible to have $m$ points inside with minimal separation of distance $d$.

added 77 characters in body
Source Link
rm -rf
  • 89.3k
  • 21
  • 297
  • 479

Here is an outline of a fairly efficient way to do this.

Say you want to generate m$m$ points, with a minimum separation of d$d$, in a box of size s x s$s \times s$. Let d2=max(d,sqrt(m)/s)$d_2=\max(d,\sqrt{m}/s)$. Consider a partitionPartition your box into subsquares of size d2 x d2;$d_2 x d_2$; these will be used as bins. We will generate, say, 3m$3m$ random points in the full box. Now place each in its appropriate bin. This can be done in O(m)$\mathcal{O}(m)$.

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, (1) Seesee if it is within distance d$d$ of the candidate point ANDand has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is O(1)$\mathcal{O}(1)$).

We stop once we have m$m$ points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoofprinthoof-print is O(d2^2)$\mathcal{O}(d_2^2)$. The speed will typically be O(m)$\mathcal{O}(m)$ unless the sizes of d$d$ and s$s$ make it either difficult or impossible to have m$m$ points inside with minimal separation of distance d$d$.

Here is an outline of a fairly efficient way to do this.

Say you want to generate m points, minimum separation of d, in a box of size s x s. Let d2=max(d,sqrt(m)/s). Consider a partition your box into subsquares of size d2 x d2; these will be used as bins. We will generate, say, 3m random points in the full box. Now place each in its appropriate bin. This can be done in O(m).

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, (1) See if it is within distance d of the candidate point AND has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is O(1)).

We stop once we have m points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoofprint is O(d2^2). The speed will typically be O(m) unless the sizes of d and s make it either difficult or impossible to have m points inside with minimal separation of distance d.

Here is an outline of a fairly efficient way to do this.

Say you want to generate $m$ points with a minimum separation of $d$, in a box of size $s \times s$. Let $d_2=\max(d,\sqrt{m}/s)$. Partition your box into subsquares of size $d_2 x d_2$; these will be used as bins. We will generate, say, $3m$ random points in the full box. Now place each in its appropriate bin. This can be done in $\mathcal{O}(m)$.

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, see if it is within distance $d$ of the candidate point and has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is $\mathcal{O}(1)$).

We stop once we have $m$ points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoof-print is $\mathcal{O}(d_2^2)$. The speed will typically be $\mathcal{O}(m)$ unless the sizes of $d$ and $s$ make it either difficult or impossible to have $m$ points inside with minimal separation of distance $d$.

Source Link
Daniel Lichtblau
  • 60.3k
  • 2
  • 105
  • 201

Here is an outline of a fairly efficient way to do this.

Say you want to generate m points, minimum separation of d, in a box of size s x s. Let d2=max(d,sqrt(m)/s). Consider a partition your box into subsquares of size d2 x d2; these will be used as bins. We will generate, say, 3m random points in the full box. Now place each in its appropriate bin. This can be done in O(m).

Now iterate over the generated points. For each, locate its bin, and gather all points in neighboring subsquare bins. For each such neighbor, (1) See if it is within distance d of the candidate point AND has already been chosen. If not, the candidate point is chosen as a member of our random set, and a down value is set to indicate this (so checking each neighbor is O(1)).

We stop once we have m points collected, or else run out of points. If the latter, generate more, add them to the existing binds, and proceed as before.

The memory hoofprint is O(d2^2). The speed will typically be O(m) unless the sizes of d and s make it either difficult or impossible to have m points inside with minimal separation of distance d.