AnyLogic
Expand
Font size
All Implemented Interfaces:
AggregatableAnimationElement, DensityMapCustomColorProvider, HasLevel, LevelElement, LevelMarkup, SVGElement, UsdElement, Serializable

public class DensityMap
extends AbstractLevelMarkup
implements DensityMapCustomColorProvider
Markup element Density Map. Enables collecting statistics on the density of moving units in the simulated space and displaying this information on animation as a density map. This functionality is supported for pedestrians and transporters with free space navigation.

Having added the Density Map element, you enable showing the density map of the specified type (pedestrian or transporter) for your simulation model. If you have transporters and pedestrians moving on the same level and need to track the density for both, you have to add two Density Map elements: one per type. Note, that the density maps located on one level must be of different types, otherwise an error will occur.

You will see that as pedestrians or transporters 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. If you have transporters and pedestrians moving in the same area, the density maps won't display the aggregate density, only separate one for each type.

The element itself acts as the color legend for the density map. It displays the correspondence between density values and colors on the map.

Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Nested Class Summary

Modifier and TypeClassDescription
static interface DensityMap.DensityMapPreparationSettings 
static final record DensityMap.GridBasedDensityMapPreparationSettings 
static final record DensityMap.NetworkBasedDensityMapPreparationSettings 

Field Summary

Fields inherited from interface com.anylogic.engine.presentation.UsdElement

ID_NOT_SET

Constructor Summary

ConstructorDescription
DensityMap()
Creates markup object Density Map with default parameters.
DensityMap(Agent owner, ShapeDrawMode drawMode, boolean isPublic, double x, double y, double width, double height, double transparency, double criticalDensity, DensityMapDisplayedValue displayedValue, boolean slidingWindow, double windowTimeMTU, boolean enableAttenuation, DensityMapType type, DensityMapBasisType basisType, DensityMapColorScheme colorScheme)
Deprecated.
deprecated in version 8.4, will be removed in the future releases

Method Summary

