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
  • Constructor Details

  • Method Details

    • registerSpaceTimeRegion

      public final void registerSpaceTimeRegion​(SpaceTimeRegion spaceTimeRegion)
      Parameters:
      spaceTimeRegion - SpaceTimeRegion; space-time region
      Throws:
      java.lang.IllegalStateException - if data is not available from the requested start time
    • now

      public abstract Time now()
      Returns the current simulation time.
      Returns:
      current simulation time
    • scheduleStartRecording

      public abstract void scheduleStartRecording​(Time time, KpiLaneDirection kpiLaneDirection)
      Schedules the start of recording for a given lane-direction.
      Parameters:
      time - Time; time to start recording
      kpiLaneDirection - KpiLaneDirection; lane-direction to start recording
    • scheduleStopRecording

      public abstract void scheduleStopRecording​(Time time, KpiLaneDirection kpiLaneDirection)
      Schedules the stop of recording for a given lane-direction.
      Parameters:
      time - Time; time to stop recording
      kpiLaneDirection - KpiLaneDirection; lane-direction to stop recording
    • registerMetaDataTypes

      public final void registerMetaDataTypes​(java.util.Set<MetaDataType<?>> metaDataTypes)
      Registers meta data types that will be stored with the trajectories.
      Parameters:
      metaDataTypes - Set<MetaDataType<?>>; meta data types to register
    • registerExtendedDataType

      public final void registerExtendedDataType​(ExtendedDataType<?,​?,​?,​G> extendedDataType)
      Registers extended data type that will be stored with the trajectories.
      Parameters:
      extendedDataType - ExtendedDataType<?,?,?,G>; extended data type to register
    • contains

      public boolean contains​(ExtendedDataType<?,​?,​?,​?> extendedDataType)
      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

      public final void startRecording​(KpiLaneDirection kpiLaneDirection)
      Start recording at the given time (which should be the current time) on the given lane direction.
      Parameters:
      kpiLaneDirection - KpiLaneDirection; lane direction
    • initRecording

      public abstract void initRecording​(KpiLaneDirection kpiLaneDirection)
      Adds listeners to start recording.
      Parameters:
      kpiLaneDirection - KpiLaneDirection; lane direction to initialize recording for
    • stopRecording

      public final void stopRecording​(KpiLaneDirection kpiLaneDirection)
      Stop recording at given lane direction.
      Parameters:
      kpiLaneDirection - KpiLaneDirection; lane direction
    • finalizeRecording

      public abstract void finalizeRecording​(KpiLaneDirection kpiLaneDirection)
      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 at
      position - Length; position of the gtu on the lane
      speed - Speed; speed of the gtu
      acceleration - Acceleration; acceleration of the gtu
      time - Time; current time
      gtu - 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 at
      position - Length; position of the gtu on the lane
      speed - Speed; speed of the gtu
      acceleration - Acceleration; acceleration of the gtu
      time - Time; current time
      gtu - 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 at
      position - Length; position of the gtu on the lane
      speed - Speed; speed of the gtu
      acceleration - Acceleration; acceleration of the gtu
      time - Time; current time
      gtu - G; gtu
    • processGtuRemoveEvent

      public final void processGtuRemoveEvent​(KpiLaneDirection kpiLaneDirection, G gtu)
      Finalizes a trajectory.
      Parameters:
      kpiLaneDirection - KpiLaneDirection; lane direction the gtu is at
      gtu - G; gtu
    • contains

      public final boolean contains​(KpiLaneDirection kpiLaneDirection)
      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

      public final TrajectoryGroup<G> getTrajectoryGroup​(KpiLaneDirection kpiLaneDirection)
      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; file
      format - String; number format, as used in String.format()
      compression - CompressionMethod; how to compress the data
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object