Pedestrian Density Map

AnyLogic enables collecting statistics on the pedestrians density in the simulated space and displaying this information on animation as a density map. 

Having added the Pedestrian Density Map element, you enable showing the pedestrian density map for your pedestrian simulation model. 

You will see that as pedestrians move in the simulated space, the layout is gradually painted in different colors. The color of every point of the space corresponds to the current density in this particular area. The density map is constantly repainted according to the actual values: when the density changes in some point, the color changes dynamically to reflect this change. In case of zero density the area is not painted at all.

The element itself acts as the color legend for the pedestrian density map. It displays the correspondence between density values and colors on the map (see the right side on the figure below).


Red color indicates the critical density (by default it is equal to 1.5 pedestrians/m2). Blue color is used for low densities. When the density in some area is zero, the density map for this particular area is not drawn at all. 

The legend shown in the figure above tells us e.g. that yellow color on the map corresponds to the density 0.75 pedestrians/m2.  

You can change the logarithmic color scheme to linear, or some custom scheme, switch attenuation on/off, etc.

To add the density map

  1. Drag the element Pedestrian Density Map from the section Space Markup of  Pedestrian Library palette into the graphical editor. At the runtime it will show the density map legend. This density map legend helps to understand what colors on the density map mean what values. Legend displays the correspondence between density values and colors on the density map. 

  1. Now you can configure the properties of the density map as you need. Go to the properties of this element. Density map may either display maximum observed density values (if attenuation is turned off), or the actual density map for the recent period of time (if attenuation is turned on). With the attenuation being turned on, when the density goes down, the color for the corresponding zone on the density map changes correspondingly (but not immediately, with the specified delay). To turn the attenuation on, select the checkbox Enable attenuation.
  2. If you are not satisfied with the density map painted over the layout and making it hardly visible, you may increase the transparency level for the density map using the slider Transparency
  3. The density map is commonly used to detect the areas with critical densities. At the model runtime the areas with the density values equal or greater than the critical density threshold are painted with red color (if some other colors are not set using the Custom Color scheme). By default the critical density value is 1.5 pedestrians/m2. You can change this value in the parameter Critical density (shown in red), peds/m2.
  4. By default AnyLogic uses logarithmic color scheme. In this case the color changes logarithmically from the "minimum" (blue) color to the "maximum" (red) color. This color scheme is frequently used when you need to pay attention only to the density values close to the critical value threshold. You can change the logarithmic color scheme to the linear scheme by choosing Linear option of the parameter Color scheme. It is the simplest color scheme: color changes linearly from the "minimum" color to the "maximum" (red) color. You can even define your own color scheme by choosing the Custom Color scheme, see the properties description below.

Demo model: Pedestrian Density Map

Properties

General

Name – The name of the shape. The name is used to identify and access the shape from code.

Ignore – If selected, the shape is excluded from the model.

Visible on upper level – If selected, the shape is also visible on the upper level where this agent lives.

Lock – If selected, the shape is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them. 

Visible – Here you specify whether the shape is visible on the animation at the model runtime, or not. Using the control, choose yes or no

Ground – Here you should specify the name of the ground where pedestrians move. This Pedestrian Density Map will display the density map for this particular ground.

Enable attenuation - If the checkbox is selected, the density map will be shown with attenuation. In this case the actual density map for the recent period of time will be shown, not the maximum observed densities. When the density goes down, the color for the corresponding zone on the density map changes correspondingly (but not immediately, with the specified delay).

Transparency - Here you can define the transparency level for the density map. Using the slider, choose the value from the range [0..100%]. 100% means fully transparent map (the density map is not visible), 0% means fully opaque density map (the animation underneath the density map is not visible at all).

Critical density - Here you specify the critical density value. All areas with the density values equal or greater than the critical density threshold will be painted on the animation with red (if some other colors are not set using the Custom Color scheme).

Color scheme - Here you can choose the color scheme for the density map. There are three alternative options available:
Logarithmic - The color will change logarithmically from the "minimum" (blue) color to the "maximum" (red) color. This color scheme is frequently used when you need to pay attention only to the density values close to the critical value threshold. 
Linear - The simplest color scheme: color will change linearly from the "minimum" (blue) color to the "maximum" (red) color. 
Custom - You can define your own color scheme and define the correspondence between colors and density values in the Custom color field below.

