Class Detector
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.core.object.StaticObject
-
- org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject
-
- org.opentrafficsim.road.network.lane.object.sensor.AbstractSensor
-
- org.opentrafficsim.road.network.lane.object.sensor.Detector
-
- All Implemented Interfaces:
Serializable
,Comparable<SingleSensor>
,Locatable
,EventProducerInterface
,org.opentrafficsim.base.Identifiable
,Drawable
,Compatible
,ObjectInterface
,LaneBasedObject
,Sensor
,SingleSensor
public class Detector extends AbstractSensor
Detector, measuring a dynamic set of measurements.Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version 5 mrt. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Detector.CompressionMethod
Defines the compression method for stored data.static interface
Detector.DetectorMeasurement<C,A>
Interface for what detectors measure.(package private) static class
Detector.PlatoonMeasurement
Cumulative information for platoon size measurement.static class
Detector.PlatoonSizes
Measurement of platoon sizes based on time between previous GTU exit and GTU entry.
-
Field Summary
Fields Modifier and Type Field Description static TimedEventType
DETECTOR_AGGREGATE
Aggregation event.static TimedEventType
DETECTOR_TRIGGERED
Trigger event.static Detector.DetectorMeasurement<Double,Speed>
HARMONIC_MEAN_SPEED
Harmonic mean speed measurement.static Detector.DetectorMeasurement<Double,Speed>
MEAN_SPEED
Mean speed measurement.static Detector.DetectorMeasurement<Double,Double>
OCCUPANCY
Occupancy measurement.static Detector.DetectorMeasurement<List<Double>,List<Double>>
PASSAGES
Passages measurement.-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.opentrafficsim.core.compatibility.Compatible
EVERYTHING, MINUS, PLUS
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Fields inherited from interface org.opentrafficsim.road.network.lane.object.sensor.SingleSensor
DEFAULT_SENSOR_ELEVATION, SENSOR_TRIGGER_EVENT
-
-
Constructor Summary
Constructors Constructor Description Detector(String id, Lane lane, Length longitudinalPosition, Length length, OTSSimulatorInterface simulator, Duration aggregation, Detector.DetectorMeasurement<?,?>... measurements)
Constructor.Detector(String id, Lane lane, Length longitudinalPosition, OTSSimulatorInterface simulator)
Constructor for regular Dutch dual-loop detectors measuring flow and mean speed aggregated over 60s.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) <C> void
accumulate(Detector.DetectorMeasurement<C,?> measurement, LaneBasedGTU gtu, boolean front)
Accumulates a measurement.AbstractSensor
clone(CrossSectionElement newCSE, OTSSimulatorInterface newSimulator)
Clone the LaneBasedObject for e.g., copying a network.Frequency
getLastFlow()
Returns the last flow.<A> A
getLastValue(Detector.DetectorMeasurement<?,A> detectorMeasurement)
Returns the last value of the detector measurement.Length
getLength()
Returns the detector length.boolean
hasLastValue()
Returns whether the detector has aggregated data available.static String
printListDouble(List<Double> list, String format)
Prints a list of doubles in to a formatted string.static String
removeTrailingZeros(String string)
Remove any trailing zeros.protected void
triggerResponse(LaneBasedGTU gtu)
Implementation of the response to a trigger of this sensor by a GTU.static void
writeToFile(OTSRoadNetwork network, String file, boolean periodic)
Write the contents of all detectors in to a file.static <C> void
writeToFile(OTSRoadNetwork network, String file, boolean periodic, String format, Detector.CompressionMethod compression)
Write the contents of all detectors in to a file.-
Methods inherited from class org.opentrafficsim.road.network.lane.object.sensor.AbstractSensor
compareTo, equals, getDetectedGTUTypes, getPositionType, getSimulator, hashCode, isCompatible, makeGeometry, toString, trigger
-
Methods inherited from class org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject
clone, getDirection, getFullId, getLane, getLocation, getLongitudinalPosition, init
-
Methods inherited from class org.opentrafficsim.core.object.StaticObject
create, create, getBounds, getGeometry, getHeight, getId, getSourceId
-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, getSourceId, hasListeners, numberOfListeners, removeListener
-
Methods inherited from interface org.opentrafficsim.road.network.lane.object.LaneBasedObject
getBounds, getDirection, getLane, getLocation, getLongitudinalPosition
-
Methods inherited from interface org.opentrafficsim.core.object.ObjectInterface
getFullId, getGeometry, getHeight
-
-
-
-
Field Detail
-
DETECTOR_TRIGGERED
public static final TimedEventType DETECTOR_TRIGGERED
Trigger event. Payload: [Id of LaneBasedGTU].
-
DETECTOR_AGGREGATE
public static final TimedEventType DETECTOR_AGGREGATE
Aggregation event. Payload: [Frequency, measurement, ...]/
-
MEAN_SPEED
public static final Detector.DetectorMeasurement<Double,Speed> MEAN_SPEED
Mean speed measurement.
-
HARMONIC_MEAN_SPEED
public static final Detector.DetectorMeasurement<Double,Speed> HARMONIC_MEAN_SPEED
Harmonic mean speed measurement.
-
OCCUPANCY
public static final Detector.DetectorMeasurement<Double,Double> OCCUPANCY
Occupancy measurement.
-
PASSAGES
public static final Detector.DetectorMeasurement<List<Double>,List<Double>> PASSAGES
Passages measurement.
-
-
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 idlane
- Lane; lanelongitudinalPosition
- Length; positionsimulator
- 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 idlane
- Lane; lanelongitudinalPosition
- Length; positionlength
- Length; lengthsimulator
- OTSSimulatorInterface; simulatoraggregation
- Duration; aggregation periodmeasurements
- 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 classAbstractSensor
- 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 accumulategtu
- LaneBasedGTU; gtufront
- 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
-
clone
public AbstractSensor clone(CrossSectionElement newCSE, OTSSimulatorInterface newSimulator) throws NetworkException
Clone the LaneBasedObject for e.g., copying a network.- Specified by:
clone
in classAbstractSensor
- Parameters:
newCSE
- CrossSectionElement; the new cross section element to which the clone belongsnewSimulator
- OTSSimulatorInterface; the new simulator for this network- Returns:
- AbstractLaneBasedObject; a clone of this object
- Throws:
NetworkException
- in case the cloning fails
-
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; networkfile
- String; fileperiodic
- 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; networkfile
- String; fileperiodic
- boolean; periodic dataformat
- String; number format, as used inString.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
-
-