This program simulates greedy cleaners (also known as a greedy walk) on a plane, which can be described as so:
- Scatter points of 'dust' on
$\mathbb{R}^2$ according to a Poisson process (the parameter$\lambda > 0$ is unimportant, soplane-cleaners
picks 1 for efficiency). - Create
$n$ 'cleaners' at the origin, with corresponding exponentially distributed timers with parameter 1. - Whenever a timer goes off, the corresponding cleaner jumps to the nearest dust particle, and ereases it. The timer for this cleaner is then reset.
plane-cleaners
allows you to watch the behaviour of these cleaners in their space in real time.
These pictures are generated by hitting p
when the program is running:
A small region of 4 cleaners, 220233828 iters:
plane-cleaners
will use all the resources it can to run the simulation. This means it will gobble RAM
and hammer your CPUs as much as it needs to run as fast as possible, which could result in system crashes.
If your computer is struggling with running it, try pressing f
, which will stop the program from generating or checking any chunks it doesn't explicitly need to.
Simulating the whole of
The distribution of points in disjoint
$A_i \subset \mathbb{R}^n$ is independent. Furthermore, the number of points in$A_i$ is distributed according to a Poisson distribution with rate equal to$\lambda$ multiplied by the Lebesgue measure of$A_i$ , and each point in$A_i$ is uniformly distributed.
We can therefore reduce chunks
in the code, and are dynamically
generated and saved.
plane-cleaners
actually generates a backlog of chunks in parallel, and translates them into place when a new chunk is needed.
Let:
-
$S$ be the chunk side width -
$c$ be a point in some chunk with centre$C$
We can then find the nearest dust particle to
- If
$i > b$ , return$c'$ . - Take the
$L_\infty$ -circle of chunks with radius$i \times S$ , and try to find the closest dust particle in it. - If there are none, skip to the next iteration.
- Set
$c'$ to this closest point (if it is closer than the old value of$c'$ ). - Set
$b = \frac{d_\infty(c, C) + d_2(c, c')}{S} + \frac{1}{2}$ .
The bound can be justified like so, with
$d_\infty(C, C_f)$
By the triangle inequality, we have:
$\leq d_\infty(C, c) + d_\infty(c, c_f) + d_\infty(c_f, C_f)$
By the fact that
$\leq d_\infty(C, c) + d_2(c, c_f) + \frac{S}{2}$
Finally, since
$\leq d_\infty(C, c) + d_2(c, c') + \frac{S}{2}$
Dividing through by
This algorithm allows us to find the closest point without having to generate the entire plane, and thus making this problem computable.
This is a part of my University of Liverpool MATH490 project, supervised by Prof. Takis Konstantopoulos. All the code is mine, with the exception of a few lines of code taken from the SDL2 example sources to get the graphics working, and the PCG code in the pcg-cpp git submodule, but it would not have been possible without the detailed mathematical explanations provided by my supervisor.