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 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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Sep 21, 2016
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-2020 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, Set<ExtendedDataType<?,?,?,G>> extendedData, KpiLaneDirection kpiLaneDirection)
-
Method Summary
All Methods Instance Methods Concrete Methods 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(FilterDataType<?> metaDataType)
boolean
equals(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>
OgetExtendedData(ExtendedDataType<?,O,S,?> extendedDataType)
<T,S>
TgetExtendedData(ExtendedDataType<T,?,S,?> extendedDataType, int index)
Returns extended data type value of a single sample.Set<ExtendedDataType<?,?,?,G>>
getExtendedDataTypes()
Returns the included extended data types.Set<FilterDataType<?>>
getFilterDataTypes()
Returns the included meta data types.String
getGtuId()
<T> T
getMetaData(FilterDataType<T> metaDataType)
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.String
toString()
-
-
-
Constructor Detail
-
Trajectory
public Trajectory(GtuDataInterface gtu, MetaData metaData, 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 Detail
-
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 > 0speed
- Speed; speedacceleration
- Acceleration; accelerationtime
- 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 > 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 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
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
public float getV(int index) throws SamplingException
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
public float getA(int index) throws SamplingException
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
public float getT(int index) throws SamplingException
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 SamplingException
Returns 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
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:
IllegalStateException
- if trajectory is empty
-
getTotalDuration
public Duration getTotalDuration()
- Returns:
- total duration of this trajectory
- Throws:
IllegalStateException
- if trajectory is empty
-
contains
public boolean contains(FilterDataType<?> metaDataType)
- Parameters:
metaDataType
- MetaDataType<?>; meta data type- Returns:
- whether the trajectory contains the meta data of give type
-
getMetaData
public <T> T getMetaData(FilterDataType<T> metaDataType)
- Type Parameters:
T
- class of meta data- Parameters:
metaDataType
- MetaDataType<T>; meta data type- Returns:
- value of meta data
-
getFilterDataTypes
public Set<FilterDataType<?>> getFilterDataTypes()
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 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
public 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 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
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 positionendPosition
- Length; end position- Returns:
- subset of the trajectory
- Throws:
NullPointerException
- if an input is nullIllegalArgumentException
- 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 timeendTime
- Time; end time- Returns:
- subset of the trajectory
- Throws:
NullPointerException
- if an input is nullIllegalArgumentException
- 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:
NullPointerException
- if an input is nullIllegalArgumentException
- 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
-
-