Intersection is a graphical space markup element that is used to connect two or more roads. Using roads, intersections, and other space markup elements you draw road networks for Road Traffic Library models.
Intersection controls traffic directions with the help of lane connectors that indicate routes for cars on each road lane as vehicles cross the intersection.
To know how to make traffic on the intersection controlled by a traffic light, refer to the Controlled intersection article.
Let us demonstrate how to draw an intersection by the example of Wilhelmstrasse and Behrenstrasse intersection in Berlin, close to the Brandenburg Gate:
The scenario is typical for all kinds of intersections. Steps 1-3 demonstrate how to draw a T-shaped intersection, then we continue and end up with a four-way intersection.
Name – The name of the intersection. The name is used to identify and access the intersection in code and properties.
Ignore – If selected, the intersection is excluded from the model.
Visible on upper agent – If selected, the intersection is also visible on the upper agent where this agent lives.
Lock – If selected, the intersection 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. It is frequently needed when you want to prevent editing this shape while drawing other shapes over it.
Visible – Here you specify whether the shape is visible on animation at model runtime, or not. Using the control, choose yes or no.
Show in - Here you can choose whether you want the shape to be shown both in 2D and 3D animation, or in 2D only, or in 3D only.
Show name – If selected, the intersection's name is displayed on the graphical diagram.
Lane connectors define the allowed traffic directions on an intersection. To enable car movement from one lane to the specific lane of other road, you should enable the lane connector linking the corresponding lane ends together.
By default AnyLogic enables the connectors that are typical for the intersection of the current topology.
Default lane connectors for four-way intersection and T-shaped intersection
Cars strictly follow lane connectors on their way through the intersection.
If you need to customize traffic directions on the intersection, you may disable any existing connectors, draw more connectors, and alter connector shapes.
Let us demonstrate how to enable traffic direction from the lower road to the right road.
If default connectors created by AnyLogic are similar to the ones you need, you can just slightly adjust them. However, if they differ drastically, it may be simpler to draw all the required lane connectors from scratch. In this case you should start with deleting all the existing lane connectors.
int nCars() - Returns number of cars located on this intersection.
List<Agent> getCars() - Returns unordered list of cars located on this intersection.
int traffic() - Returns the number of cars that have passed through this lane connector during 1 hour of model time. To obtain this result, we count the cars that have passed through this intersection during the last 5 minutes of model time and multiply this number by 12.
int countCars() - Returns the total number of cars that have passed through this lane connector since the start of the model run.
void resetStats() - Resets the counters for countCars() and traffic() functions of the lane connector.
int traffic(Road from, Road to) - Returns the number of cars that have passed between the specified lanes during 1 hour of model time. This result is the sum of traffic() for each lane connector between the specified lanes.
Parameters:
from - a lane connected to the intersection
to - a lane connected to the intersection
int countCars(Road from, Road to) - Returns the number of cars that have passed between the specified lanes since the start of the model run. The result is the sum of countCars() for each lane connector between the specified lanes.
Parameters:
from - a lane connected to the intersection
to - a lane connected to the intersection
void resetStats() - Resets the counters for countCars() and traffic() functions of the intersection.
void setVisible(boolean v) - Sets the visibility of the intersection.
Parameter: v - visibility of the intersection: if true - the intersection is visible, if false - not visible.
boolean isVisible() - Returns the visibility of the intersection. If it returns true, the intersection is visible, if false - not
void showLaneConnectors(boolean showLaneConnectors) - Returns the visibility of lane connectors of the intersection.
Parameter:
showLaneConnectors - visibility of lane connectors: if true - the connectors are visible, if false - not visible.
RoadNetwork getRoadNetwork() - Returns the road network this intersection belongs to.
List<RoadLanesConnector> getLanesConnectors() - Returns the list of lane connectors inside this intersection.
void remove() - Removes the intersection from the presentation. If the intersection is not a part of presentation, the function does nothing. Note, that removal from the presentation does not necessarily mean removing from the model logic, since logical networks and routes may have been created before the removal and survive it.