Class Variable
- java.lang.Object
-
- org.opentrafficsim.trafficcontrol.trafcod.Variable
-
- All Implemented Interfaces:
Serializable
,EventListener
,EventListenerInterface
class Variable extends Object implements EventListenerInterface
A TrafCOD variable, timer, or detector.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOutput(TrafficLight trafficLight)
Add a traffic light to this variable.void
clearChangedFlag()
Clear the CHANGED flag of this Variable.void
clearFlag(Flags flag)
Clear one flag.(package private) Variable
clone(org.opentrafficsim.core.network.OTSNetwork newNetwork, TrafCOD newTrafCOD)
void
cloneState(Variable fromVariable, org.opentrafficsim.core.network.Network newNetwork)
Copy the state of this variable from another variable.int
conflictGroupRank()
Retrieve the rank of the conflict group that this Variable represents.boolean
decrementTimer(int timeStamp10)
Decrement the value of a timer.TrafficLightColor
getColor()
Retrieve the color for an output Variable.String
getEndSource()
Describe the rule that ends this variable.EnumSet<Flags>
getFlags()
Return a safe copy of the flags.String
getName()
Retrieve the name of this variable.int
getRefCount()
Retrieve the number of rules that refer to this variable.String
getStartSource()
Describe the rule that starts this variable.short
getStream()
Retrieve the stream to which this variable belongs.int
getTimerMax()
Retrieve the start value of this timer in units of 0.1 seconds (1 second is represented by the value 10).Set<TrafficLight>
getTrafficLights()
Retrieve the traffic lights controlled by this variable.int
getValue()
Retrieve the current value of this Variable.void
incrementReferenceCount()
Increment the reference counter of this variable.void
initialize()
Initialize this variable if it has the INITED flag set.boolean
isConflictGroup()
Report of this Variable identifies the current conflict group.boolean
isDetector()
Report if this Variable is a detector.boolean
isOutput()
Report whether a change in this variable must be published.boolean
isTimer()
Report whether this Variable is a timer.void
notify(EventInterface event)
void
setEndSource(String endSource)
Set the description of the rule that ends this variable.void
setFlag(Flags flag)
Set one flag.void
setOutput(int colorValue)
Make this variable an output variable and set the color value.void
setStartSource(String startSource)
Set the description of the rule that starts this variable.void
setTimerMax(int value10)
Set the maximum time of this timer.boolean
setValue(int newValue, int timeStamp10, CausePrinter cause, TrafCOD trafCODController)
void
subscribeToDetector(TrafficLightSensor sensor)
Link a detector variable to a sensor.String
toString()
String
toString(EnumSet<PrintFlags> printFlags)
Convert selected fields to a String.
-
-
-
Method Detail
-
getRefCount
public int getRefCount()
Retrieve the number of rules that refer to this variable.- Returns:
- int; the number of rules that refer to this variable
-
clone
final Variable clone(org.opentrafficsim.core.network.OTSNetwork newNetwork, TrafCOD newTrafCOD) throws org.opentrafficsim.core.network.NetworkException, TrafficControlException
- Parameters:
newNetwork
- OTSNetwork; the OTS Network in which the clone will existnewTrafCOD
- TrafCOD; the TrafCOD engine that will own the new Variable- Returns:
- Variable; the clone of this variable in the new network
- Throws:
org.opentrafficsim.core.network.NetworkException
- when a traffic light or sensor is not present in newNetworkTrafficControlException
- when the output for the cloned traffic light cannot be created
-
getTrafficLights
public Set<TrafficLight> getTrafficLights()
Retrieve the traffic lights controlled by this variable.- Returns:
- Set<TrafficLight>; the traffic lights controlled by this variable, or null when this variable has no traffic lights
-
getName
public String getName()
Retrieve the name of this variable.- Returns:
- String; the name (without the stream number) of this Variable
-
subscribeToDetector
public void subscribeToDetector(TrafficLightSensor sensor) throws TrafficControlException
Link a detector variable to a sensor.- Parameters:
sensor
- TrafficLightSensor; the sensor- Throws:
TrafficControlException
- when this variable is not a detector
-
initialize
public void initialize()
Initialize this variable if it has the INITED flag set.
-
decrementTimer
public boolean decrementTimer(int timeStamp10) throws TrafficControlException
Decrement the value of a timer.- Parameters:
timeStamp10
- int; the current simulator time in tenths of a second- Returns:
- boolean; true if the timer expired due to this call; false if the timer is still running, or expired before this call
- Throws:
TrafficControlException
- when this Variable is not a timer
-
getColor
public TrafficLightColor getColor() throws TrafficControlException
Retrieve the color for an output Variable.- Returns:
- int; the color code for this Variable
- Throws:
TrafficControlException
- if this Variable is not an output
-
isOutput
public boolean isOutput()
Report whether a change in this variable must be published.- Returns:
- boolean; true if this Variable is an output; false if this Variable is not an output
-
isConflictGroup
public boolean isConflictGroup()
Report of this Variable identifies the current conflict group.- Returns:
- boolean; true if this Variable identifies the current conflict group; false if it does not.
-
conflictGroupRank
public int conflictGroupRank() throws TrafficControlException
Retrieve the rank of the conflict group that this Variable represents.- Returns:
- int; the rank of the conflict group that this Variable represents
- Throws:
TrafficControlException
- if this Variable is not a conflict group identifier
-
isDetector
public boolean isDetector()
Report if this Variable is a detector.- Returns:
- boolean; true if this Variable is a detector; false if this Variable is not a detector
-
setValue
public boolean setValue(int newValue, int timeStamp10, CausePrinter cause, TrafCOD trafCODController)
- Parameters:
newValue
- int; the new value of this VariabletimeStamp10
- int; the time stamp of this updatecause
- CausePrinter; rule, timer, or detector that caused the changetrafCODController
- TrafCOD; the TrafCOD controller- Returns:
- boolean; true if the value of this variable changed
-
cloneState
public void cloneState(Variable fromVariable, org.opentrafficsim.core.network.Network newNetwork) throws org.opentrafficsim.core.network.NetworkException
Copy the state of this variable from another variable. Only used when cloning the TrafCOD engine.- Parameters:
fromVariable
- Variable; the variable whose state is copiednewNetwork
- Network; the Network that contains the new traffic control engine- Throws:
org.opentrafficsim.core.network.NetworkException
- when the clone of a traffic light of fromVariable does not exist in newNetwork
-
getTimerMax
public int getTimerMax() throws TrafficControlException
Retrieve the start value of this timer in units of 0.1 seconds (1 second is represented by the value 10).- Returns:
- int; the timerMax10 value
- Throws:
TrafficControlException
- when this class is not a Timer
-
getValue
public int getValue()
Retrieve the current value of this Variable.- Returns:
- int; the value of this Variable
-
setFlag
public void setFlag(Flags flag)
Set one flag.- Parameters:
flag
- Flags; Flags
-
clearFlag
public void clearFlag(Flags flag)
Clear one flag.- Parameters:
flag
- Flags; the flag to clear
-
isTimer
public boolean isTimer()
Report whether this Variable is a timer.- Returns:
- boolean; true if this Variable is a timer; false if this variable is not a timer
-
clearChangedFlag
public void clearChangedFlag()
Clear the CHANGED flag of this Variable.
-
incrementReferenceCount
public void incrementReferenceCount()
Increment the reference counter of this variable. The reference counter counts the number of rules where this variable occurs on the right hand side of the assignment operator.
-
setOutput
public void setOutput(int colorValue) throws TrafficControlException
Make this variable an output variable and set the color value.- Parameters:
colorValue
- int; the output value (as used in the TrafCOD file)- Throws:
TrafficControlException
- when the colorValue is invalid, or this method is called more than once for this variable
-
addOutput
public void addOutput(TrafficLight trafficLight) throws TrafficControlException
Add a traffic light to this variable.- Parameters:
trafficLight
- TrafficLight; the traffic light to add- Throws:
TrafficControlException
- when this variable is not an output
-
setTimerMax
public void setTimerMax(int value10) throws TrafficControlException
Set the maximum time of this timer.- Parameters:
value10
- int; the maximum time in 0.1 s- Throws:
TrafficControlException
- when this Variable is not a timer
-
getStartSource
public String getStartSource()
Describe the rule that starts this variable.- Returns:
- String
-
setStartSource
public void setStartSource(String startSource) throws TrafficControlException
Set the description of the rule that starts this variable.- Parameters:
startSource
- String; description of the rule that starts this variable- Throws:
TrafficControlException
- when a start source has already been set
-
getEndSource
public String getEndSource()
Describe the rule that ends this variable.- Returns:
- String
-
setEndSource
public void setEndSource(String endSource) throws TrafficControlException
Set the description of the rule that ends this variable.- Parameters:
endSource
- String; description of the rule that ends this variable- Throws:
TrafficControlException
- when an end source has already been set
-
getStream
public short getStream()
Retrieve the stream to which this variable belongs.- Returns:
- short; the stream to which this variable belongs
-
toString
public String toString(EnumSet<PrintFlags> printFlags)
Convert selected fields to a String.- Parameters:
printFlags
- EnumSet<PrintFlags>; the set of fields to convert- Returns:
- String
-
notify
public void notify(EventInterface event) throws RemoteException
- Specified by:
notify
in interfaceEventListenerInterface
- Throws:
RemoteException
-
-