Package org.opentrafficsim.road.od
Class OdMatrix
java.lang.Object
org.opentrafficsim.road.od.OdMatrix
- All Implemented Interfaces:
Serializable
,org.djutils.base.Identifiable
The minimal OD matrix has 1 origin, 1 destination and 1 time period. More of each can be used. Further categorization of data
is possible, i.e. for origin O to destination D, for lane L, for route R and for vehicle class C, the demand at time T
is D. The further categorization is defined by an array of
Class
's that define the categorization.
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
- See Also:
-
Constructor Summary
ConstructorDescriptionOdMatrix
(String id, List<? extends Node> origins, List<? extends Node> destinations, Categorization categorization, org.djunits.value.vdouble.vector.TimeVector globalTimeVector, Interpolation globalInterpolation) Constructs an OD matrix. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
final int
destinationTotal
(Node destination) Calculates total number of trips over time for given destination.final boolean
getCategories
(Node origin, Node destination) Returns the categories specified for given origin-destination combination.final Categorization
final org.djunits.value.vdouble.scalar.Frequency
getDemand
(Node origin, Node destination, Category category, org.djunits.value.vdouble.scalar.Time time, boolean sliceStart) Returns the demand at given time.getDemandPattern
(Node origin, Node destination, Category category) final org.djunits.value.vdouble.vector.FrequencyVector
getDemandVector
(Node origin, Node destination, Category category) final Interpolation
final org.djunits.value.vdouble.vector.TimeVector
final String
getId()
final Interpolation
getInterpolation
(Node origin, Node destination, Category category) final org.djunits.value.vdouble.vector.TimeVector
getTimeVector
(Node origin, Node destination, Category category) final int
Returns the number of trips in the given time period.final int[]
getTripsVector
(Node origin, Node destination, Category category) final int
hashCode()
final void
increaseTrips
(Node origin, Node destination, Category category, int periodIndex, int trips) Adds a number of trips to given origin-destination combination, category and time period.final int
Calculates total number of trips over time for the complete matrix.final int
originDestinationTotal
(Node origin, Node destination) Calculates total number of trips over time for given origin-destination combination.final int
originTotal
(Node origin) Calculates total number of trips over time for given origin.final void
print()
Prints the complete OD matrix with each demand data on a single line.final void
putDemandVector
(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand) Add a demand vector to OD.final void
putDemandVector
(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, double fraction) Add a demand vector to OD.final void
putDemandVector
(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation) Add a demand vector to OD.final void
putDemandVector
(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation, double fraction) Add a demand vector to OD, by a fraction of total demand.final void
putDemandVector
(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation, double[] fraction) Add a demand vector to OD, by a fraction per time period of total demand.final void
putTripsVector
(Node origin, Node destination, Category category, int[] trips) final void
putTripsVector
(Node origin, Node destination, Category category, int[] trips, org.djunits.value.vdouble.vector.TimeVector timeVector) Sets demand data by number of trips.toString()
-
Constructor Details
-
OdMatrix
public OdMatrix(String id, List<? extends Node> origins, List<? extends Node> destinations, Categorization categorization, org.djunits.value.vdouble.vector.TimeVector globalTimeVector, Interpolation globalInterpolation) Constructs an OD matrix.- Parameters:
id
- String; idorigins
- List<? extends Node>; origin nodesdestinations
- List<? extends Node>; destination nodescategorization
- Categorization; categorization of dataglobalTimeVector
- TimeVector; default timeglobalInterpolation
- Interpolation; interpolation of demand data- Throws:
NullPointerException
- if any input is null
-
-
Method Details
-
getId
- Specified by:
getId
in interfaceorg.djutils.base.Identifiable
- Returns:
- id.
-
getOrigins
- Returns:
- origins.
-
getDestinations
- Returns:
- destinations.
-
getCategorization
- Returns:
- categorization.
-
getGlobalTimeVector
public final org.djunits.value.vdouble.vector.TimeVector getGlobalTimeVector()- Returns:
- globalTimeVector.
-
getGlobalInterpolation
- Returns:
- globalInterpolation.
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, double fraction) Add a demand vector to OD.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorydemand
- FrequencyVector; demand data, length has to be equal to the global time vectorfraction
- double; fraction of demand for this category- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand) Add a demand vector to OD.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorydemand
- FrequencyVector; demand data, length has to be equal to the global time vector- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation) Add a demand vector to OD. In this method, which all other methods that add or put demand indirectly refer to, many consistency and validity checks are performed. These do not include checks on network connectivity, since the network may be subject to change during simulation.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorydemand
- FrequencyVector; demand data, length has to be equal to the time vectortimeVector
- TimeVector; time vectorinterpolation
- Interpolation; interpolation- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation, double fraction) Add a demand vector to OD, by a fraction of total demand.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorydemand
- FrequencyVector; demand data, length has to be equal to the time vectortimeVector
- TimeVector; time vectorinterpolation
- Interpolation; interpolationfraction
- double; fraction of demand for this category- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, org.djunits.value.vdouble.vector.FrequencyVector demand, org.djunits.value.vdouble.vector.TimeVector timeVector, Interpolation interpolation, double[] fraction) Add a demand vector to OD, by a fraction per time period of total demand.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorydemand
- FrequencyVector; demand data, length has to be equal to the time vectortimeVector
- TimeVector; time vectorinterpolation
- Interpolation; interpolationfraction
- double[]; fraction of demand for this category- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
getDemandVector
public final org.djunits.value.vdouble.vector.FrequencyVector getDemandVector(Node origin, Node destination, Category category) - Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- demand data for given origin, destination and categorization,
null
if no data is given - Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getTimeVector
public final org.djunits.value.vdouble.vector.TimeVector getTimeVector(Node origin, Node destination, Category category) - Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- interpolation for given origin, destination and categorization,
null
if no data is given - Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getInterpolation
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- interpolation for given origin, destination and categorization,
null
if no data is given - Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getDemand
public final org.djunits.value.vdouble.scalar.Frequency getDemand(Node origin, Node destination, Category category, org.djunits.value.vdouble.scalar.Time time, boolean sliceStart) Returns the demand at given time. If given time is before the first time slice or after the last time slice, 0 demand is returned.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorytime
- Time; timesliceStart
- boolean; whether the time is at the start of an arbitrary time slice- Returns:
- demand for given origin, destination and categorization, at given time
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getDemandPattern
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- OD entry for given origin, destination and categorization.
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
contains
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- whether there is data for the specified origin, destination and category
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getCategories
Returns the categories specified for given origin-destination combination.- Parameters:
origin
- Node; origindestination
- Node; destination- Returns:
- categories specified for given origin-destination combination
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixNullPointerException
- if an input is null
-
putTripsVector
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorytrips
- int[]; trip data, length has to be equal to the global time vector - 1, each value is the number of trips during a period- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
putTripsVector
public final void putTripsVector(Node origin, Node destination, Category category, int[] trips, org.djunits.value.vdouble.vector.TimeVector timeVector) Sets demand data by number of trips. Interpolation over time is stepwise.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categorytrips
- int[]; trip data, length has to be equal to the time vector - 1, each value is the number of trips during a periodtimeVector
- TimeVector; time vector- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIllegalArgumentException
- if the demand data has a different length than time data, or is less than 2IllegalArgumentException
- if demand is negative or time not strictly increasingIllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationNullPointerException
- if an input is null
-
getTripsVector
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- trip data for given origin, destination and categorization,
null
if no data is given - Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationNullPointerException
- if an input is null
-
getTrips
Returns the number of trips in the given time period.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categoryperiodIndex
- int; index of time period- Returns:
- demand for given origin, destination and categorization, at given time
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIndexOutOfBoundsException
- if the period is outside of the specified rangeNullPointerException
- if an input is null
-
increaseTrips
public final void increaseTrips(Node origin, Node destination, Category category, int periodIndex, int trips) Adds a number of trips to given origin-destination combination, category and time period. This can only be done for data with stepwise interpolation.- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; categoryperiodIndex
- int; index of time periodtrips
- int; trips to add (may be negative)- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixIllegalArgumentException
- if the category does not belong to the categorizationIndexOutOfBoundsException
- if the period is outside of the specified rangeUnsupportedOperationException
- if the interpolation of the data is not stepwise, or demand becomes negtiveNullPointerException
- if an input is null
-
originTotal
Calculates total number of trips over time for given origin.- Parameters:
origin
- Node; origin- Returns:
- total number of trips over time for given origin
- Throws:
IllegalArgumentException
- if origin is not part of the OD matrixNullPointerException
- if origin is null
-
destinationTotal
Calculates total number of trips over time for given destination.- Parameters:
destination
- Node; destination- Returns:
- total number of trips over time for given destination
- Throws:
IllegalArgumentException
- if destination is not part of the OD matrixNullPointerException
- if destination is null
-
matrixTotal
public final int matrixTotal()Calculates total number of trips over time for the complete matrix.- Returns:
- total number of trips over time for the complete matrix
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixNullPointerException
- if an input is null
-
originDestinationTotal
Calculates total number of trips over time for given origin-destination combination.- Parameters:
origin
- Node; origindestination
- Node; destination- Returns:
- total number of trips over time for given origin-destination combination
- Throws:
IllegalArgumentException
- if origin or destination is not part of the OD matrixNullPointerException
- if an input is null
-
toString
-
print
public final void print()Prints the complete OD matrix with each demand data on a single line. -
hashCode
public final int hashCode() -
equals
-