Any time an event or attraction draws a crowd, individuals may continue to move into the most crowded areas and inadvertently obstruct egress, creating dangerously dense-packed locations vulnerable to stampedes. In addition to the motivation of avoiding danger, people may also want to avoid highly congested spots because the experience is unpleasant. Distributed sensing and computing can help solve this problem.

Using Protelis and the principles of aggregate programming, it is straightforward to write a scalable and robust distributed application to detect severe crowding and help individuals navigate around highly congested areas. We illustrate the use of several core Protelis operators and built-in functions.

Code samples and illustrations from a simulation:

Using some of Protelis’s special operators and syntax (purple), a small number of functions (blue) can be defined and applied to variables (green). A crowd safety service can use information about the number of nearby devices to issue warnings about areas with dangerous crowding levels.

The function dangerousDensity flags whether a location has a high or low danger. The function determines danger by estimating the local density of people, using the values of p (proportion of people with a participating device running this app), r (the radius of interest), and checking large groups of people (>300) against a density danger cut-off value of 2.17 people per square meter.

def dangerousDensity(p, r) {
  let mr =  managementRegions(r*2, () -> { nbrRange });
  let danger =  average(mr, densityEst(p, r)) > 2.17 && summarize(mr, sum, 1 / p, 0 ) > 300;
  if(danger) { high } else { low }
}

The function crowdTracking checks for a dangerous density in crowded areas, where 1.08 people per square meter is used as the cut-off to define crowded.

def crowdTracking(p, r, t) {
  let crowdRgn =  recentTrue(densityEst(p, r) > 1.08, t);
  if(crowdRgn) { densityEst(p, r) } else { none }
}

The function crowdWarning alerts individuals who are near dangerously crowded spots.

def crowdWarning(p, r, warn, t) {
  distanceTo(crowdTracking(p, r, t) == high) < warn
}

map with green, yellow, and red dots

In this simulation of the 2013 Vienna Marathon, dots represent devices running the crowd safety service. Red dots are devices in locations with potentially dangerous crowd density and yellow dots are devices providing crowd density warnings.

map with blue, yellow, and red dots

In this simulation of public events near the Boston waterfront, dots represent devices running the crowd safety service. Red dots are devices in locations with potentially dangerous crowd density and yellow dots are devices providing crowd density warnings.

This is an accelerated video showing a crowd dispersal application using the Alchemist simulator. Each black dot is a handheld device, following real movement traces from the 2013 Vienna City Marathon. Red dots are devices warned as being in dangerously crowded areas, and yellow dots are devices warned that they are nearing a dangerously crowded area. Blue dots represent people who follow the crowd dispersal application’s advice. More information about the application, its implementation, and its evaluation are available here.

For more information, see Aggregate Programming: From Foundations to Applications, Jacob Beal, Mirko Viroli, In: Bernardo M., De Nicola R., Hillston J. (eds) Formal Methods for the Quantitative Evaluation of Collective Adaptive Systems. SFM 2016. Lecture Notes in Computer Science, vol 9700. Springer, Cham