AnyLogic AnyLogic
Expand
Font size
All Implemented Interfaces:
AggregatableAnimationElement, HasLevel, SVGElement, java.io.Serializable

public class Road
extends AbstractRoadConnectableElement
Class representing a road segment with several forward and backward lanes. Road segment should have at least 1 forward or backward lane. Road segment can have a median strip of the specified width that separates forward and backward directions. Road segment has incoming and outgoing connection points at ends. Each lane has 1 incoming connection point, 1 outgoing connection point and a guideline connecting them. Lanes of each direction are numbered starting from 0 from outmost to inmost, so the lane closest to the central line has the greatest index.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Field Summary

Fields 
static float[] DOUBLE_DASH  
static float[] SINGLE_DASH  
Modifier and Type Field Description

Constructor Summary

Constructors 
Road()
Creates a new road segments.
Road​(Agent owner, ShapeDrawMode drawMode, boolean isPublic, int forwardLanesCount, int backwardLanesCount, double medianStripWidthInMeters, java.awt.Paint medianStripColor, MarkupSegment... axisSegments)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods 
void addSegment​(MarkupSegment segment)
Adds segment to this markup element
double averageSpeed​(boolean isOnForwardSide, double offset)
Returns the average speed (in meters per second) on the given road direction near the specified offset
double averageSpeed​(boolean isOnForwardSide, double offset, SpeedUnits units)
Returns the average speed (in the given units) on the given road direction near the specified offset
java.util.List<MarkupSegment> getAxisMarkupSegments()
Returns list of markup segments representing road axis (the middle of median strip).
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
RoadConnectionPoint getBackwardIncomingConnectionPoint​(int backwardLaneIndex)
Returns incoming connection point located at the beginning of backward lane with the specified index.
java.util.List<MarkupSegment> getBackwardLaneMarkupSegments​(int backwardLaneIndex)
Returns list of markup segments representing guideline of backward lane with the specified lane index.
int getBackwardLanesCount()
Returns count of backward lanes.
RoadConnectionPoint getBackwardOutgoingConnectionPoint​(int backwardLaneIndex)
Returns outgoing connection point located at the end of backward lane with the specified index.
java.util.List<RoadConnectionPoint> getBeginConnectionPoints()
Returns list of all connection points located at the beginning of road segment.
BoundingRectangle getBoundingRectangle()  
java.util.List<BusStop> getBusStops()
Returns all bus stops contained in this road
java.util.List<Agent> getCars​(boolean isOnForwardSide)
Returns ordered list of cars located on the given direction.
java.util.List<RoadConnectionPoint> getConnectionPoints()
Returns a list of connection points of the road element.
java.util.List<RoadConnectionPoint> getEndConnectionPoints()
Returns list of all connection points located at end of road segment.
RoadConnectionPoint getForwardIncomingConnectionPoint​(int forwardLaneIndex)
Returns incoming connection point located at the beginning of forward lane with the specified index.
java.util.List<MarkupSegment> getForwardLaneMarkupSegments​(int forwardLaneIndex)
Returns list of markup segments representing guideline of forward lane with the specified lane index.
int getForwardLanesCount()
Returns count of forward lanes.
RoadConnectionPoint getForwardOutgoingConnectionPoint​(int forwardLaneIndex)
Returns outgoing connection point located at the end of forward lane with the specified index.
java.util.List<RoadConnectionPoint> getIncomingConnectionPoints​(PathEndType type)
Returns list of incoming connection points located at the beginning of road segment.
int getLaneIndex​(RoadConnectionPoint connectionPoint)
Returns zero-based index of lane to which the specified connection point belongs to.
java.awt.Color getMedianStripColor()
Returns the color of the median strip, or null if median strip has no fill or has texture (in this case getMedianStripTexture() should be used instead)
Texture getMedianStripTexture()
Returns the texture of the median strip color, if the median strip has texture
double getMedianStripWidth()
Returns median strip width, in pixels.
double getMedianStripWidth​(LengthUnits units)
Returns median strip width measured in the given units.
java.util.List<RoadConnectionPoint> getOutgoingConnectionPoints​(PathEndType type)
Returns list of outgoing connection points located at the beginning of road segment.
java.util.List<ParkingLot> getParkingLots()
Returns all parking lots contained in this road
MarkupSegment getSegment​(int index)
Returns the segment by its index
int getSegmentCount()
Returns the number of segments
java.util.List<StopLine> getStopLines()
Returns all stop lines contained in this road
double getWidth()
Returns the total width of road segment which consists of width of all forward lanes, width of all backward lanes and width of median strip.
double getWidth​(LengthUnits units)
Returns the total width of road segment which consists of width of all forward lanes, width of all backward lanes and width of median strip.
boolean isConnectionPointOnForwardDirection​(RoadConnectionPoint connectionPoint)
Checks if the specified road connection point is located on forward direction of the road segment.
java.util.Iterator<MarkupSegment> iterator()
Creates and returns read-only iterator over segments
int nCars​(boolean isOnForwardSide)
Returns number of cars located on the given direction.
int nCarsOnLane​(boolean isOnForwardSide, int laneIndex)
Returns number of cars located on located in the specified lane.
void postInitialize()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void setBackwardLanesCount​(int backwardLanesCount)
Sets number of backward lanes
void setDataSource​(RoadDataSource dataSource)  
void setForwardLanesCount​(int forwardLanesCount)
Sets number of forward lanes
void setMedianStripColor​(java.awt.Color color)
Sets the color of the median strip color.
void setMedianStripColor​(java.awt.Paint color)
Sets the color (or Texture) of the median strip color.
void setMedianStripWidth​(double medianStripWidthInPixels)
Deprecated.
this method is deprecated and may be removed in the next release.
void setMedianStripWidth​(double medianStripWidth, LengthUnits units)
Sets median strip width measured in the given units
Modifier and Type Method Description

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

