# Street Collisions

Disclaimer: Here be Maths.

So tonight, whilst walking home from University, I came across some people who walking directly across my path. If we both continued on our intended paths we were going to collide. Thus I swung slightly to the right to walk behind these people, but alas, they had the same plan and also tried turn left to walk behind me. End result? We both stumbled around in the “which way should I move now” dance before we could continue upon our way.

I thought that this was kind of interesting in that both of us had attempted to be considerate to the other pedestrian, but instead we had actually just caused another collision. If either one of us had decided to keep walking, we would have happily continued on our way with barely a passing note.

On the train home I began to think about this problem and weather I was actually doing the right thing by trying to “be nice” and change my direction to avoid the other person. It’s interesting to note that this is just the same as if two people are walking directly towards each other down the street. If both people decide to take the same action (both turn left, both turn right or both continue straight ahead) a collision will take place (for the purposes of this discussion, flailing around trying to get past each other can be considered a “collision”). Any other combination will lead to unimpeded progress.

Lets define this a bit more formally:

Each person can take an action, where `action ∊ {L, R, S}` (Left, Right and Straight respectively). Lets also consider two classes of people. We have the PigHeaded folk who always charge straight ahead (`pigheaded = {L: 0.0, R:0.0, S:1.0}`) and Considerate folk who try and walk around the other person (for the time being lets just say `considerate = {L: 0.5, R:0.5, S:0.0}`).

Now lets consider the change of a crash given that we (Person 1) are Considerate. Since we’ll always try and walk around, we can never run into a PigHeaded person, so the only way we can collide is if another considerate person turns the same way us us. Thus:

`Pr(Crash|Considerate_1) = Pr(Considerate_2)×0.5 = Pr(¬PigHeaded_2)×0.5`

We can apply similar reasoning to work out what the probability of a crash is if we are PigHeaded instead. PigHeaded people will never collide into considerate people, but will always collide with other PigHeaded folk. Thus:

`Pr(Crash|PigHeaded_1) = Pr(PigHeaded_2)`

We can then combine these two together to work out what the overall probability of a crash is:

``Pr(Crash) = Pr(PigHeaded_1)×Pr(Crash|PigHeaded_1) + Pr(¬PigHeaded_2)×Pr(Crash|Considerate_1)          = Pr(PigHeaded_1)×Pr(PigHeaded_2) + Pr(¬PigHeaded_2)×Pr(¬PigHeaded_2)×0.5``

If we say that `p = Pr(PigHeaded)` then with a bit of maths this becomes:

``Pr(Crash) = p×p + (1-p)×(1-p)×0.5          = p^2 + 0.5p^2 - p + 0.5          = 1.5p^2 - p + 0.5``

Plotting this we get a nice quadratic showing that if everyone was Considerate (p=0.0) we still have a 1-in-4 chance of collision, but if everyone was PigHeaded (p=1.0) everyone would always crash into each other. Now the question is, can we do better?

Clearly the direction turned is not entirely random. Remember that I tried to walk behind the other person. That’s not a random choice. And consider if we were walking along a street with buildings on one side and open space on the other, it’s quite likely that you’d choose to turn towards the open space rather than into the small gap between the wall.

Remember our assumption that considerate people had a 50/50 probability of turning either way. Lets see what happens when replace this with a term representing the correlation between the direction chosen between considerate walkers. If strongly positive correlated (`c = 1.0`) then the other considerate walker will always turn the same direction as me. If strongly negative correlated (`c = -1.0`) then they will turn the opposite direction. And if there is no correlation (`c = 0.0`) then they’re just turning at random.

Now if `c = 1.0` then we will always avoid crashing into considerate person, yet if `c = -1.0` we will always collide. Thus we can update our probability of a collision given we are considerate:
`Pr(Crash|Considerate_1) = Pr(Considerate_2)×0.5×(1-c) = Pr(¬PigHeaded_2)×0.5×(1-c)`
And updating our formula for the probability of any crash we get:

``Pr(Crash) = p×p + (1-p)×(1-p)×0.5          = p^2 + (p^2 - 2×p + 1)×0.5×(1-c)``

Now lets plot this again. Since we have two free variables it should technically be a surface, but since it’s rather uniform we can plot it just as a series of lines. The bottom line is `c = 1.0` whilst the top is `c = -1.0` with steps of 0.1: 