I started playing with NetLogo years back as a possible avenue for modeling housing markets. Ultimately, I decided that agent-based modeling, while a powerful analytic tool, was likely best suited to explore phenomena that interact in a closed system like a network.

I created the below model of classroom evacuation really as a teaching tool to help students understand the role of complexity in an otherwise mundane situation – like evacuating a classroom.

The model works as follows: Assuming a fire has begun in the classroom, ask the students sitting in the lecture hall to ‘get out of their seats’ and either evacuate the classroom based on a routine that minimizes their distance to the exit or by a routine that trades-off distance and time minimization.

You can play with the simulation here or read on below to find out how it works. Note that given the number of calculations it’s making, it may run a bit slow in the browser (turn the speed slider bar to three quarters to have it run faster).

To setup the model press “Setup”. Then, given the emergency, ask the students to “Get out of your seats”.

The first routine, ‘Evacuate on distance’ has the students calculate their (manhattan) distance to the exit and then move in that direction. They never deviate from this course, despite the traffic in front of them and despite the fact that ‘going around’ would be more efficient. You can see this effect in the image below.

This is clearly not a good representation of reality. In reality, people in this situation trade off their preference for minimizing distance with an additional preference for minimizing the time it takes to get out.

If the model is run again using the ‘Evacuate w/ distance and time’ option, the result is much more realistic. Here is the routine:

- Assign my ‘target’ to one of the two nodes at either end of my row that has the least wait time. Wait time is the mean accumulated number of turns that a student agent and its neighbors could not move.
- Move to an adjacent patch on my row with no other agent present and having the least distance to the ‘target’.
- Calculate wait time at each node.
- If I make it on to the aisles flanking the rows walk ‘downhill’ (to accumulate the least distance) to the exit.
- Repeat until everyone gets out.

Shades of blue are used to represent wait time.

You will notice that students waiting to exit the rows shuffle back and forth as the constantly changing wait times means they are constantly changing their target node.

The distance/time routine is not only more realistic but it’s more efficient as well (see the ‘tick’ counter). This is the case even over several hundred model iterations as seen in the graph below:

In the end, the dynamics of evacuation are exceptionally difficult to model. It really comes down to the following question:

“What is the probability that an alternate route might get me out quicker even if I accrue more distance in the process?”

This is such a complex problem given so many possible alternative routes at any given moment, and that the efficiency of any given route is ever-changing.