Simulates one or several traffic lights. Traffic light (also known as traffic signal, traffic semaphore, signal light, stop light) is a signaling device positioned at road intersections, pedestrian crossings, and other locations to control conflicting flows of traffic.
In AnyLogic you can set Traffic Light to control car traffic at specified intersection or stop-line(s).
Demo model: Traffic Light
To know how to create a controlled intersection, please refer here.
Demo model: Traffic Light Phases Optimization
boolean isOn() -
Returns true
if the traffic light is on, false
otherwise.
turnOn() - Turns on traffic light.
turnOff() - Turns off traffic light.
turnOn(double offset) - Turns on traffic light with offset in model time units.
Parameter: offset - offset in model time units
turnOn(double offset, TimeUnits units) - Turns on traffic light with offset in specified time units. For example, the function call turnOn(1, MINUTE) will turn the traffic light on in 1 minute from the current time.
Parameters:
offset - offset in specified time units
units - time unit constant
switchToNextPhase() - Switches traffic light to the next phase. Typical use case: current phase has infinite duration and should be switched.
double getCurrentPhaseDuration() - Returns the duration of the current phase in model time units. If traffic light is off, the function returns -1.
double getCurrentPhaseDuration(TimeUnits units) - Returns the duration of the current phase in specified time units. For example, if the duration of the current phase is 30 seconds, the function call getCurrentPhaseDuration(MINUTE) will return 0.5. If traffic light is off, the function returns -1.
Parameter: units - time unit constant
double getCurrentPhaseElapsedTime() - Returns the time elapsed from the beginning of the current phase in model time units or -1 if the traffic light is off.
double getCurrentPhaseElapsedTime(TimeUnits units) - Returns the time elapsed from the beginning of the current phase in specified time units. For example, if 15 seconds have elapsed, the function call getCurrentPhaseElapsedTime(MINUTE) will return 0.25. If traffic light is off, the function returns -1.
Parameter: units - time unit constant
double getCurrentPhaseRemainingTime() - Returns the remaining time to the end of the current phase in model time units. If traffic light is off, the function returns -1.
double getCurrentPhaseRemainingTime(TimeUnits units) - Returns the remaining time to the end of the current phase in specified time units. For example, if the remaining time is 15 seconds, the function call getCurrentPhaseRemainingTime(MINUTE) will return 0.25. If traffic light is off, the function returns -1.
Parameter: units - time unit constant
int getPhasesNumber() - Returns number of phases.
int getCurrentPhaseIndex() - Returns 0-based index of the current phase, or -1 if the traffic light is off.
double getPhaseDuration(int index) - Returns the duration of the phase in model time units. You specify the phase by its index. For example, to get the duration of the first phase, you should call getPhaseDuration(0).
Parameter: index - phase index (0, 1, 2, ...)
double getPhaseDuration(int index, TimeUnits units) - Returns the duration of the phase in given time units. You specify the phase by its index. For example, to get the duration of the second phase in seconds, you should call getPhaseDuration(1, SECOND).
Parameters: index - phase index (0, 1, 2, ...)
units - time unit constant
List<List<TrafficLightSignal>> getPhaseSignals() - Returns a list of lists where each list contains the phases of one stop-line.
TrafficLightSignal
getCurrentSignal(StopLine stopLine) - Returns current signal for
the specified stop line. Returns null
, if the traffic
light is off, or if it does not control the stop line.
Parameter: stopLine - the specified stop line.
TrafficLightSignal
getCurrentSignal(RoadLanesConnector roadLaneConnector) - Returns
current signal for the specified road lane connector. Returns null
,
if the traffic light is off or if it does not control the road lane
connector.
Parameter:
roadLaneConnector -
the specified road lane connector
List<T> getSignalElements() - Returns list of controlled stop lines or lane connectors.
setRoadNetwork(RoadNetwork roadNetwork) - Sets a road network.
Parameter: roadNetwork - road network that the created traffic light belongs to
RoadNetwork getRoadNetwork() - Returns road network containing the markup element the specified traffic light is controlling.