Modifier and TypeMethodDescription
booleancontains(double px, double py)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e.
doublecurrentDensity(double x, double y)
Returns the current density value in the area neighboring the specified point, units/m2.
doublecurrentDensity(DensityMapCompatibleNetworkElement element)
Returns the current density value at the specified density map compatible network element.
doublecurrentDensity(Level level, double x, double y)
Returns the current density value in the area neighboring the specified point, units/m2.
doublecurrentDensity(Level level, DensityMapCompatibleNetworkElement element)
Returns the current density value at the specified density map compatible network element.
ColorcustomColor(double density)
This method should be overridden to return color in CUSTOM color scheme
voiddisplay(boolean flag)
Shows the density map if flag == true and hides otherwise.
voiddisplay(Level level, boolean flag)
Shows the density map on level if flag == true and hides otherwise.
DensityMapBasisTypegetCalculationBasis()
Returns the calculation basis of the density map.
ColorgetColor(double density)
Returns the color matching for the specified density value
ColorgetColor(double density, boolean reducePrecision)
Deprecated.
- A possibility to get non-reduced color is eliminated.
DensityMapColorSchemegetColorScheme()
Returns the color scheme of this density map
doublegetCriticalDensity()
Returns the critical density for the density map, in selected units / m^2.
DensityMapDataStoragegetDataStorage(Level level) 
DensityMapDisplayedValuegetDensityValue()
Returns the 'Displayed density value' parameter.
doublegetHeight()
Returns height of the density map legend
AgentgetOwner() 
doublegetSlidingWindow()
Returns sliding window time in model time units.
doublegetSlidingWindow(TimeUnits units)
Returns sliding window in specified time units.
doublegetTransparency()
Returns the density map transparency
DensityMapTypegetType()
Returns the type of density map.
doublegetWidth()
Returns width of the density map legend
doublegetX()
Returns x coordinate of the density map legend
doublegetY()
Returns y coordinate of the density map legend
voidhide()
Hides the density map.
voidhide(Level level)
Hides the density map on the specified level.
booleanisEnableAttenuation()
Returns true if the density map is shown with attenuation; returns false otherwise.
booleanisShown()
Returns whether the density map is shown.
booleanisShown(Level level)
Returns whether the density map is shown on the specified level.
booleanisTrackNetworkNodes()
Returns true if the network-based density map tracks network nodes, false otherwise.
booleanisTrackNetworkPaths()
Returns true if the network-based density map tracks network paths, false otherwise.
doublemaximumDensity(double x, double y)
Returns maximum observed density at the specified point
doublemaximumDensity(DensityMapCompatibleNetworkElement element)
Returns maximum observed density at the specified density map compatible network element
doublemaximumDensity(Level level, double x, double y)
Returns maximum observed density at the specified point
doublemaximumDensity(Level level, DensityMapCompatibleNetworkElement element)
Returns maximum observed density at the specified density map compatible network element
doublemeanDensity(double x, double y)
Returns mean density at the specified point
doublemeanDensity(DensityMapCompatibleNetworkElement element)
Returns mean density at the specified density map compatible network element
doublemeanDensity(Level level, double x, double y)
Returns mean density at the specified point
doublemeanDensity(Level level, DensityMapCompatibleNetworkElement element)
Returns mean density at the specified density map compatible network element
voidonDestroy() 
voidprepare(DensityMap.DensityMapPreparationSettings settings)
Prepares density map data storage and density map animator.
voidprepareGridBasedMap(Level level, double xUpperLeftPx, double yUpperLeftPx, int xCellCount, int yCellCount, double cellSizePx)
Prepares the density map for the space-based (grid-based) case.
voidprepareNetworkBasedMap(Level level, Set<DensityMapCompatibleNetwork> networks)
Prepares the density map for the network-based case.
voidreset()
Resets maximum density to current density
voidsetCalculationBasis(DensityMapBasisType type)
Sets the density map calculation basis.
voidsetColorScheme(DensityMapColorScheme colorScheme)
Defines the color scheme for density map.
voidsetCriticalDensity(double criticalDensity)
Sets the critical density for the density map, in selected units / m^2.
voidsetDensityValue(DensityMapDisplayedValue valueType)
Sets the 'Displayed density value' parameter.
voidsetEnableAttenuation(boolean enable)
Enables/disables attenuation for the density map.
voidsetHeight(double height)
Sets height of the density map legend
voidsetOwner(Agent owner)
Sets the owner of the markup element
voidsetSlidingWindow(double time)
Enables sliding window with specified time.
voidsetSlidingWindow(double time, TimeUnits units)
Enables sliding window with specified time.
voidsetTrackNetworkNodes(boolean track)
Sets network nodes tracking for the network-based density map.
voidsetTrackNetworkPaths(boolean track)
Sets network paths tracking for the network-based density map.
voidsetTransparency(double transparency)
Set the density map transparency.
voidsetType(DensityMapType type)
Sets the density map type.
voidsetWidth(double width)
Sets width of the density map legend
voidsetX(double x)
Sets x coordinate of the density map legend
voidsetY(double y)
Sets y coordinate of the density map legend
voidshow()
Shows the density map.
voidshow(Level level)
Shows the density map on the specified level.

Methods inherited from class com.anylogic.engine.markup.AbstractLevelMarkup

getDrawMode, getLevel, setLevel

Methods inherited from class com.anylogic.engine.markup.MarkupShape

error, getFullName, getOutsideLevelZ, getPresentable, getSpace, initialize, isClickHandled, isOnly3D, isPublic, onClick, remove, setDrawMode

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, onAggregatorVisibilityChanged, postInitialize

Constructor Details

DensityMap

public DensityMap()
Creates markup object Density Map with default parameters. After creation the map should be added to Level (see Level.add(LevelMarkup))

DensityMap

@Deprecated
public DensityMap(Agent owner,
 ShapeDrawMode drawMode,
 boolean isPublic,
 double x,
 double y,
 double width,
 double height,
 double transparency,
 double criticalDensity,
 DensityMapDisplayedValue displayedValue,
 boolean slidingWindow,
 double windowTimeMTU,
 boolean enableAttenuation,
 DensityMapType type,
 DensityMapBasisType basisType,
 DensityMapColorScheme colorScheme)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Parameters:
