Class Detector

    • Constructor Detail

      • Detector

        public Detector​(String id,
                        Lane lane,
                        Length longitudinalPosition,
                        OTSSimulatorInterface simulator)
                 throws NetworkException
        Constructor for regular Dutch dual-loop detectors measuring flow and mean speed aggregated over 60s.
        Parameters:
        id - String; detector id
        lane - Lane; lane
        longitudinalPosition - Length; position
        simulator - OTSSimulatorInterface; simulator
        Throws:
        NetworkException - on network exception
      • Detector

        public Detector​(String id,
                        Lane lane,
                        Length longitudinalPosition,
                        Length length,
                        OTSSimulatorInterface simulator,
                        Duration aggregation,
                        Detector.DetectorMeasurement<?,​?>... measurements)
                 throws NetworkException
        Constructor.
        Parameters:
        id - String; detector id
        lane - Lane; lane
        longitudinalPosition - Length; position
        length - Length; length
        simulator - OTSSimulatorInterface; simulator
        aggregation - Duration; aggregation period
        measurements - DetectorMeasurement<?, ?>...; measurements to obtain
        Throws:
        NetworkException - on network exception
    • Method Detail

      • getLength

        public Length getLength()
        Returns the detector length.
        Returns:
        Length; the detector length
      • triggerResponse

        protected void triggerResponse​(LaneBasedGTU gtu)
        Implementation of the response to a trigger of this sensor by a GTU.
        Specified by:
        triggerResponse in class AbstractSensor
        Parameters:
        gtu - LaneBasedGTU; the lane based GTU that triggered this sensor.
      • accumulate

        <C> void accumulate​(Detector.DetectorMeasurement<C,​?> measurement,
                            LaneBasedGTU gtu,
                            boolean front)
        Accumulates a measurement.
        Type Parameters:
        C - accumulated type
        Parameters:
        measurement - DetectorMeasurement<C, ?>; measurement to accumulate
        gtu - LaneBasedGTU; gtu
        front - boolean; triggered by front entering (or rear leaving when false)
      • hasLastValue

        public boolean hasLastValue()
        Returns whether the detector has aggregated data available.
        Returns:
        boolean; whether the detector has aggregated data available
      • getLastFlow

        public Frequency getLastFlow()
        Returns the last flow.
        Returns:
        last flow
      • getLastValue

        public <A> A getLastValue​(Detector.DetectorMeasurement<?,​A> detectorMeasurement)
        Returns the last value of the detector measurement.
        Type Parameters:
        A - aggregate value type of the detector measurement
        Parameters:
        detectorMeasurement - DetectorMeasurement<?,A>; detector measurement
        Returns:
        last value of the detector measurement
      • writeToFile

        public static final void writeToFile​(OTSRoadNetwork network,
                                             String file,
                                             boolean periodic)
        Write the contents of all detectors in to a file.
        Parameters:
        network - OTSRoadNetwork; network
        file - String; file
        periodic - boolean; periodic data
      • writeToFile

        public static final <C> void writeToFile​(OTSRoadNetwork network,
                                                 String file,
                                                 boolean periodic,
                                                 String format,
                                                 Detector.CompressionMethod compression)
        Write the contents of all detectors in to a file.
        Type Parameters:
        C - accumulated type
        Parameters:
        network - OTSRoadNetwork; network
        file - String; file
        periodic - boolean; periodic data
        format - String; number format, as used in String.format()
        compression - CompressionMethod; how to compress the data
      • removeTrailingZeros

        public static final String removeTrailingZeros​(String string)
        Remove any trailing zeros.
        Parameters:
        string - String; string of number
        Returns:
        String; string without trailing zeros
      • printListDouble

        public static final String printListDouble​(List<Double> list,
                                                   String format)
        Prints a list of doubles in to a formatted string.
        Parameters:
        list - List<Double>; double values
        format - String; format string
        Returns:
        formatted string of doubles