Custom color - [Visible if Color scheme is set to Custom] If you want to define some custom color scheme for the density map, here you should specify the expression that will return different colors depending on the density value (you can obtain the density value using the local variable density).
You can see the example of such an expression set up as the default value:
density > self.criticalDensity * 0.7 ? red : transparent

It defines that red color will be used for the densities that are higher than the specified threshold value (70% of the critical density value). For the lower densities, the density map will not be drawn at all.

Position and size

X – X-coordinate of the density map legend.

Y – Y-coordinate of the density map legend.

Width – Width of the density map legend (in pixels).

Height – Height of the density map legend (in pixels).

Advanced

Show in - Here you can choose whether you want the density map legend to be shown both In 2D and 3D animation, or in 2D only, or in 3D only.

Show name – If selected, the shape's name is displayed on a presentation diagram.

Functions

Pedestrian density

Function

Description

double
currentDensity(double x, double y)

Returns the current density value in the area neighboring the specified point, pedestrians/m². This value does not reflect exactly the current situation, it accumulates historic data. 

Parameters:  x - X-coordinate of the point
                        y - Y-coordinate of the point

double 
maximumDensity(double x, double y)

Returns the maximum density value in the specified point, pedestrians/m².

Parameters:  x - X-coordinate of the point
                        y - Y-coordinate of the point


Color scheme

Function

Description

DensityMapColorScheme getColorScheme()

Returns the color scheme of the density map.

Possible values: LINEAR_COLOR_SCHEMELOGARITHMIC_COLOR_SCHEME, CUSTOM_COLOR_SCHEME

void setColorScheme
(DensityMapColorScheme colorScheme)

Sets the new color scheme.

Parameter: colorScheme - the new color scheme. 
Possible values: LINEAR_COLOR_SCHEMELOGARITHMIC_COLOR_SCHEME, CUSTOM_COLOR_SCHEME

double getCriticalDensity()

Returns the critical density for the density map, in pedestrians / sq. meter.

void setCriticalDensity
(double criticalDensity)

Sets the new critical density for the density map, in pedestrians / sq. meter.

Parameter: criticalDensity - the new critical density value 


Attenuation and transparency

Function

Description

double getTransparency()

Returns the density map transparency. The value is in the range [0, 1], 0 means fully opaque, 1 means fully transparent.

void setTransparency
(double transparency)

Sets the new density map transparency.

Parameter: transparency -  the new transparency value. The value should be in the range [0, 1], 0 means fully opaque, 1 means fully transparent.

boolean isEnableAttenuation()

Returns true if the density map is shown with atenuation; returns false otherwise.

void setEnableAttenuation
(boolean enable)

Turns density map attenuation on/off.

Parameter: enable - attenuation. If enable is true - the density map is shown with atenuation, if it is false - attenuation is turned off.


Visibility

Function

Description

void show()

Shows the density map.

void hide()

Hides the density map.

boolean isVisible()

Returns true if the density map legend is visible; returns false otherwise.

void setVisible(boolean v)

Sets the visibility of the density map legend.

Parameter: v - visibility. If v is true - the density map legend is set to be visible, if it is false - not visible.


Ground

Function

Description

Ground getGround()

Returns the ground, for which this element shows the density map.


Legend position

Function

Description

double getX()

Returns the X-coordinate of the density map legend.

double getY()

Returns the Y-coordinate of the density map legend.

void setX(double x)

Sets the X-coordinate of the density map legend.

Parameter: x - new X-coordinate

void setY(double y)

Sets the Y-coordinate of the density map legend.

Parameter: y - new Y-coordinate


Legend size

Function

Description

double getWidth()

Returns the width of the density map legend (in pixels).

double getHeight()

Returns the height of the density map legend (in pixels). 

void setWidth (double width)

Sets the width of the density map legend (in pixels).

Parameter: width - the new width

void setHeight (double height)

Sets the height of the density map legend (in pixels).

Parameter: height - the new height



Related topics

Markup for pedestrian simulation

 Pedestrian flow statistics

 API reference: DensityMap class