owner -
drawMode -
isPublic -
x -
y -
width -
height -
transparency -
criticalDensity -
enableAttenuation -
colorScheme -

Method Details

setOwner

public void setOwner(Agent owner)
Description copied from class: MarkupShape
Sets the owner of the markup element
Overrides:
setOwner in class MarkupShape
Parameters:
owner - new owner

reset

public void reset()
Resets maximum density to current density

getX

public double getX()
Returns x coordinate of the density map legend
Returns:
x coordinate of the density map legend

setX

public void setX(double x)
Sets x coordinate of the density map legend
Parameters:
x - - x coordinate of the density map legend

getY

public double getY()
Returns y coordinate of the density map legend
Returns:
y coordinate of the density map legend

setY

public void setY(double y)
Sets y coordinate of the density map legend
Parameters:
y - - y coordinate of the density map legend

getWidth

public double getWidth()
Returns width of the density map legend
Returns:
width of the density map legend

setWidth

public void setWidth(double width)
Sets width of the density map legend
Parameters:
width - - width of the density map legend

getHeight

public double getHeight()
Returns height of the density map legend
Returns:
height of the density map legend

setHeight

public void setHeight(double height)
Sets height of the density map legend
Parameters:
height - - height of the density map legend

getTransparency

public double getTransparency()
Returns the density map transparency
Returns:
the density map transparency

getType

public DensityMapType getType()
Returns the type of density map. Possible values are:
  • DensityMapType.PEDESTRIAN
  • DensityMapType.TRANSPORTER
  • DensityMapType.CONVEYOR
  • DensityMapType.RAILROAD
Returns:
the type of density map

setType

public void setType(DensityMapType type)
Sets the density map type. May be called only before initialization of the density map.
Parameters:
type - - type of density map. Possible values are:
  • DensityMapType.PEDESTRIAN
  • DensityMapType.TRANSPORTER
  • DensityMapType.CONVEYOR
  • DensityMapType.RAILROAD

getCalculationBasis

public DensityMapBasisType getCalculationBasis()
Returns the calculation basis of the density map. Possible values are:
Returns:
the calculation basis of the density map

setCalculationBasis

public void setCalculationBasis(DensityMapBasisType type)
Sets the density map calculation basis. May be called only before initialization of the density map.
Parameters:
type - - calculation of density map. Possible values are:

setTransparency

public void setTransparency(double transparency)
Set the density map transparency. (The value should be in the range [0, 1], 0 means fully transparent, 1 means fully opaque)
Parameters:
transparency - - defines the transparency of the density map

getCriticalDensity

public double getCriticalDensity()
Returns the critical density for the density map, in selected units / m^2.
Returns:
the critical density for the density map

setCriticalDensity

public void setCriticalDensity(double criticalDensity)
Sets the critical density for the density map, in selected units / m^2. When the density reaches the critical value, the corresponding area on animation is shown in red.
Parameters:
criticalDensity - - critical density for the density map

setSlidingWindow

public void setSlidingWindow(double time)
Enables sliding window with specified time. Owner should be set, otherwise an error will occur. Sliding window may be enabled only before initialization.
Parameters:
time - - time in model time units

setSlidingWindow

public void setSlidingWindow(double time,
 TimeUnits units)
Enables sliding window with specified time. Sliding window may be enabled only before initialization.
Parameters:
time - - time in model time units
units - - time units

getSlidingWindow

public double getSlidingWindow()
Returns sliding window time in model time units. Owner should be set, otherwise an error will occur.
Returns:
sliding window time in model time units

getSlidingWindow

public double getSlidingWindow(TimeUnits units)
Returns sliding window in specified time units.
Parameters:
units - - time units
Returns:
sliding window in specified time units.

getDensityValue

public DensityMapDisplayedValue getDensityValue()
Returns the 'Displayed density value' parameter. The parameter specifies what value is displayed on the map. Possible values are:
  • DENSITY_VALUE_MEAN
  • DENSITY_VALUE_MAX
Returns:
the 'Displayed density value' parameter

setDensityValue

