Evacuation simulation using Cellular Automata (part 2)

Fernando Tenório de Miranda Filho
Semantix
Published in
3 min readDec 20, 2021

--

Photo by Fredrick Tendong on Unsplash

Pygame to the rescue

In part 1 of our post we defined the CARoom class that enables us to run the simulation. In this post, we start by visualizing it with the help of pygame. In order to do that, we create a CustomRoom.py file with the following:

This class defines a simple 20m x 20m (50 x 50 cells) room with 3 obstacles: 2 large squared blocks and a narrow central wall. In the experiments we are going to use the parameters available in the make_2_obstacle_room function. Now create a file CAPanel.py with our visualization:

Now you should be able to execute:

python3 CAPanel.py

Our little tool should pop-up running at 60 FPS (which you can adjust by setting the FPS variable in the main function).

Now, to the experiments!

Defining the experiments

Since there are so many things we can change, there are many different types of experiments we can make. We could, for example, change the layout of the room by adding more obstacles or more exits. Or we could keep the same obstacles and change the exits size or location. We can also control how full the room is and the panic probability. Try to experiment and answer your own questions.

In order to keep this post short, lets try to investigate how the full factor, mean evacuation time and exit size relate to each other. The full factor parameter represents how much of the room is filled with people. Of course, we expect to see a decrease in the mean evacuation time as we lower the full factor and make the exits larger, but how exactly does this happen? Lets try to find out. Here is the Experiment.py code:

The code uses the multiprocessing module to speed up things. We simply define a grid of parameters and span a process to run each simulation 30 times. We log the parameters and results to the console, so we can easily capture it. Now lets get some data, so run

python3 Experiment.py > simulation.txt

and go make a coffee. You can set the reps parameter to a lower value, or make a smaller grid, it’s up to you. For this experiment, our data looks like:

We see what we expected: the larger the exit, the faster the evacuation, and this is true across all full factors. We can also see that the effect of adding a larger exit is non-linear, making more impact as we increase it from 1 to 2. Another conclusion, this one not so obvious, is that for crowded rooms (high er full factor), the effect of a larger exit is more intense, which we can see comparing the slopes from 1 to 2 across all curves. Also, for crowded rooms, the curve flattens out slower, which means that larger exits are more important to be considered when the room is expected to be full or almost full of people.

So, this ends this post, and I hope you have learned something new! Remember to make your own experiments and adjustments to the code, see you later!

--

--