Class TrafCOD

    • Constructor Detail

      • TrafCOD

        public TrafCOD​(String controllerName,
                       URL trafCodURL,
                       OTSSimulatorInterface simulator,
                       Container display,
                       BufferedImage displayBackground,
                       List<String> displayObjectLocations)
                throws TrafficControlException,
                       SimRuntimeException,
                       IOException
        Construct a new TrafCOD traffic light controller.
        Parameters:
        controllerName - String; name of this TrafCOD traffic light controller
        trafCodURL - URL; the URL of the TrafCOD rules
        simulator - OTSSimulatorInterface; the simulation engine
        display - Container; if non-null, a controller display is constructed and shown in the supplied container
        displayBackground - BufferedImage; background for controller display image
        displayObjectLocations - List<String>; list of sensors and traffic lights and their locations on the displayBackGround
        Throws:
        TrafficControlException - when a rule cannot be parsed
        SimRuntimeException - when scheduling the first evaluation event fails
        IOException - when loading the TrafCOD rules from the URL fails
      • TrafCOD

        public TrafCOD​(String controllerName,
                       List<String> trafCODRules,
                       OTSSimulatorInterface simulator,
                       BufferedImage displayBackground,
                       List<String> displayObjectLocations)
                throws TrafficControlException,
                       SimRuntimeException
        Construct a new TrafCOD traffic light controller.
        Parameters:
        controllerName - String; name of this TrafCOD traffic light controller
        trafCODRules - List<String>; the TrafCOD rules
        simulator - OTSSimulatorInterface; the simulation engine
        displayBackground - BufferedImage; background for controller display image
        displayObjectLocations - List<String>; list of sensors and traffic lights and their locations on the displayBackGround
        Throws:
        TrafficControlException - when a rule cannot be parsed
        SimRuntimeException - when scheduling the first evaluation event fails
    • Method Detail

      • loadTextFromURL

        public static List<String> loadTextFromURL​(URL url)
                                            throws IOException
        Read a text from a URL and convert it to a list of strings.
        Parameters:
        url - URL; the URL to open and read
        Returns:
        List<String>; the lines read from the URL (trimmed).
        Throws:
        IOException - when opening or reading the URL failed.
      • getStructureNumber

        public int getStructureNumber()
        Retrieve the structure number.
        Returns:
        int; the structureNumber
      • updateDetector

        public void updateDetector​(String detectorId,
                                   boolean detectingGTU)
        Tell the traffic controller that the state of a detector has changed.
        Specified by:
        updateDetector in interface ActuatedTrafficController
        Parameters:
        detectorId - String; id of the detector
        detectingGTU - boolean;
      • traceVariablesOfStream

        public void traceVariablesOfStream​(int stream,
                                           boolean trace)
        Switch tracing of all variables of a particular traffic stream, or all variables that do not have an associated traffic stream on or off.
        Parameters:
        stream - int; the traffic stream number, or TrafCOD.NO_STREAM to affect all variables that do not have an associated traffic stream
        trace - boolean; if true; switch on tracing; if false; switch off tracing
      • traceVariable

        public void traceVariable​(String variableName,
                                  int stream,
                                  boolean trace)
        Switch tracing of one variable on or off.
        Parameters:
        variableName - String; name of the variable
        stream - int; traffic stream of the variable, or TrafCOD.NO_STREAM to select a variable that does not have an associated traffic stream
        trace - boolean; if true; switch on tracing; if false; switch off tracing
      • getDisplayContainer

        public Container getDisplayContainer()
        Retrieve the Swing (for now) container in which the controller displays its current state.
        Specified by:
        getDisplayContainer in interface ActuatedTrafficController
        Returns:
        Container; the display of the current state; may return null!