public void setDensityValue(DensityMapDisplayedValue valueType)
Sets the 'Displayed density value' parameter. Possible values are:
  • DENSITY_VALUE_MEAN
  • DENSITY_VALUE_MAX
Parameters:
valueType - a constant defining density value type

isEnableAttenuation

public boolean isEnableAttenuation()
Returns true if the density map is shown with attenuation; returns false otherwise.
Returns:
true if the density map is shown with attenuation; returns false otherwise.

setEnableAttenuation

public void setEnableAttenuation(boolean enable)
Enables/disables attenuation for the density map.
Parameters:
enable -

isTrackNetworkNodes

@AnyLogicInternalLibraryAPI
public boolean isTrackNetworkNodes()
Returns true if the network-based density map tracks network nodes, false otherwise.
Returns:
true if the network-based density map tracks network nodes, false otherwise.

setTrackNetworkNodes

@AnyLogicInternalLibraryAPI
public void setTrackNetworkNodes(boolean track)
Sets network nodes tracking for the network-based density map.
Parameters:
track -

isTrackNetworkPaths

@AnyLogicInternalLibraryAPI
public boolean isTrackNetworkPaths()
Returns true if the network-based density map tracks network paths, false otherwise.
Returns:
true if the network-based density map tracks network paths, false otherwise.

setTrackNetworkPaths

@AnyLogicInternalLibraryAPI
public void setTrackNetworkPaths(boolean track)
Sets network paths tracking for the network-based density map.
Parameters:
track -

getColorScheme

public DensityMapColorScheme getColorScheme()
Returns the color scheme of this density map
Returns:
the color scheme of this density map

setColorScheme

public void setColorScheme(DensityMapColorScheme colorScheme)
Defines the color scheme for density map. Valid values:
  • LINEAR_COLOR_SCHEME - Linear density-color dependency.
  • LOGARITHMIC_COLOR_SCHEME - Logarithmic density-color dependency.
  • CUSTOM_COLOR_SCHEME - Custom color scheme, defined in getCustomColor dynamic parameter.
Parameters:
colorScheme - - the color scheme for density map

customColor

@AnyLogicInternalCodegenAPI
public Color customColor(double density)
This method should be overridden to return color in CUSTOM color scheme
Specified by:
customColor in interface DensityMapCustomColorProvider

show

public void show()
Shows the density map.

show

public void show(Level level)
Shows the density map on the specified level.
Parameters:
level - - the level to show

hide

public void hide()
Hides the density map.

hide

public void hide(Level level)
Hides the density map on the specified level.
Parameters:
level - - the level to hide

isShown

public boolean isShown()
Returns whether the density map is shown.
Returns:
true if shown, false otherwise

isShown

public boolean isShown(Level level)
Returns whether the density map is shown on the specified level.
Parameters:
level - - the level to check
Returns:
true if shown, false otherwise

display

@AnyLogicInternalAPI
public void display(boolean flag)
Shows the density map if flag == true and hides otherwise.
Parameters:
flag - - defines visibility for density map

display

@AnyLogicInternalAPI
public void display(Level level,
 boolean flag)
Shows the density map on level if flag == true and hides otherwise.
Parameters:
level - - the level on which to change visibility
flag - - defines visibility for density map

currentDensity

public double currentDensity(double x,
 double y)
Returns the current density value in the area neighboring the specified point, units/m2. The units here mean either pedestrians, transporters or trains, depending on the density map type. 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
Returns:
density at the specified point

currentDensity

public double currentDensity(Level level,
 double x,
 double y)
Returns the current density value in the area neighboring the specified point, units/m2. The units here mean either pedestrians, transporters or trains, depending on the density map type. This value does not reflect exactly the current situation, it accumulates historic data.
Parameters:
level - - level where the point is located
x - - X coordinate of the point
y - - Y coordinate of the point
Returns:
density at the specified point

currentDensity

public double currentDensity(DensityMapCompatibleNetworkElement element)
Returns the current density value at the specified density map compatible network element. For network-based density maps, the value is calculated from the size of the agents relative to the size of the network element they occupy. This value does not reflect exactly the current situation, it accumulates historic data.
Parameters:
element - - density map compatible network element
Returns:
density at the specified density map compatible network element

