# An anticipatory interaction model for a crowd of pedestrians



 var WolframCDF = WolframCDF || new cdf_plugin(); WolframCDF.addCDFObject("CDF_5416d5649ac50450a915511833f563c04e48a6ac", "https://www.lucamoroni.it/wp-content/uploads/2015/02/PedestrianAnticipatoryModel.cdf", 800, 443); 

How to run a CDF Player simulation

## Overview

This is an interactive simulation that I created with the software Wolfram Mathematica, reproducing an anticipatory model for pedestrian interactions.
The demonstration can be interactively used with the free CDF Player (see here how to install it).

## The model

The model is based on the paper:

A universal power law governing pedestrian interactions
by Ioannis Karamouzas, Brian Skinner, and Stephen J. Guy
published on 2 December 2014 in Physical Review Letters

The article, together with some other interesting related material, is also available in the page  Applied Motion Lab, University of Minnesota.

There are also many informative articles (as this or this).

The main point of the model is that the interaction force between two pedestrian is not based on their distance (as it’d happen for, say, electrons) but rather on their time-to-collision, which is defined as “the duration of time for which two pedestrians could continue walking at their current velocities before colliding”.

So, in this model you won’t see nearby pedestrians repel each other if their trajectories are not such to produce a collision in the next few seconds. That makes possible for pedestrians to walk side by side as it happens in the real world.
On the other hand two pedestrians about to collide will try to change their motion (in velocity direction and/or speed).
See the original paper for further details.

## Usage

There are presently two environment models for the pedestrian interaction: the “courtyard” model and the “exit door” model.

In the courtyard model pedestrian are bound to move in a closed square environment. They will have initial random positions, velocities and speeds and will then move according to the rules detailed in the following controls section,  interacting with themselves and with the walls.
The main aim of this model is to explore the possible emergence of some syncing processes in the pedestrians motions.

In the exit door model pedestrian will try to make their way through a narrow exit door. They will move towards a target point following the rules specified in the following controls section.
In this model the pedestrian who manage to gain their exit are then re-created along the room walls with a random position and a random velocity direction.
The main aim of this model is to compare the effectiveness (exit rate) of different queueing strategies and to visualize the different cramming situations that can arise with different choices of the controls.

In both models the pedestrians tend to restore, after each interaction, their initial absolute speed.
In fact, since the pedestrian interaction force based on their time-to-collision parameter is not conservative, energy is not preserved and without a restoring speed force pedestrians would soon slow down and lose all their initial kinetic energy. The restoring speed force is then needed to keep the dynamics of the model alive.

Controls:
Hovering with the mouse on the labels of the controls should give (in the tool-tip) the essential information on the main meaning and usage of the control.

General controls:
dt: time step used in the integrator; higher values make the simulation run quicker but less precise.
initial speed variance: the interval for the initial speeds (randomly generated with a uniform distribution) will be  times this initial average speed.
walls damping coeff.: if this coefficient is set to 0 there will be no damping when the particles bounce against the walls, reproducing a pure elastic collision. Otherwise the damping coefficient will reduce the elastic bouncing behavior of the particles, creating potentially interesting clustering and synchronization effects.
anticipatory force strength: multiplicative coefficient for the strength of the anticipatory force in the pedestrian’s interactions.

Controls specific to the “courtyard” model:
free direction: particles will have no preferred direction, and move freely after each interaction.
initial (0) or xy (1) direction: coefficient to change (mix) the behavior from the initial velocity preferred direction (0) to horizontal/vertical preferred direction (1). In the first case, to allow for a “natural” bouncing, the preferred direction angles for the velocity vector at time t will be , where  is the initial vector angle.

Controls specific to the “exit door” model:
british queuing: coefficient to shift back the target points of each particle (according to their position) from the exit door in order to form a more ordered queue line in the british style. After entering the “ideal” queue line the particles will move towards the exit door.

