Class Variable

    • Constructor Detail

      • Variable

        Variable​(String name,
                 short stream,
                 TrafCOD trafCOD)
        Construct a new Variable.
        Parameters:
        name - String; name of the new variable (without the stream number)
        stream - short; stream number to which the new Variable is associated
        trafCOD - TrafCOD; the TrafCOD engine
    • 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 exist
        newTrafCOD - 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 newNetwork
        TrafficControlException - 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
      • 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
      • 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 Variable
        timeStamp10 - int; the time stamp of this update
        cause - CausePrinter; rule, timer, or detector that caused the change
        trafCODController - 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 copied
        newNetwork - 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.
      • getFlags

        public EnumSet<Flags> getFlags()
        Return a safe copy of the flags.
        Returns:
        EnumSet<Flags>
      • 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
      • 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