currentDensity

public double currentDensity(Level level,
 DensityMapCompatibleNetworkElement element)
Returns the current density value at the specified density map compatible network element. For network-based density maps, the value is calculated from the size of the agents relative to the size of the network element they occupy. This value does not reflect exactly the current situation, it accumulates historic data.
Parameters:
level - - level where the element is located
element - - density map compatible network element
Returns:
density at the specified density map compatible network element
See Also:

maximumDensity

public double maximumDensity(double x,
 double y)
Returns maximum observed density at the specified point
Parameters:
x - - X coordinate of the point
y - - Y coordinate of the point
Returns:
maximum density at the specified point

maximumDensity

public double maximumDensity(Level level,
 double x,
 double y)
Returns maximum observed density at the specified point
Parameters:
level - - level where the point is located
x - - X coordinate of the point
y - - Y coordinate of the point
Returns:
maximum density at the specified point

maximumDensity

public double maximumDensity(DensityMapCompatibleNetworkElement element)
Returns maximum observed density at the specified density map compatible network element
Parameters:
element - - density map compatible network element
Returns:
maximum density at the specified point

maximumDensity

public double maximumDensity(Level level,
 DensityMapCompatibleNetworkElement element)
Returns maximum observed density at the specified density map compatible network element
Parameters:
level - - level where the element is located
element - - density map compatible network element
Returns:

meanDensity

public double meanDensity(double x,
 double y)
Returns mean density at the specified point
Parameters:
x - - X coordinate of the point
y - - Y coordinate of the point
Returns:
mean density at the specified point

meanDensity

public double meanDensity(Level level,
 double x,
 double y)
Returns mean density at the specified point
Parameters:
level - - level where the point is located
x - - X coordinate of the point
y - - Y coordinate of the point
Returns:
mean density at the specified point

meanDensity

public double meanDensity(DensityMapCompatibleNetworkElement element)
Returns mean density at the specified density map compatible network element
Parameters:
element - - density map compatible network element
Returns:
mean density at the specified density map compatible network element

meanDensity

public double meanDensity(Level level,
 DensityMapCompatibleNetworkElement element)
Returns mean density at the specified density map compatible network element
Parameters:
level - - level where the element is located
element - - density map compatible network element
Returns:
mean density at the specified density map compatible network element

onDestroy

@AnyLogicInternalCodegenAPI
public void onDestroy()

prepare

@AnyLogicInternalLibraryAPI
public void prepare(DensityMap.DensityMapPreparationSettings settings)
Prepares density map data storage and density map animator.
Parameters:
settings -

prepareGridBasedMap

@AnyLogicInternalLibraryAPI
public void prepareGridBasedMap(Level level,
 double xUpperLeftPx,
 double yUpperLeftPx,
 int xCellCount,
 int yCellCount,
 double cellSizePx)
Prepares the density map for the space-based (grid-based) case.
Parameters:
xUpperLeftPx -
yUpperLeftPx -
xCellCount -
yCellCount -
cellSizePx -
See Also:

prepareNetworkBasedMap

@AnyLogicInternalLibraryAPI
public void prepareNetworkBasedMap(Level level,
 Set<DensityMapCompatibleNetwork> networks)
Prepares the density map for the network-based case.
Parameters:
networks -
See Also:

getDataStorage

@AnyLogicInternalLibraryAPI
public DensityMapDataStorage getDataStorage(Level level)

contains

public boolean contains(double px,
 double py)
Description copied from class: MarkupShape
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y)
Specified by:
contains in class MarkupShape
Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
Returns:
true if the shape contains the point with the given coordinates

getColor

public Color getColor(double density)
Returns the color matching for the specified density value
Parameters:
density - density value
Returns:
the color of the specified density value

getColor

@AnyLogicInternalAPI
@Deprecated
public Color getColor(double density,
 boolean reducePrecision)
Deprecated.
- A possibility to get non-reduced color is eliminated. The method will be removed in future release, use getColor(double) instead.

getOwner

@AnyLogicInternalAPI
public Agent getOwner()