public class TrafficLight<T extends ISignalable>
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
TrafficLight(T[] signalElements,
double[] phaseDurationsInSeconds,
TrafficLightSignal[][] phaseSignals)
Creates a new traffic light to control traffic using stop lines or lane connectors
|
Modifier and Type | Method and Description |
---|---|
double |
calcPhaseDurationInSeconds(int index)
This method is internal and shouldn't be called by user.
|
double |
getCurrentPhaseDuration()
Returns duration of the current phase in model time units, or -1 if the traffic light is off
|
double |
getCurrentPhaseDuration(TimeUnits units)
Returns duration of the current phase in specified time units, or -1 if the traffic light is off
|
double |
getCurrentPhaseElapsedTime()
Returns time elapsed from beginning of the current phase in model time units or -1 if the traffic light is off
|
double |
getCurrentPhaseElapsedTime(TimeUnits units)
Returns time elapsed from beginning of the current phase in specified time units or -1 if the traffic light is
off
|
int |
getCurrentPhaseIndex()
Returns 0-based index of the current phase, or -1 if the traffic light is off
|
double |
getCurrentPhaseRemainingTime()
Returns time remaining to the end of the current phase in model time units or -1 if the traffic light is off
|
double |
getCurrentPhaseRemainingTime(TimeUnits units)
Returns time remaining to the end of the current phase in specified time units or -1 if the traffic light is off
|
TrafficLightSignal |
getCurrentSignal(ISignalable signalElement)
Returns current signal for the specified stop line or lane connector.
|
double |
getPhaseDuration(int index)
Returns duration of the phase in model time units by index
|
double |
getPhaseDuration(int index,
TimeUnits units)
Returns duration of the phase in the given time units by index
|
java.util.List<java.util.List<TrafficLightSignal>> |
getPhaseSignals()
Returns two-dimensional list of signals where rows is the signals of one line and columns is the signals of one
phase
|
int |
getPhasesNumber()
Returns number of phases
|
RoadNetwork |
getRoadNetwork()
Return roadNetwork specified for this traffic light
|
java.util.List<T> |
getSignalElements()
Returns list of controlled stop lines or lane connectors
|
TrafficLightType |
getType()
This method is internal and shouldn't be called by user.
|
boolean |
isOn()
Returns
true if the traffic light is on, false otherwise |
void |
onPhaseChanged(int currentPhaseIndex) |
void |
setCurrentPhaseIndex(int currentPhaseIndex)
This method should not be called by user.
|
void |
setDelegate(TrafficLightDelegate delegate) |
void |
switchToNextPhase()
Switches traffic light to next phase.
|
java.lang.String |
toString() |
void |
turnOff()
Turns off traffic light
|
void |
turnOn()
Turns on traffic light
|
void |
turnOn(double offset)
Turns on traffic light with offset in model time units
|
void |
turnOn(double offset,
TimeUnits units)
Turns on traffic light with offset in the specified time units
|
public TrafficLight(T[] signalElements, double[] phaseDurationsInSeconds, TrafficLightSignal[][] phaseSignals)
signalElements
- Controlled stop lines or lane connectorsphaseDurationsInSeconds
- Durations of phases in seconds. Length of array is a number of
phases.phaseSignals
- Two-dimensional array of signals where rows are the signals of one stop line/lane connector
and columns are the signals of one phase. That is phaseSignals.length == signalElements.length and phaseSignals.[i].length ==
phaseDurations.length.public RoadNetwork getRoadNetwork()
@AnyLogicInternalAPI public TrafficLightType getType()
public java.util.List<T> getSignalElements()
public java.util.List<java.util.List<TrafficLightSignal>> getPhaseSignals()
public int getPhasesNumber()
public double getPhaseDuration(int index)
index
- phase index (0, 1, 2, ...)public double getPhaseDuration(int index, TimeUnits units)
index
- phase index (0, 1, 2, ...)units
- time units@AnyLogicInternalAPI public double calcPhaseDurationInSeconds(int index)
getPhaseDuration(int, TimeUnits)
instead.@AnyLogicInternalAPI public void setDelegate(TrafficLightDelegate delegate)
public void turnOn()
public void turnOn(double offset)
offset
- offset in model time unitspublic void turnOn(double offset, TimeUnits units)
offset
- offset in the specified time unitsunits
- the time unitspublic void turnOff()
public boolean isOn()
true
if the traffic light is on, false
otherwisetrue
if the traffic light is on, false
otherwisepublic void switchToNextPhase()
infinite
duration and
should be switchedpublic int getCurrentPhaseIndex()
public double getCurrentPhaseDuration()
public double getCurrentPhaseDuration(TimeUnits units)
units
- the time unitspublic double getCurrentPhaseElapsedTime()
public double getCurrentPhaseElapsedTime(TimeUnits units)
units
- the time unitspublic double getCurrentPhaseRemainingTime()
public double getCurrentPhaseRemainingTime(TimeUnits units)
units
- the time unitspublic TrafficLightSignal getCurrentSignal(ISignalable signalElement)
null
signalElement
- specified stop line or lane connector.@AnyLogicInternalAPI public void setCurrentPhaseIndex(int currentPhaseIndex)
CarTrafficLight_xjal
object when phase changes event is fired.currentPhaseIndex
- Index of the phase.@AnyLogicInternalCodegenAPI public void onPhaseChanged(int currentPhaseIndex)
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © AnyLogic North America, LLC. All Rights Reserved.