contains, getLevel, getRoadNetwork, setDebugInfoVisible, setRoadNetwork

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

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

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

discardOwner, executeUserAction, findSVGElement, getName, getSVGId, initializeInternal, isVisible, onAggregatorInitialized, onAggregatorVisibilityChanged, removeSVGFromOwner, resetSVGState, setVisible, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGProperties

Methods inherited from class java.lang.Object

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

Field Detail

DOUBLE_DASH

public static final float[] DOUBLE_DASH

SINGLE_DASH

public static final float[] SINGLE_DASH

Constructor Detail

Road

public Road()
Creates a new road segments.

Road

@Deprecated
public Road​(Agent owner,
            ShapeDrawMode drawMode,
            boolean isPublic,
            int forwardLanesCount,
            int backwardLanesCount,
            double medianStripWidthInMeters,
            java.awt.Paint medianStripColor,
            MarkupSegment... axisSegments)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Creates a new road segments along the specified path with specified count of forward and backward lanes and specified width of median strip between driving directions. Axis path specifies the middle line of delimiter. If the road network uses right-hand driving, all forward lanes will be created to the right of axis path and all backward lanes will be created to the left of the axis path. Vice versa for left-hand driving.
Parameters:
owner - Agent to which the created road intersection belongs to.
drawMode - Where to draw this space markup shape: 2D, 3D or 2D+3D.
ispublic - If true, the markup shape is visible on container's presentation.
forwardLanesCount - Count of forward lanes.
backwardLanesCount - Count of backward lanes.
medianStripWidthInMeters - Width of median strip in meters.
axisSegments - Path specifying the line delimiting driving directions.

Method Detail

setDataSource

@AnyLogicInternalAPI
public void setDataSource​(RoadDataSource dataSource)

averageSpeed

public double averageSpeed​(boolean isOnForwardSide,
                           double offset,
                           SpeedUnits units)
Returns the average speed (in the given units) on the given road direction near the specified offset
Parameters:
isOnForwardSide - true if direction is along road axis line, false otherwise
offset - offset from the beginning of road axis line
units - speed units
Returns:
average speed value

averageSpeed

public double averageSpeed​(boolean isOnForwardSide,
                           double offset)
Returns the average speed (in meters per second) on the given road direction near the specified offset
Parameters:
isOnForwardSide - true if direction is along road axis line, false otherwise
offset - offset from the beginning of road axis line
Returns:
average speed value, meters per second

nCars

public int nCars​(boolean isOnForwardSide)
Returns number of cars located on the given direction.
Parameters:
isOnForwardSide - true if direction is along road axis line, false otherwise
Returns:
number of cars

nCarsOnLane

public int nCarsOnLane​(boolean isOnForwardSide,
                       int laneIndex)
Returns number of cars located on located in the specified lane.
Parameters:
isOnForwardSide - true if direction is along road axis line, false otherwise
laneIndex - zero-based index of lane. Lanes are numbered from outmost (that has index 0) to inmost
Returns:
number of cars located in the specified lane

getCars

public java.util.List<Agent> getCars​(boolean isOnForwardSide)
Returns ordered list of cars located on the given direction. The first car in the list is the nearest one to the exit point from road (seems to be the first one to exit the road, if there is no acceleration)
Parameters:
isOnForwardSide - true if direction is along road axis line, false otherwise
Returns:
ordered list of cars

setForwardLanesCount

public void setForwardLanesCount​(int forwardLanesCount)
Sets number of forward lanes
Parameters:
forwardLanesCount -

