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

public class DensityMap
extends AbstractLevelMarkup
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

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, 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.
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.
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() 
DensityMapDisplayedValuegetDensityValue()
Returns the 'Displayed density value' parameter.
doublegetHeight()
Returns height of the density map legend
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.
booleanisEnableAttenuation()
Returns true if the density map is shown with attenuation; returns false otherwise.
doublemaximumDensity(double x, double y)
Returns maximum observed density at the specified point
doublemeanDensity(double x, double y)
Returns mean density at the specified point
voidonDestroy() 
voidprepareGridBasedMap(double xUpperLeftPx, double yUpperLeftPx, int xCellCount, int yCellCount, double cellSizePx) 
voidreset()
Resets maximum density to current density
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.
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.

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, 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,
 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
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

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.

setEnableAttenuation

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

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

show

public void show()
Shows the density map.

hide

public void hide()
Hides the density map.

display

public void display(boolean flag)
Shows the density map if flag == true and hides otherwise.
Parameters:
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 or transporters, 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

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

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

onDestroy

@AnyLogicInternalCodegenAPI
public void onDestroy()

prepareGridBasedMap

@AnyLogicInternalLibraryAPI
public void prepareGridBasedMap(double xUpperLeftPx,
 double yUpperLeftPx,
 int xCellCount,
 int yCellCount,
 double cellSizePx)

getDataStorage

@AnyLogicInternalLibraryAPI
public DensityMapDataStorage getDataStorage()

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.