Problem 2700. Simulate one complete step in the Biham–Middleton–Levine traffic model

The Biham–Middleton–Levine traffic model is a simple cellular automata model loosely mimicking traffic flow. In an m-by-n domain, we see white empty space (or 0 in our matrix representation), red cars (1 in the matrix), and blue cars (2 in the matrix).
Assume the space is toroidal. That is to say, the right side connects with the left, and the top connects to the bottom. So a red car that moves off the far right of the matrix re-appears on the far left.
Here is a 4-by-4 version with three red cars and two blue cars.
0 0 0 2
1 1 0 0
0 0 2 0
0 0 0 1
Red cars always move to the right if they are unblocked. A red car can move either into an empty space or a space being vacated by a moving red car.
After we move the red cars (1s) we will have this matrix.
0 0 0 2
0 1 1 0
0 0 2 0
1 0 0 0
We're only halfway through the process. After we move the blue cars (2s) we end up here.
0 0 0 0
0 1 1 2
0 0 0 0
1 0 2 0
This last value of the matrix would be the return value of your function. Assume that red cars always move before blue cars.
For some visualizations of Biham–Middleton–Levine traffic, see this very nice simulation site.

Solution Stats

34.15% Correct | 65.85% Incorrect
Last Solution submitted on Feb 27, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers30

Suggested Problems

More from this Author50

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!