setBackwardLanesCount

public void setBackwardLanesCount​(int backwardLanesCount)
Sets number of backward lanes
Parameters:
backwardLanesCount -

setMedianStripWidth

@Deprecated
public void setMedianStripWidth​(double medianStripWidthInPixels)
Deprecated.
this method is deprecated and may be removed in the next release. Please use method with units argument instead.
Sets median strip width
Parameters:
medianStripWidthInPixels - median strip width measured in pixels

setMedianStripWidth

public void setMedianStripWidth​(double medianStripWidth,
                                LengthUnits units)
Sets median strip width measured in the given units
Parameters:
medianStripWidth - median strip width
units - length units

addSegment

public void addSegment​(MarkupSegment segment)
Adds segment to this markup element
Parameters:
segment - the segment, should be initialized if was created using no-argument constructor

getSegmentCount

public int getSegmentCount()
Returns the number of segments
Returns:
the number of segments

getSegment

public MarkupSegment getSegment​(int index)
Returns the segment by its index
Parameters:
index - the segment index, [0 .. getSegmentCount() - 1]
Returns:
the segment

iterator

public java.util.Iterator<MarkupSegment> iterator()
Creates and returns read-only iterator over segments

postInitialize

@AnyLogicInternalAPI
public void postInitialize()
Description copied from interface: AggregatableAnimationElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
postInitialize in interface AggregatableAnimationElement

getWidth

public double getWidth()
Returns the total width of road segment which consists of width of all forward lanes, width of all backward lanes and width of median strip.
Returns:
Total width of road segment in pixels.

getWidth

public double getWidth​(LengthUnits units)
Returns the total width of road segment which consists of width of all forward lanes, width of all backward lanes and width of median strip.
Returns:
Total width of road segment, measured in the given units.

getIncomingConnectionPoints

@AnyLogicInternalLibraryAPI
public java.util.List<RoadConnectionPoint> getIncomingConnectionPoints​(PathEndType type)
Returns list of incoming connection points located at the beginning of road segment. Connection points are ordered the same way as lanes: from outmost to inmost.
Parameters:
type - one of RoadEnd.Type.BEGIN or RoadEnd.Type.END
Returns:
List of incoming connection points located at the beginning of road segment.

getOutgoingConnectionPoints

@AnyLogicInternalLibraryAPI
public java.util.List<RoadConnectionPoint> getOutgoingConnectionPoints​(PathEndType type)
Returns list of outgoing connection points located at the beginning of road segment. Connection points are ordered the same way as lanes: from outmost to inmost.
Parameters:
type - one of RoadEnd.Type.BEGIN or RoadEnd.Type.END
Returns:
List of outgoing connection points located at the beginning of road segment.

getBeginConnectionPoints

@AnyLogicInternalLibraryAPI
public java.util.List<RoadConnectionPoint> getBeginConnectionPoints()
Returns list of all connection points located at the beginning of road segment. Connection points are ordered in the following way: - First, outgoing connection points from outmost to inmost, - Second, incoming connection points from inmost to outmost.
Returns:
List of all connection points located at the beginning of road segment.

getEndConnectionPoints

@AnyLogicInternalLibraryAPI
public java.util.List<RoadConnectionPoint> getEndConnectionPoints()
Returns list of all connection points located at end of road segment. Connection points are ordered in the following way: - First, outgoing connection points from outmost to inmost, - Second, incoming connection points from inmost to outmost.
Returns:
List of all connection points located at end of road segment.

getLaneIndex

@AnyLogicInternalLibraryAPI
public int getLaneIndex​(RoadConnectionPoint connectionPoint)
Returns zero-based index of lane to which the specified connection point belongs to.
Parameters:
connectionPoint - Specified connection point.
Returns:
zero-based index of lane to which the specified connection point belongs or -1 if specified connection point does not belong to the road segment.

getForwardIncomingConnectionPoint

@AnyLogicInternalLibraryAPI
public RoadConnectionPoint getForwardIncomingConnectionPoint​(int forwardLaneIndex)
Returns incoming connection point located at the beginning of forward lane with the specified index.
Parameters:
forwardLaneIndex - Specified index of forward lane.
Returns:
Incoming connection point located at the beginning of forward lane with the specified index or null if no lane with the specified index exists.

isConnectionPointOnForwardDirection

@AnyLogicInternalLibraryAPI
public boolean isConnectionPointOnForwardDirection​(RoadConnectionPoint connectionPoint)
Checks if the specified road connection point is located on forward direction of the road segment.
Parameters:
connectionPoint - Specified connection point.
Returns:
True if the specified road connection point is located on forward direction, false otherwise.

getForwardOutgoingConnectionPoint

