I have the following situation. There are M independent random walkers on the discrete domain 0, 1, ..., L. We do this for N identical domains. This results in a matrix X
where X[i, j]
is the position of walker i
on domain j
. To make a random step, I add an identically shaped matrix with random +1 and -1's to matrix X
. Then I deal with the edges. This works well.
However, I want to extend this model to have solid particles that can't pass through each other. This is shown in 2 cases.
- One particle is at position
i
, the second is at positioni+1
. The first particle moves to the right, while the second moves to the left. - One particle is at position
i
, the second is at positioni+2
. The first particle moves to the right, while the second particle moves to the left.
If I do all steps independently, I can check each step manually to see if it's a legal step. However, this is bad O(M^2N)
performance. Is there a more efficient way to detect which matrix element pairs X[i,j], X[k, j]
result in two particles passing through each other, preferably in a vectorized way? In this way, I can make the simulation skip these steps.
I guess you have to use some form of loops to achieve this, but maybe this helps: