Package org.opentrafficsim.kpi.sampling
Class Sampler<G extends GtuDataInterface>
java.lang.Object
org.opentrafficsim.kpi.sampling.Sampler<G>
- Type Parameters:
G
- gtu data type
public abstract class Sampler<G extends GtuDataInterface>
extends java.lang.Object
Sampler is the highest level organizer for sampling.
Copyright (c) 2013-2019 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 Sep 22, 2016
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Sampler.CompressionMethod
Defines the compression method for stored data. -
Constructor Summary
Constructors Constructor Description Sampler()
-
Method Summary
Modifier and Type Method Description boolean
contains(ExtendedDataType<?,?,?,?> extendedDataType)
Whether this sampler has the given extended data type registered to it.boolean
contains(KpiLaneDirection kpiLaneDirection)
Returns whether there is data for the give lane direction.boolean
equals(java.lang.Object obj)
abstract void
finalizeRecording(KpiLaneDirection kpiLaneDirection)
Remove listeners to stop recording.TrajectoryGroup<G>
getTrajectoryGroup(KpiLaneDirection kpiLaneDirection)
Returns the trajectory group of given lane direction.int
hashCode()
abstract void
initRecording(KpiLaneDirection kpiLaneDirection)
Adds listeners to start recording.abstract Time
now()
Returns the current simulation time.void
processGtuAddEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)
Creates a trajectory with the current snapshot of a GTU.void
processGtuMoveEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)
Adds a new snapshot of a GTU to its recording trajectory, if recorded.void
processGtuRemoveEvent(KpiLaneDirection kpiLaneDirection, G gtu)
Finalizes a trajectory.void
processGtuRemoveEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)
Finalizes a trajectory with the current snapshot of a GTU.void
registerExtendedDataType(ExtendedDataType<?,?,?,G> extendedDataType)
Registers extended data type that will be stored with the trajectories.void
registerMetaDataTypes(java.util.Set<MetaDataType<?>> metaDataTypes)
Registers meta data types that will be stored with the trajectories.void
registerSpaceTimeRegion(SpaceTimeRegion spaceTimeRegion)
abstract void
scheduleStartRecording(Time time, KpiLaneDirection kpiLaneDirection)
Schedules the start of recording for a given lane-direction.abstract void
scheduleStopRecording(Time time, KpiLaneDirection kpiLaneDirection)
Schedules the stop of recording for a given lane-direction.void
startRecording(KpiLaneDirection kpiLaneDirection)
Start recording at the given time (which should be the current time) on the given lane direction.void
stopRecording(KpiLaneDirection kpiLaneDirection)
Stop recording at given lane direction.void
writeToFile(java.lang.String file)
Write the contents of the sampler in to a file.void
writeToFile(java.lang.String file, java.lang.String format, Sampler.CompressionMethod compression)
Write the contents of the sampler in to a file.
-
Constructor Details
-
Sampler
public Sampler()
-
-
Method Details
-
registerSpaceTimeRegion
- Parameters:
spaceTimeRegion
- SpaceTimeRegion; space-time region- Throws:
java.lang.IllegalStateException
- if data is not available from the requested start time
-
now
Returns the current simulation time.- Returns:
- current simulation time
-
scheduleStartRecording
Schedules the start of recording for a given lane-direction.- Parameters:
time
- Time; time to start recordingkpiLaneDirection
- KpiLaneDirection; lane-direction to start recording
-
scheduleStopRecording
Schedules the stop of recording for a given lane-direction.- Parameters:
time
- Time; time to stop recordingkpiLaneDirection
- KpiLaneDirection; lane-direction to stop recording
-
registerMetaDataTypes
Registers meta data types that will be stored with the trajectories.- Parameters:
metaDataTypes
- Set<MetaDataType<?>>; meta data types to register
-
registerExtendedDataType
Registers extended data type that will be stored with the trajectories.- Parameters:
extendedDataType
- ExtendedDataType<?,?,?,G>; extended data type to register
-
contains
Whether this sampler has the given extended data type registered to it.- Parameters:
extendedDataType
- ExtendedDataType<?,?,?,?>; extended data type- Returns:
- whether this sampler has the given extended data type registered to it
-
startRecording
Start recording at the given time (which should be the current time) on the given lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction
-
initRecording
Adds listeners to start recording.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction to initialize recording for
-
stopRecording
Stop recording at given lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction
-
finalizeRecording
Remove listeners to stop recording.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction to finalize recording for
-
processGtuAddEvent
public final void processGtuAddEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)Creates a trajectory with the current snapshot of a GTU.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction the gtu is atposition
- Length; position of the gtu on the lanespeed
- Speed; speed of the gtuacceleration
- Acceleration; acceleration of the gtutime
- Time; current timegtu
- G; gtu
-
processGtuMoveEvent
public final void processGtuMoveEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)Adds a new snapshot of a GTU to its recording trajectory, if recorded. This method may be invoked on GTU that are not being recorded; the event will then be ignored.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction the gtu is atposition
- Length; position of the gtu on the lanespeed
- Speed; speed of the gtuacceleration
- Acceleration; acceleration of the gtutime
- Time; current timegtu
- G; gtu
-
processGtuRemoveEvent
public final void processGtuRemoveEvent(KpiLaneDirection kpiLaneDirection, Length position, Speed speed, Acceleration acceleration, Time time, G gtu)Finalizes a trajectory with the current snapshot of a GTU.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction the gtu is atposition
- Length; position of the gtu on the lanespeed
- Speed; speed of the gtuacceleration
- Acceleration; acceleration of the gtutime
- Time; current timegtu
- G; gtu
-
processGtuRemoveEvent
Finalizes a trajectory.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction the gtu is atgtu
- G; gtu
-
contains
Returns whether there is data for the give lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction- Returns:
- whether there is data for the give lane direction
-
getTrajectoryGroup
Returns the trajectory group of given lane direction.- Parameters:
kpiLaneDirection
- KpiLaneDirection; lane direction- Returns:
- trajectory group of given lane direction,
null
if none
-
writeToFile
public final void writeToFile(java.lang.String file)Write the contents of the sampler in to a file. By default this is zipped and numeric data is formated %.3f.- Parameters:
file
- String; file
-
writeToFile
public final void writeToFile(java.lang.String file, java.lang.String format, Sampler.CompressionMethod compression)Write the contents of the sampler in to a file.- Parameters:
file
- String; fileformat
- String; number format, as used inString.format()
compression
- CompressionMethod; how to compress the data
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-