@AnyLogicInternalLibraryAPI
public RoadConnectionPoint getForwardOutgoingConnectionPoint​(int forwardLaneIndex)
Returns outgoing connection point located at the end of forward lane with the specified index.
Parameters:
forwardLaneIndex - Specified index of forward lane.
Returns:
Outgoing connection point located at the end of forward lane with the specified index or null if no lane with the specified index exists.

getBackwardIncomingConnectionPoint

@AnyLogicInternalLibraryAPI
public RoadConnectionPoint getBackwardIncomingConnectionPoint​(int backwardLaneIndex)
Returns incoming connection point located at the beginning of backward lane with the specified index.
Parameters:
backwardLaneIndex - Specified index of backward lane.
Returns:
Incoming connection point located at the beginning of backward lane with the specified index or null if no lane with the specified index exists.

setMedianStripColor

public void setMedianStripColor​(java.awt.Color color)
Sets the color of the median strip color.
Parameters:
color - the new color, null = do not draw the median strip color

setMedianStripColor

public void setMedianStripColor​(java.awt.Paint color)
Sets the color (or Texture) of the median strip color.
Parameters:
color - the new color, null = do not draw the median strip color

getMedianStripColor

public java.awt.Color getMedianStripColor()
Returns the color of the median strip, or null if median strip has no fill or has texture (in this case getMedianStripTexture() should be used instead)
Returns:
the color of the median strip color

getMedianStripTexture

public Texture getMedianStripTexture()
Returns the texture of the median strip color, if the median strip has texture
Returns:
the texture of the median strip color

getBackwardOutgoingConnectionPoint

@AnyLogicInternalLibraryAPI
public RoadConnectionPoint getBackwardOutgoingConnectionPoint​(int backwardLaneIndex)
Returns outgoing connection point located at the end of backward lane with the specified index.
Parameters:
backwardLaneIndex - Specified index of backward lane.
Returns:
Outgoing connection point located at the end of backward lane with the specified index or null if no lane with the specified index exists.

getForwardLanesCount

public int getForwardLanesCount()
Returns count of forward lanes.
Returns:
Count of forward lanes.

getBackwardLanesCount

public int getBackwardLanesCount()
Returns count of backward lanes.
Returns:
Count of backward lanes.

getForwardLaneMarkupSegments

@AnyLogicInternalLibraryAPI
public java.util.List<MarkupSegment> getForwardLaneMarkupSegments​(int forwardLaneIndex)
Returns list of markup segments representing guideline of forward lane with the specified lane index.
Parameters:
forwardLaneIndex - Specified index of forward lane.
Returns:
List of markup segments representing guideline of forward lane with the specified lane index, empty list if no forward lanes exist.

getBackwardLaneMarkupSegments

@AnyLogicInternalLibraryAPI
public java.util.List<MarkupSegment> getBackwardLaneMarkupSegments​(int backwardLaneIndex)
Returns list of markup segments representing guideline of backward lane with the specified lane index.
Parameters:
backwardLaneIndex - Specified index of backward lane.
Returns:
List of markup segments representing guideline of backward lane with the specified lane index, empty list if no backward lanes exist.

getAxisMarkupSegments

@AnyLogicInternalLibraryAPI
public java.util.List<MarkupSegment> getAxisMarkupSegments()
Returns list of markup segments representing road axis (the middle of median strip).
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.

getMedianStripWidth

public double getMedianStripWidth()
Returns median strip width, in pixels.
Returns:
median strip width, in pixels.

getMedianStripWidth

public double getMedianStripWidth​(LengthUnits units)
Returns median strip width measured in the given units.
Parameters:
units - length units
Returns:
median strip width, in the given units.

getConnectionPoints

@AnyLogicInternalLibraryAPI
public java.util.List<RoadConnectionPoint> getConnectionPoints()
Description copied from class: AbstractRoadConnectableElement
Returns a list of connection points of the road element. The elements of list can be sorted in any order, but this order is the same during lifetime of the element.
Specified by:
getConnectionPoints in class AbstractRoadConnectableElement
Returns:
List of connection points of the road element.

getBoundingRectangle

@AnyLogicInternalAPI
public BoundingRectangle getBoundingRectangle()

getStopLines

public java.util.List<StopLine> getStopLines()
Returns all stop lines contained in this road
Returns:
unmodifiable list of stop lines, ordered in 'forward' direction

getParkingLots

public java.util.List<ParkingLot> getParkingLots()
Returns all parking lots contained in this road
Returns:
unmodifiable list of parking lots, ordered in 'forward' direction

getBusStops

public java.util.List<BusStop> getBusStops()
Returns all bus stops contained in this road
Returns:
unmodifiable list of bus stops, ordered in 'forward' direction
How can we improve this article?