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.
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 ClassesModifier and TypeClassDescriptionstatic final recordSpace-time view of a trajectory. -
Constructor Summary
ConstructorsConstructorDescriptionTrajectory(GtuData gtu, Map<FilterDataType<?, ? super G>, Object> filterData, Set<ExtendedDataType<?, ?, ?, ? super G>> extendedData) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Length position, Speed speed, Acceleration acceleration, Duration time) Adds values of position, speed, acceleration and time.voidAdds values of position, speed, acceleration, time and extended data.intbinarySearchT(float time) Returns the last index with a time smaller than or equal to the given time.intbinarySearchX(float position) Returns the last index with a position smaller than or equal to the given position.booleancontains(ExtendedDataType<?, ?, ?, ?> extendedDataType) Returns whether ths extended data type is contained.booleancontains(FilterDataType<?, ?> filterDataType) Returns whether the filter data is contained.booleanfloat[]getA()Returns the acceleration array.floatgetA(int index) Returnsavalue of a single sample.Returns strongly typed acceleration array.getAccelerationAtPosition(Length position) Returns an interpolated acceleration at the given position.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> TgetFilterData(FilterDataType<T, ?> filterDataType) Returns the value of the filter data.Set<FilterDataType<?,? super G>> Returns the included filter data types.getGtuId()Returns the GTU id.Returns the GTU type id.Returns strongly type position array.getPositionAtTime(Duration time) Returns an interpolated position at the given time.Returns a space-time view of this trajectory.getSpaceTimeView(Length startPosition, Length endPosition, Duration startTime, Duration endTime) Returns a space-time view of this trajectory as contained within the defined space-time region.getSpeed()Returns strongly typed speed array.getSpeedAtPosition(Length position) Returns an interpolated speed at the given position.getSpeedAtTime(Duration time) Returns an interpolated speed at the given time.float[]getT()Returns the time array.floatgetT(int index) Returnstvalue of a single sample.getTime()Returns strongly typed time array.getTimeAtPosition(Length position) Returns an interpolated time at the given position.Returns the total duration span.Returns the length of the data.float[]getV()Returns the speed array.floatgetV(int index) Returnsvvalue of a single sample.float[]getX()Returns the position array.floatgetX(int index) Returnsxvalue of a single sample.inthashCode()intsize()The size of the underlying data.Copies the trajectory but with a subset of the data.Copies the trajectory but with a subset of the data.Copies the trajectory but with a subset of the data that is contained in the given space-time region.toString()
-
Constructor Details
-
Trajectory
public Trajectory(GtuData gtu, Map<FilterDataType<?, ? super G>, Object> filterData, Set<ExtendedDataType<?, ?, ?, ? super G>> extendedData) Constructor.- Parameters:
gtu- GTU of this trajectory, only the id is stored.filterData- filter dataextendedData- types of extended data
-
-
Method Details
-
add
Adds values of position, speed, acceleration and time.- Parameters:
position- 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- speedacceleration- accelerationtime- time
-
add
Adds values of position, speed, acceleration, time and extended data.- Parameters:
position- position is relative to the start of the lane in the direction of the design linespeed- speedacceleration- accelerationtime- timegtu- 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 GTU id.- Returns:
- GTU id
-
getGtuTypeId
Returns the GTU type id.- Returns:
- GTU type 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- position- Returns:
- 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- time- Returns:
- last index with a time smaller than or equal to the given time
-
getX
public float getX(int index) Returnsxvalue of a single sample.- Parameters:
index- index- Returns:
xvalue of a single sample
-
getV
public float getV(int index) Returnsvvalue of a single sample.- Parameters:
index- index- Returns:
vvalue of a single sample
-
getA
public float getA(int index) Returnsavalue of a single sample.- Parameters:
index- index- Returns:
avalue of a single sample
-
getT
public float getT(int index) Returnstvalue of a single sample.- Parameters:
index- index- Returns:
tvalue of a single sample
-
getExtendedData
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- data type from which to retrieve the dataindex- index for which to retrieve the data- Returns:
- extended data type value of a single sample
-
getPosition
Returns strongly type position array.- Returns:
- strongly typed position array.
-
getSpeed
Returns strongly typed speed array.- Returns:
- strongly typed speed array.
-
getAcceleration
Returns strongly typed acceleration array.- Returns:
- strongly typed acceleration array.
-
getTime
Returns strongly typed time array.- Returns:
- strongly typed time array.
-
getTotalLength
Returns the length of the data.- Returns:
- total length of this trajectory
-
getTotalDuration
Returns the total duration span.- Returns:
- total duration of this trajectory
-
contains
Returns whether the filter data is contained.- Parameters:
filterDataType- 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- 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- 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- 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
Returns a space-time view of this trajectory. This is much more efficient thangetX()as no array is copied. The limitation is that only distance and time (and mean speed) in the space-time view can be obtained.- Returns:
- space-time view of this trajectory
-
getSpaceTimeView
public Trajectory.SpaceTimeView getSpaceTimeView(Length startPosition, Length endPosition, Duration startTime, Duration endTime) Returns a space-time view of this trajectory as contained within the defined space-time region. 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- start positionendPosition- end positionstartTime- start timeendTime- 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- start positionendPosition- end position- Returns:
- subset of the trajectory
- Throws:
NullPointerException- if an input is nullIllegalArgumentException- of minLength is smaller than maxLength
-
subSet
Copies the trajectory but with a subset of the data.- Parameters:
startTime- start timeendTime- 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, Duration startTime, Duration endTime) Copies the trajectory but with a subset of the data that is contained in the given space-time region.- Parameters:
startPosition- start positionendPosition- end positionstartTime- start timeendTime- end time- Returns:
- subset of the trajectory
- Throws:
NullPointerException- if an input is nullIllegalArgumentException- of minLength/Time is smaller than maxLength/Time
-
getTimeAtPosition
Returns an interpolated time at the given position.- Parameters:
position- position- Returns:
- interpolated time at the given position
-
getSpeedAtPosition
Returns an interpolated speed at the given position.- Parameters:
position- position- Returns:
- interpolated speed at the given position
-
getAccelerationAtPosition
Returns an interpolated acceleration at the given position.- Parameters:
position- position- Returns:
- interpolated acceleration at the given position
-
getPositionAtTime
Returns an interpolated position at the given time.- Parameters:
time- time- Returns:
- interpolated position at the given time
-
getSpeedAtTime
Returns an interpolated speed at the given time.- Parameters:
time- time- Returns:
- interpolated speed at the given time
-
getAccelerationAtTime
Returns an interpolated acceleration at the given time.- Parameters:
time- time- Returns:
- interpolated acceleration at the given time
-
hashCode
public int hashCode() -
equals
-
toString
-