Package org.opentrafficsim.kpi.sampling
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.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Trajectory.Boundary
Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.static class
Trajectory.SpaceTimeView
Space-time view of a trajectory. -
Constructor Summary
Constructors Constructor Description Trajectory(GtuDataInterface gtu, MetaData metaData, java.util.Set<ExtendedDataType<?,?,?,G>> extendedData, KpiLaneDirection kpiLaneDirection)
-
Method Summary
Modifier and Type Method Description void
add(Length position, Speed speed, Acceleration acceleration, Time time)
Adds values of position, speed, acceleration and time.void
add(Length position, Speed speed, Acceleration acceleration, 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)
boolean
contains(MetaDataType<?> metaDataType)
boolean
equals(java.lang.Object obj)
float[]
getA()
float
getA(int index)
Returnsa
value of a single sample.FloatAccelerationVector
getAcceleration()
Acceleration
getAccelerationAtPosition(Length position)
Returns an interpolated acceleration at the given position.Acceleration
getAccelerationAtTime(Time time)
Returns an interpolated acceleration at the given time.<O, S> O
getExtendedData(ExtendedDataType<?,O,S,?> extendedDataType)
<T, S> T
getExtendedData(ExtendedDataType<T,?,S,?> extendedDataType, int index)
Returns extended data type value of a single sample.java.util.Set<ExtendedDataType<?,?,?,G>>
getExtendedDataTypes()
Returns the included extended data types.java.lang.String
getGtuId()
<T> T
getMetaData(MetaDataType<T> metaDataType)
java.util.Set<MetaDataType<?>>
getMetaDataTypes()
Returns the included meta data types.FloatLengthVector
getPosition()
Length
getPositionAtTime(Time time)
Returns an interpolated position at the given time.Trajectory.SpaceTimeView
getSpaceTimeView(Length startPosition, Length endPosition, Time startTime, Time endTime)
Returns a space-time view of this trajectory.FloatSpeedVector
getSpeed()
Speed
getSpeedAtPosition(Length position)
Returns an interpolated speed at the given position.Speed
getSpeedAtTime(Time time)
Returns an interpolated speed at the given time.float[]
getT()
float
getT(int index)
Returnst
value of a single sample.FloatTimeVector
getTime()
Time
getTimeAtPosition(Length position)
Returns an interpolated time at the given position.Duration
getTotalDuration()
Length
getTotalLength()
float[]
getV()
float
getV(int index)
Returnsv
value of a single sample.float[]
getX()
float
getX(int index)
Returnsx
value of a single sample.int
hashCode()
int
size()
Trajectory<G>
subSet(Length startPosition, Length endPosition)
Copies the trajectory but with a subset of the data.Trajectory<G>
subSet(Length startPosition, Length endPosition, Time startTime, Time endTime)
Copies the trajectory but with a subset of the data.Trajectory<G>
subSet(Time startTime, Time endTime)
Copies the trajectory but with a subset of the data.java.lang.String
toString()
-
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 dataextendedData
- Set<ExtendedDataType<?,?,?,G>>; types of extended datakpiLaneDirection
- KpiLaneDirection; direction of travel
-
-
Method Details
-
add
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 > 0speed
- Speed; speedacceleration
- Acceleration; accelerationtime
- Time; time
-
add
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 > 0speed
- Speed; speedacceleration
- Acceleration; accelerationtime
- Time; timegtu
- 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
Returnsx
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
Returnsv
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
Returnsa
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
Returnst
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 SamplingExceptionReturns extended data type value of a single sample.- Type Parameters:
T
- scalar type of extended data typeS
- storage type of extended data type- Parameters:
extendedDataType
- ExtendedDataType<T,?,S,?>; data type from which to retrieve the dataindex
- 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
- 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
- Returns:
- strongly typed copy of speed
-
getAcceleration
- Returns:
- strongly typed copy of acceleration
-
getTime
- Returns:
- strongly typed copy of time
-
getTotalLength
- Returns:
- total length of this trajectory
- Throws:
java.lang.IllegalStateException
- if trajectory is empty
-
getTotalDuration
- Returns:
- total duration of this trajectory
- Throws:
java.lang.IllegalStateException
- if trajectory is empty
-
contains
- Parameters:
metaDataType
- MetaDataType<?>; meta data type- Returns:
- whether the trajectory contains the meta data of give type
-
getMetaData
- Type Parameters:
T
- class of meta data- Parameters:
metaDataType
- MetaDataType<T>; meta data type- Returns:
- value of meta data
-
getMetaDataTypes
Returns the included meta data types.- Returns:
- included meta data types
-
contains
- 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 typeS
- 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
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 thansubSet()
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 positionendPosition
- Length; end positionstartTime
- Time; start timeendTime
- Time; end time- Returns:
- space-time view of this trajectory
-
subSet
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 positionendPosition
- Length; end position- Returns:
- subset of the trajectory
- Throws:
java.lang.NullPointerException
- if an input is nulljava.lang.IllegalArgumentException
- of minLength is smaller than maxLength
-
subSet
Copies the trajectory but with a subset of the data.- Parameters:
startTime
- Time; start timeendTime
- Time; end time- Returns:
- subset of the trajectory
- Throws:
java.lang.NullPointerException
- if an input is nulljava.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 positionendPosition
- Length; end positionstartTime
- Time; start timeendTime
- Time; end time- Returns:
- subset of the trajectory
- Throws:
java.lang.NullPointerException
- if an input is nulljava.lang.IllegalArgumentException
- of minLength/Time is smaller than maxLength/Time
-
getTimeAtPosition
Returns an interpolated time at the given position.- Parameters:
position
- Length; position- Returns:
- Time; interpolated time at the given position
-
getSpeedAtPosition
Returns an interpolated speed at the given position.- Parameters:
position
- Length; position- Returns:
- Speed; interpolated speed at the given position
-
getAccelerationAtPosition
Returns an interpolated acceleration at the given position.- Parameters:
position
- Length; position- Returns:
- Acceleration; interpolated acceleration at the given position
-
getPositionAtTime
Returns an interpolated position at the given time.- Parameters:
time
- Time; time- Returns:
- Length; interpolated position at the given time
-
getSpeedAtTime
Returns an interpolated speed at the given time.- Parameters:
time
- Time; time- Returns:
- Speed; interpolated speed at the given time
-
getAccelerationAtTime
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-