Class Trajectory<G extends GtuData>

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

public final class Trajectory<G extends GtuData> extends 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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Spatial or temporal boundary as a fractional position in the array.
    static final class 
    Space-time view of a trajectory.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Trajectory(GtuData gtu, Map<FilterDataType<?,? super G>,Object> filterData, Set<ExtendedDataType<?,?,?,? super G>> extendedData, LaneData<?> lane)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(org.djunits.value.vdouble.scalar.Length position, org.djunits.value.vdouble.scalar.Speed speed, org.djunits.value.vdouble.scalar.Acceleration acceleration, org.djunits.value.vdouble.scalar.Time time)
    Adds values of position, speed, acceleration and time.
    void
    add(org.djunits.value.vdouble.scalar.Length position, org.djunits.value.vdouble.scalar.Speed speed, org.djunits.value.vdouble.scalar.Acceleration acceleration, org.djunits.value.vdouble.scalar.Time time, G gtu)
    Adds values of position, speed, acceleration and time.
    int
    binarySearchT(float time)
    Returns the last index with a time smaller than or equal to the given time.
    int
    binarySearchX(float position)
    Returns the last index with a position smaller than or equal to the given position.
    boolean
    contains(ExtendedDataType<?,?,?,?> extendedDataType)
    Returns whether ths extended data type is contained.
    boolean
    contains(FilterDataType<?,?> filterDataType)
    Returns whether the filter data is contained.
    boolean
    float[]
    Returns the acceleration array.
    float
    getA(int index)
    Returns a value of a single sample.
    org.djunits.value.vfloat.vector.FloatAccelerationVector
    Returns strongly typed acceleration array.
    org.djunits.value.vdouble.scalar.Acceleration
    getAccelerationAtPosition(org.djunits.value.vdouble.scalar.Length position)
    Returns an interpolated acceleration at the given position.
    org.djunits.value.vdouble.scalar.Acceleration
    getAccelerationAtTime(org.djunits.value.vdouble.scalar.Time time)
    Returns an interpolated acceleration at the given time.
    <O, S> O
    getExtendedData(ExtendedDataType<?,O,S,?> extendedDataType)
    Returns the output data of the extended data type.
    <T, S> T
    getExtendedData(ExtendedDataType<T,?,S,?> extendedDataType, int index)
    Returns extended data type value of a single sample.
    Set<ExtendedDataType<?,?,?,? super G>>
    Returns the included extended data types.
    <T> T
    getFilterData(FilterDataType<T,?> filterDataType)
    Returns the value of the filter data.
    Set<FilterDataType<?,? super G>>
    Returns the included filter data types.
    Returns the id.
    org.djunits.value.vfloat.vector.FloatLengthVector
    Returns strongly type position array.
    org.djunits.value.vdouble.scalar.Length
    getPositionAtTime(org.djunits.value.vdouble.scalar.Time time)
    Returns an interpolated position at the given time.
    getSpaceTimeView(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.Length endPosition, org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.Time endTime)
    Returns a space-time view of this trajectory.
    org.djunits.value.vfloat.vector.FloatSpeedVector
    Returns strongly typed speed array.
    org.djunits.value.vdouble.scalar.Speed
    getSpeedAtPosition(org.djunits.value.vdouble.scalar.Length position)
    Returns an interpolated speed at the given position.
    org.djunits.value.vdouble.scalar.Speed
    getSpeedAtTime(org.djunits.value.vdouble.scalar.Time time)
    Returns an interpolated speed at the given time.
    float[]
    Returns the time array.
    float
    getT(int index)
    Returns t value of a single sample.
    org.djunits.value.vfloat.vector.FloatTimeVector
    Returns strongly typed time array.
    org.djunits.value.vdouble.scalar.Time
    getTimeAtPosition(org.djunits.value.vdouble.scalar.Length position)
    Returns an interpolated time at the given position.
    org.djunits.value.vdouble.scalar.Duration
    Returns the total duration span.
    org.djunits.value.vdouble.scalar.Length
    Returns the length of the data.
    float[]
    Returns the speed array.
    float
    getV(int index)
    Returns v value of a single sample.
    float[]
    Returns the position array.
    float
    getX(int index)
    Returns x value of a single sample.
    int
    int
    The size of the underlying data.
    subSet(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.Length endPosition)
    Copies the trajectory but with a subset of the data.
    subSet(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.Length endPosition, org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.Time endTime)
    Copies the trajectory but with a subset of the data.
    subSet(org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.Time endTime)
    Copies the trajectory but with a subset of the data.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Trajectory

      public Trajectory(GtuData gtu, Map<FilterDataType<?,? super G>,Object> filterData, Set<ExtendedDataType<?,?,?,? super G>> extendedData, LaneData<?> lane)
      Parameters:
      gtu - GtuData; GTU of this trajectory, only the id is stored.
      filterData - Map<FilterDataType<?, ? super G>, Object>; filter data
      extendedData - Set<ExtendedDataType<?, ? ,? , ? super G>>; types of extended data
      lane - LaneData<?>; lane of travel
  • Method Details

    • add

      public void add(org.djunits.value.vdouble.scalar.Length position, org.djunits.value.vdouble.scalar.Speed speed, org.djunits.value.vdouble.scalar.Acceleration acceleration, org.djunits.value.vdouble.scalar.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(org.djunits.value.vdouble.scalar.Length position, org.djunits.value.vdouble.scalar.Speed speed, org.djunits.value.vdouble.scalar.Acceleration acceleration, org.djunits.value.vdouble.scalar.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()
      The size of the underlying data.
      Returns:
      size of the underlying trajectory data
    • getGtuId

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

      public float[] getX()
      Returns the position array.
      Returns:
      si position values.
    • getV

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

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

      public float[] getT()
      Returns the time array.
      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 org.djunits.value.vfloat.vector.FloatLengthVector getPosition()
      Returns strongly type position array.
      Returns:
      strongly typed position array.
    • getSpeed

      public org.djunits.value.vfloat.vector.FloatSpeedVector getSpeed()
      Returns strongly typed speed array.
      Returns:
      strongly typed speed array.
    • getAcceleration

      public org.djunits.value.vfloat.vector.FloatAccelerationVector getAcceleration()
      Returns strongly typed acceleration array.
      Returns:
      strongly typed acceleration array.
    • getTime

      public org.djunits.value.vfloat.vector.FloatTimeVector getTime()
      Returns strongly typed time array.
      Returns:
      strongly typed time array.
    • getTotalLength

      public org.djunits.value.vdouble.scalar.Length getTotalLength()
      Returns the length of the data.
      Returns:
      total length of this trajectory
      Throws:
      IllegalStateException - if trajectory is empty
    • getTotalDuration

      public org.djunits.value.vdouble.scalar.Duration getTotalDuration()
      Returns the total duration span.
      Returns:
      total duration of this trajectory
      Throws:
      IllegalStateException - if trajectory is empty
    • contains

      public boolean contains(FilterDataType<?,?> filterDataType)
      Returns whether the filter data is contained.
      Parameters:
      filterDataType - MetaDataType<?, ?>; filter data type
      Returns:
      whether the trajectory contains the filter data of give type
    • getFilterData

      public <T> T getFilterData(FilterDataType<T,?> filterDataType)
      Returns the value of the filter data.
      Type Parameters:
      T - class of filter data
      Parameters:
      filterDataType - MetaDataType<T, ?>; filter data type
      Returns:
      value of filter data
    • getFilterDataTypes

      public Set<FilterDataType<?,? super G>> getFilterDataTypes()
      Returns the included filter data types.
      Returns:
      included filter data types
    • contains

      public boolean contains(ExtendedDataType<?,?,?,?> extendedDataType)
      Returns whether ths extended data type is contained.
      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
      Returns the output data of the extended data type.
      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 Set<ExtendedDataType<?,?,?,? super G>> getExtendedDataTypes()
      Returns the included extended data types.
      Returns:
      included extended data types
    • getSpaceTimeView

      public Trajectory.SpaceTimeView getSpaceTimeView(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.Length endPosition, org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.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(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.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:
      NullPointerException - if an input is null
      IllegalArgumentException - of minLength is smaller than maxLength
    • subSet

      public Trajectory<G> subSet(org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.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:
      NullPointerException - if an input is null
      IllegalArgumentException - of minTime is smaller than maxTime
    • subSet

      public Trajectory<G> subSet(org.djunits.value.vdouble.scalar.Length startPosition, org.djunits.value.vdouble.scalar.Length endPosition, org.djunits.value.vdouble.scalar.Time startTime, org.djunits.value.vdouble.scalar.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:
      NullPointerException - if an input is null
      IllegalArgumentException - of minLength/Time is smaller than maxLength/Time
    • getTimeAtPosition

      public org.djunits.value.vdouble.scalar.Time getTimeAtPosition(org.djunits.value.vdouble.scalar.Length position)
      Returns an interpolated time at the given position.
      Parameters:
      position - Length; position
      Returns:
      Time; interpolated time at the given position
    • getSpeedAtPosition

      public org.djunits.value.vdouble.scalar.Speed getSpeedAtPosition(org.djunits.value.vdouble.scalar.Length position)
      Returns an interpolated speed at the given position.
      Parameters:
      position - Length; position
      Returns:
      Speed; interpolated speed at the given position
    • getAccelerationAtPosition

      public org.djunits.value.vdouble.scalar.Acceleration getAccelerationAtPosition(org.djunits.value.vdouble.scalar.Length position)
      Returns an interpolated acceleration at the given position.
      Parameters:
      position - Length; position
      Returns:
      Acceleration; interpolated acceleration at the given position
    • getPositionAtTime

      public org.djunits.value.vdouble.scalar.Length getPositionAtTime(org.djunits.value.vdouble.scalar.Time time)
      Returns an interpolated position at the given time.
      Parameters:
      time - Time; time
      Returns:
      Length; interpolated position at the given time
    • getSpeedAtTime

      public org.djunits.value.vdouble.scalar.Speed getSpeedAtTime(org.djunits.value.vdouble.scalar.Time time)
      Returns an interpolated speed at the given time.
      Parameters:
      time - Time; time
      Returns:
      Speed; interpolated speed at the given time
    • getAccelerationAtTime

      public org.djunits.value.vdouble.scalar.Acceleration getAccelerationAtTime(org.djunits.value.vdouble.scalar.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 Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object