Package org.opentrafficsim.kpi.sampling
Class Trajectory<G extends GtuData>
java.lang.Object
org.opentrafficsim.kpi.sampling.Trajectory<G>
- Type Parameters:
G
- gtu data type
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
Modifier and TypeClassDescriptionclass
Spatial or temporal boundary as a fractional position in the array.static final class
Space-time view of a trajectory. -
Constructor Summary
ConstructorDescriptionTrajectory
(GtuData gtu, Map<FilterDataType<?, ? super G>, Object> filterData, Set<ExtendedDataType<?, ?, ?, ? super G>> extendedData, LaneData<?> lane) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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[]
getA()
Returns the acceleration array.float
getA
(int index) Returnsa
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.getGtuId()
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
getSpeed()
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[]
getT()
Returns the time array.float
getT
(int index) Returnst
value of a single sample.org.djunits.value.vfloat.vector.FloatTimeVector
getTime()
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[]
getV()
Returns the speed array.float
getV
(int index) Returnsv
value of a single sample.float[]
getX()
Returns the position array.float
getX
(int index) Returnsx
value of a single sample.int
hashCode()
int
size()
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.toString()
-
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 dataextendedData
- Set<ExtendedDataType<?, ? ,? , ? super G>>; types of extended datalane
- 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 > 0speed
- Speed; speedacceleration
- Acceleration; accelerationtime
- 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 > 0speed
- Speed; speedacceleration
- Acceleration; accelerationtime
- Time; timegtu
- 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
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
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, ?, throws SamplingExceptionS, ?> extendedDataType, int index) 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 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
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
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
Returns the included filter data types.- Returns:
- included filter data types
-
contains
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, throws SamplingExceptionS, ?> extendedDataType) Returns the output data of the extended data type.- 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(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 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(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 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(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 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(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 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 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() -
equals
-
toString
-