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,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 classDetector.CompressionMethodDefines the compression method for stored data.static interfaceDetector.DetectorMeasurement<C,A>Interface for what detectors measure.static classDetector.PlatoonSizesMeasurement of platoon sizes based on time between previous GTU exit and GTU entry.
-
Field Summary
Fields Modifier and Type Field Description static TimedEventTypeDETECTOR_AGGREGATEAggregation event.static TimedEventTypeDETECTOR_TRIGGEREDTrigger event.static Detector.DetectorMeasurement<Double,Speed>HARMONIC_MEAN_SPEEDHarmonic mean speed measurement.static Detector.DetectorMeasurement<Double,Speed>MEAN_SPEEDMean speed measurement.static Detector.DetectorMeasurement<Double,Double>OCCUPANCYOccupancy measurement.static Detector.DetectorMeasurement<List<Double>,List<Double>>PASSAGESPassages 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, DEVSSimulatorInterface.TimeDoubleUnit simulator)Constructor for regular Dutch dual-loop detectors measuring flow and mean speed aggregated over 60s.Detector(String id, Lane lane, Length longitudinalPosition, Length length, DEVSSimulatorInterface.TimeDoubleUnit simulator, Duration aggregation, Detector.DetectorMeasurement<?,?>... measurements)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractSensorclone(CrossSectionElement newCSE, SimulatorInterface.TimeDoubleUnit newSimulator)Clone the LaneBasedObject for e.g., copying a network.FrequencygetLastFlow()Returns the last flow.<A> AgetLastValue(Detector.DetectorMeasurement<?,A> detectorMeasurement)Returns the last value of the detector measurement.LengthgetLength()Returns the detector length.booleanhasLastValue()Returns whether the detector has aggregated data available.static StringprintListDouble(List<Double> list, String format)Prints a list of doubles in to a formatted string.static StringremoveTrailingZeros(String string)Remove any trailing zeros.protected voidtriggerResponse(LaneBasedGTU gtu)Implementation of the response to a trigger of this sensor by a GTU.static voidwriteToFile(OTSRoadNetwork network, String file, boolean periodic)Write the contents of all detectors in to a file.static <C> voidwriteToFile(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.base.Identifiable
getId
-
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, DEVSSimulatorInterface.TimeDoubleUnit 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- DEVSSimulatorInterface.TimeDoubleUnit; simulator- Throws:
NetworkException- on network exception
-
Detector
public Detector(String id, Lane lane, Length longitudinalPosition, Length length, DEVSSimulatorInterface.TimeDoubleUnit simulator, Duration aggregation, Detector.DetectorMeasurement<?,?>... measurements) throws NetworkException
Constructor.- Parameters:
id- String; detector idlane- Lane; lanelongitudinalPosition- Length; positionlength- Length; lengthsimulator- DEVSSimulatorInterface.TimeDoubleUnit; 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:
triggerResponsein classAbstractSensor- Parameters:
gtu- LaneBasedGTU; the lane based GTU that triggered this sensor.
-
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, SimulatorInterface.TimeDoubleUnit newSimulator) throws NetworkException
Clone the LaneBasedObject for e.g., copying a network.- Specified by:
clonein classAbstractSensor- Parameters:
newCSE- CrossSectionElement; the new cross section element to which the clone belongsnewSimulator- SimulatorInterface.TimeDoubleUnit; 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
-
-