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-2020 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 EventTypeDETECTOR_AGGREGATEAggregation event.static EventTypeDETECTOR_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 interface org.opentrafficsim.core.compatibility.Compatible
EVERYTHING, MINUS, PLUSFields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITIONFields 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
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, triggerMethods inherited from class org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject
clone, getDirection, getFullId, getLane, getLocation, getLongitudinalPosition, initMethods inherited from class org.opentrafficsim.core.object.StaticObject
create, create, getBounds, getGeometry, getHeight, getId, getSourceIdMethods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, getEventTypesWithListeners, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, getSourceId, hasListeners, numberOfListeners, removeListenerMethods inherited from interface org.opentrafficsim.road.network.lane.object.LaneBasedObject
getBounds, getDirection, getLane, getLocation, getLongitudinalPositionMethods inherited from interface org.opentrafficsim.core.object.ObjectInterface
getFullId, getGeometry, getHeight
-
Field Details
-
DETECTOR_TRIGGERED
Trigger event. Payload: [LaneBasedGTU gtu]. -
DETECTOR_AGGREGATE
Aggregation event. Payload: [Frequency flow, other attached measurements]/ -
MEAN_SPEED
Mean speed measurement. -
HARMONIC_MEAN_SPEED
Harmonic mean speed measurement. -
OCCUPANCY
Occupancy measurement. -
PASSAGES
Passages measurement.
-
-
Constructor Details
-
Detector
public Detector(String id, Lane lane, Length longitudinalPosition, DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkExceptionConstructor 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 NetworkExceptionConstructor.- 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 Details
-
getLength
Returns the detector length.- Returns:
- Length; the detector length
-
triggerResponse
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
Returns the last flow.- Returns:
- last flow
-
getLastValue
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 NetworkExceptionClone 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
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
Remove any trailing zeros.- Parameters:
string- String; string of number- Returns:
- String; string without trailing zeros
-
printListDouble
Prints a list of doubles in to a formatted string.- Parameters:
list- List<Double>; double valuesformat- String; format string- Returns:
- formatted string of doubles
-