Indicators:
energy: since the pedestrian interaction force is not conservative, energy is not preserved and particles would then slow down and lose all their initial kinetic energy. To avoid this all the particles are given a “restoring speed” force and will then try to regain their initial absolute speeds after each interaction. The difference between the initial kinetic energy and the actual kinetic energy represents the energy currently absorbed in the interactions.
particle colors: red particles are the ones with higher initial (and preferential) speed. The other intermediate hues (from red to orange to yellow to green to azure to blue), represent particles with decreasing speeds. The blue particles are then the ones with lower speeds.
clusters: if this option is checked clusters will be shown as gray dotted circles where the line thickness/darkness is proportional to the cluster size. Clusters are calculated through Mathematica function FindClusters.
sync index (only shown in the “courtyard” model): it’s higher when the particles tend to circulate around the center of mass with the same rotation direction. It would be 100% if all the particles would circulate in the same clockwise (red) or counterclockwise (blue) rotation direction around the center of mass.
exits rate (only shown for the “exit door” model): number of exits/time. The time is calculated from the time of the first exit .

Notes:

Syncing process (in the courtyard model)

The syncing of the pedestrians stems from the fact that the anticipatory force doesn’t have almost any effect when people walk side by side but has its major effects, instead, in case of head-on prospective collisions. That means that groups of pedestrians with parallel velocities are more likely to form and establish.

The syncing process usually follows these steps:
1) in a first phase little groups with similar motion directions tend to form. Some of these grows bigger by enrolling other stray pedestrians.
2) it may then happen that 2 or 3 large main groups of pedestrians form, but with inhomogeneous motion directions. They will then fight an epic battle to make their kind of motion prevail and win.
3) The winners will then form a giant group of conforming pedestrians tending to rotate with a clockwise or counterclockwise homogeneous circular motion around the center of mass and the sync index will so reach the high value of 50% or more.

…but that’s not the end of the story…

Some rebels can separate from the main-stream crowd and join forces with some other stray cat. In the same time the crowding and bouncing against the corners of the courtyard by the giant group can jeopardize its previously established direction of motion and create some havoc. The sync index will then drop quickly until a new temporary equilibrium state is reached.
Even if rather unlikely it’s anyway possible that at some future distant time a full overthrowing succeeds (reversing the rotation direction) promoted by the combined action of some group of rebels and by the havoc spreading in the conforming giant group members, quarreling with themselves about the direction to take when crowding in a courtyard corner.

Queueing styles (in the exit door model)

With the British queueing style people who gets very close to the exit door but miss the entrance (i.e. because pushed away by other incoming pedestrians) try to re-enter the queue line in a  backward position. This create an interesting flow motion that recalls the ebb and eddies of fluid dynamics.
On the other hand, with a disordered queueing style, pedestrian tend to cram in front of the exit door and the ensuing higher level of interaction usually causes a lower throughput.
An unexpected feature that can be observed in this situation is the slow oscillation of the crowd cramming the exit door in the up-down direction, along the rightmost wall.

Credits
1) The main inspiration for this simulation was the book:

Steven Strogatz,  Sync – The Emerging Science of Spontaneous Order, Penguin Books, 2004

That’s one of the best scientific books I’ve read in the last years (and I can’t wait to start reading  Nonlinear Dynamics and Chaos by the same author, that’s already in my bookcase waiting list…).
If I remember well I also knew about the paper “A universal power law governing pedestrian interactions” by a twit from Steven.

2) The core of the Mathematica notebook form which this CDF simulation was extracted is a discrete integrator realized through a highly optimized compiled function.
Without that compiled function the dynamic would much more slower and practically useless (that’s is understandable considering that, say, for 80 particles there could be up to 802=6400 interactions, each to be re-calculated in every small time step).
The compiled integrator I’ve used is built upon a similar one included in a demonstration published in the Wolfram Demonstration Project (Approach of a System of Particles towards Thermal Equilibrium), contributed by Ulrich Mutze and Stephan Leibbrandt.
Thanks Ulrich and Stephan!

Author: Luca MoroniFebruary 2015