Class Trajectory<G extends GtuDataInterface>

java.lang.Object
org.opentrafficsim.kpi.sampling.Trajectory<G>
Type Parameters:
G - gtu data type

public final class Trajectory<G extends GtuDataInterface>
extends java.lang.Object
Contains position, speed, acceleration and time data of a GTU, over some section. Position is relative to the start of the lane in the direction of travel, also when trajectories have been truncated at a position x > 0. Note that this regards internal data and output. Input position always refers to the design line of the lane. This class internally flips input positions and boundaries.

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.

$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Sep 21, 2016
Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • Trajectory

      public Trajectory​(GtuDataInterface gtu, MetaData metaData, java.util.Set<ExtendedDataType<?,​?,​?,​G>> extendedData, KpiLaneDirection kpiLaneDirection)
      Parameters:
      gtu - GtuDataInterface; GTU of this trajectory, only the id is stored.
      metaData - MetaData; meta data
      extendedData - Set<ExtendedDataType<?,?,?,G>>; types of extended data
      kpiLaneDirection - KpiLaneDirection; direction of travel
  • Method Details

    • add

      public void add​(Length position, Speed speed, Acceleration acceleration, Time time)
      Adds values of position, speed, acceleration and time.
      Parameters:
      position - Length; position is relative to the start of the lane in the direction of the design line, i.e. irrespective of the travel direction, also when trajectories have been truncated at a position x > 0
      speed - Speed; speed
      acceleration - Acceleration; acceleration
      time - Time; time
    • add

      public void add​(Length position, Speed speed, Acceleration acceleration, Time time, G gtu)
      Adds values of position, speed, acceleration and time.
      Parameters:
      position - Length; position is relative to the start of the lane in the direction of the design line, i.e. irrespective of the travel direction, also when trajectories have been truncated at a position x > 0
      speed - Speed; speed
      acceleration - Acceleration; acceleration
      time - Time; time
      gtu - G; gtu to add extended data for
    • size

      public int size()
      Returns:
      size of the underlying trajectory data
    • getGtuId

      public java.lang.String getGtuId()
      Returns:
      GTU id
    • getX

      public float[] getX()
      Returns:
      si position values, position is relative to the start of the lane, also when trajectories have been truncated at a position x > 0
    • getV

      public float[] getV()
      Returns:
      si speed values
    • getA

      public float[] getA()
      Returns:
      si acceleration values
    • getT

      public float[] getT()
      Returns:
      si time values
    • binarySearchX

      public int binarySearchX​(float position)
      Returns the last index with a position smaller than or equal to the given position.
      Parameters:
      position - float; position
      Returns:
      int; last index with a position smaller than or equal to the given position
    • binarySearchT

      public int binarySearchT​(float time)
      Returns the last index with a time smaller than or equal to the given time.
      Parameters:
      time - float; time
      Returns:
      int; last index with a time smaller than or equal to the given time
    • getX

      public float getX​(int index) throws SamplingException
      Returns x value of a single sample.
      Parameters:
      index - int; index
      Returns:
      x value of a single sample
      Throws:
      SamplingException - if the index is out of bounds
    • getV

      public float getV​(int index) throws SamplingException
      Returns v value of a single sample.
      Parameters:
      index - int; index
      Returns:
      v value of a single sample
      Throws:
      SamplingException - if the index is out of bounds
    • getA

      public float getA​(int index) throws SamplingException
      Returns a value of a single sample.
      Parameters:
      index - int; index
      Returns:
      a value of a single sample
      Throws:
      SamplingException - if the index is out of bounds
    • getT

      public float getT​(int index) throws SamplingException
      Returns t value of a single sample.
      Parameters:
      index - int; index
      Returns:
      t value of a single sample
      Throws:
      SamplingException - if the index is out of bounds
    • getExtendedData

      public <T,​ S> T getExtendedData​(ExtendedDataType<T,​?,​S,​?> extendedDataType, int index) throws SamplingException
      Returns extended data type value of a single sample.
      Type Parameters:
      T - scalar type of extended data type
      S - storage type of extended data type
      Parameters:
      extendedDataType - ExtendedDataType<T,?,S,?>; data type from which to retrieve the data
      index - int; index for which to retrieve the data
      Returns:
      extended data type value of a single sample
      Throws:
      SamplingException - if the index is out of bounds
    • getPosition

      public FloatLengthVector getPosition()
      Returns:
      strongly typed copy of position, position is relative to the start of the lane, also when trajectories have been truncated at a position x > 0
    • getSpeed

      public FloatSpeedVector getSpeed()
      Returns:
      strongly typed copy of speed
    • getAcceleration

      public FloatAccelerationVector getAcceleration()
      Returns:
      strongly typed copy of acceleration
    • getTime

      public FloatTimeVector getTime()
      Returns:
      strongly typed copy of time
    • getTotalLength

      public Length getTotalLength()
      Returns:
      total length of this trajectory
      Throws:
      java.lang.IllegalStateException - if trajectory is empty
    • getTotalDuration

      public Duration getTotalDuration()
      Returns:
      total duration of this trajectory
      Throws:
      java.lang.IllegalStateException - if trajectory is empty
    • contains

      public boolean contains​(MetaDataType<?> metaDataType)
      Parameters:
      metaDataType - MetaDataType<?>; meta data type
      Returns:
      whether the trajectory contains the meta data of give type
    • getMetaData

      public <T> T getMetaData​(MetaDataType<T> metaDataType)
      Type Parameters:
      T - class of meta data
      Parameters:
      metaDataType - MetaDataType<T>; meta data type
      Returns:
      value of meta data
    • getMetaDataTypes

      public java.util.Set<MetaDataType<?>> getMetaDataTypes()
      Returns the included meta data types.
      Returns:
      included meta data types
    • contains

      public boolean contains​(ExtendedDataType<?,​?,​?,​?> extendedDataType)
      Parameters:
      extendedDataType - ExtendedDataType<?,?,?,?>; extended data type
      Returns:
      whether the trajectory contains the extended data of give type
    • getExtendedData

      public <O,​ S> O getExtendedData​(ExtendedDataType<?,​O,​S,​?> extendedDataType) throws SamplingException
      Type Parameters:
      O - output type
      S - storage type
      Parameters:
      extendedDataType - ExtendedDataType<?,O,S,?>; extended data type to return
      Returns:
      values of extended data type
      Throws:
      SamplingException - if the extended data type is not in the trajectory
    • getExtendedDataTypes

      public java.util.Set<ExtendedDataType<?,​?,​?,​G>> getExtendedDataTypes()
      Returns the included extended data types.
      Returns:
      included extended data types
    • getSpaceTimeView

      public Trajectory.SpaceTimeView getSpaceTimeView​(Length startPosition, Length endPosition, Time startTime, Time endTime)
      Returns a space-time view of this trajectory. This is much more efficient than subSet() as no trajectory is copied. The limitation is that only distance and time (and mean speed) in the space-time view can be obtained.
      Parameters:
      startPosition - Length; start position
      endPosition - Length; end position
      startTime - Time; start time
      endTime - Time; end time
      Returns:
      space-time view of this trajectory
    • subSet

      public Trajectory<G> subSet​(Length startPosition, Length endPosition)
      Copies the trajectory but with a subset of the data. Longitudinal entry is only true if the original trajectory has true, and the subset is from the start.
      Parameters:
      startPosition - Length; start position
      endPosition - Length; end position
      Returns:
      subset of the trajectory
      Throws:
      java.lang.NullPointerException - if an input is null
      java.lang.IllegalArgumentException - of minLength is smaller than maxLength
    • subSet

      public Trajectory<G> subSet​(Time startTime, Time endTime)
      Copies the trajectory but with a subset of the data.
      Parameters:
      startTime - Time; start time
      endTime - Time; end time
      Returns:
      subset of the trajectory
      Throws:
      java.lang.NullPointerException - if an input is null
      java.lang.IllegalArgumentException - of minTime is smaller than maxTime
    • subSet

      public Trajectory<G> subSet​(Length startPosition, Length endPosition, Time startTime, Time endTime)
      Copies the trajectory but with a subset of the data.
      Parameters:
      startPosition - Length; start position
      endPosition - Length; end position
      startTime - Time; start time
      endTime - Time; end time
      Returns:
      subset of the trajectory
      Throws:
      java.lang.NullPointerException - if an input is null
      java.lang.IllegalArgumentException - of minLength/Time is smaller than maxLength/Time
    • getTimeAtPosition

      public Time getTimeAtPosition​(Length position)
      Returns an interpolated time at the given position.
      Parameters:
      position - Length; position
      Returns:
      Time; interpolated time at the given position
    • getSpeedAtPosition

      public Speed getSpeedAtPosition​(Length position)
      Returns an interpolated speed at the given position.
      Parameters:
      position - Length; position
      Returns:
      Speed; interpolated speed at the given position
    • getAccelerationAtPosition

      public Acceleration getAccelerationAtPosition​(Length position)
      Returns an interpolated acceleration at the given position.
      Parameters:
      position - Length; position
      Returns:
      Acceleration; interpolated acceleration at the given position
    • getPositionAtTime

      public Length getPositionAtTime​(Time time)
      Returns an interpolated position at the given time.
      Parameters:
      time - Time; time
      Returns:
      Length; interpolated position at the given time
    • getSpeedAtTime

      public Speed getSpeedAtTime​(Time time)
      Returns an interpolated speed at the given time.
      Parameters:
      time - Time; time
      Returns:
      Speed; interpolated speed at the given time
    • getAccelerationAtTime

      public Acceleration getAccelerationAtTime​(Time time)
      Returns an interpolated acceleration at the given time.
      Parameters:
      time - Time; time
      Returns:
      Acceleration; interpolated acceleration at the given time
    • 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
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object