Class ODMatrix
java.lang.Object
org.opentrafficsim.road.gtu.strategical.od.ODMatrix
- All Implemented Interfaces:
java.io.Serializable
,Identifiable
public class ODMatrix extends java.lang.Object implements java.io.Serializable, 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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Sep 15, 2016
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ODMatrix(java.lang.String id, java.util.List<? extends Node> origins, java.util.List<? extends Node> destinations, Categorization categorization, TimeVector globalTimeVector, Interpolation globalInterpolation)
Constructs an OD matrix. -
Method Summary
Modifier and Type Method Description boolean
contains(Node origin, Node destination, Category category)
int
destinationTotal(Node destination)
Calculates total number of trips over time for given destination.boolean
equals(java.lang.Object obj)
java.util.Set<Category>
getCategories(Node origin, Node destination)
Returns the categories specified for given origin-destination combination.Categorization
getCategorization()
Frequency
getDemand(Node origin, Node destination, Category category, Time time, boolean sliceStart)
Returns the demand at given time.DemandPattern
getDemandPattern(Node origin, Node destination, Category category)
FrequencyVector
getDemandVector(Node origin, Node destination, Category category)
java.util.List<Node>
getDestinations()
Interpolation
getGlobalInterpolation()
TimeVector
getGlobalTimeVector()
java.lang.String
getId()
Interpolation
getInterpolation(Node origin, Node destination, Category category)
java.util.List<Node>
getOrigins()
TimeVector
getTimeVector(Node origin, Node destination, Category category)
int
getTrips(Node origin, Node destination, Category category, int periodIndex)
Returns the number of trips in the given time period.int[]
getTripsVector(Node origin, Node destination, Category category)
int
hashCode()
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.int
matrixTotal()
Calculates total number of trips over time for the complete matrix.int
originDestinationTotal(Node origin, Node destination)
Calculates total number of trips over time for given origin-destination combination.int
originTotal(Node origin)
Calculates total number of trips over time for given origin.void
print()
Prints the complete OD matrix with each demand data on a single line.void
putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand)
Add a demand vector to OD.void
putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, double fraction)
Add a demand vector to OD.void
putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, TimeVector timeVector, Interpolation interpolation)
Add a demand vector to OD.void
putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, TimeVector timeVector, Interpolation interpolation, double fraction)
Add a demand vector to OD, by a fraction of total demand.void
putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, TimeVector timeVector, Interpolation interpolation, double[] fraction)
Add a demand vector to OD, by a fraction per time period of total demand.void
putTripsVector(Node origin, Node destination, Category category, int[] trips)
void
putTripsVector(Node origin, Node destination, Category category, int[] trips, TimeVector timeVector)
Sets demand data by number of trips.java.lang.String
toString()
-
Constructor Details
-
ODMatrix
public ODMatrix(java.lang.String id, java.util.List<? extends Node> origins, java.util.List<? extends Node> destinations, Categorization categorization, 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:
java.lang.NullPointerException
- if any input is null
-
-
Method Details
-
getId
public final java.lang.String getId()- Specified by:
getId
in interfaceIdentifiable
- Returns:
- id.
-
getOrigins
- Returns:
- origins.
-
getDestinations
- Returns:
- destinations.
-
getCategorization
- Returns:
- categorization.
-
getGlobalTimeVector
- Returns:
- globalTimeVector.
-
getGlobalInterpolation
- Returns:
- globalInterpolation.
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
putDemandVector
public final void putDemandVector(Node origin, Node destination, Category category, FrequencyVector demand, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
getDemandVector
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- demand data for given origin, destination and categorization,
null
if no data is given - Throws:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- if an input is null
-
getTimeVector
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- interpolation for given origin, destination and categorization,
null
if no data is given - Throws:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- if an input is null
-
getDemand
public final Frequency getDemand(Node origin, Node destination, Category category, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- if an input is null
-
getDemandPattern
- Parameters:
origin
- Node; origindestination
- Node; destinationcategory
- Category; category- Returns:
- OD entry for given origin, destination and categorization.
- Throws:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- if an input is null
-
putTripsVector
public final void putTripsVector(Node origin, Node destination, Category category, int[] trips, 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IllegalArgumentException
- if the demand data has a different length than time data, or is less than 2java.lang.IllegalArgumentException
- if demand is negative or time not strictly increasingjava.lang.IllegalArgumentException
- if the route (if in the category) is not from the origin to the destinationjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IndexOutOfBoundsException
- if the period is outside of the specified rangejava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.IllegalArgumentException
- if the category does not belong to the categorizationjava.lang.IndexOutOfBoundsException
- if the period is outside of the specified rangejava.lang.UnsupportedOperationException
- if the interpolation of the data is not stepwise, or demand becomes negtivejava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin is not part of the OD matrixjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if destination is not part of the OD matrixjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.NullPointerException
- 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:
java.lang.IllegalArgumentException
- if origin or destination is not part of the OD matrixjava.lang.NullPointerException
- if an input is null
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
print
public final void print()Prints the complete OD matrix with each demand data on a single line. -
hashCode
public final int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-