ODMatrixArray

public class ODMatrixArray implements AssignableODMatrix

Origin-destination matrix for passenger vehicles.

Author:Milan Lovric

Constructors

ODMatrixArray

public ODMatrixArray(Zoning zoning)

Constructor.

Parameters:
  • zoning – Zoning system.

ODMatrixArray

public ODMatrixArray(RealODMatrix realMatrix, Zoning zoning)

Constructor that rounds the flows of a real-valued OD matrix.

Parameters:
  • realMatrix – Origin-destination matrix with real-valued flows.
  • zoning – Zoning system.

ODMatrixArray

public ODMatrixArray(String fileName, Zoning zoning)

Constructor that reads OD matrix from an input csv file.

Parameters:
  • fileName – Path to the input file.
  • zoning – Zoning system.
Throws:
  • IOException – if any.
  • FileNotFoundException – if any.

Methods

calculateTripEnds

public HashMap<String, Integer> calculateTripEnds()

Calculates the number of trips ending in each destination zone

Returns:Number of trip ends.

calculateTripStarts

public HashMap<String, Integer> calculateTripStarts()

Calculates the number of trips starting in each origin zone

Returns:Number of trip starts.

createLadMatrixFromTEMProMatrix

public static ODMatrixArray createLadMatrixFromTEMProMatrix(ODMatrixArrayTempro temproMatrix, Zoning zoning)

Creates LAD OD matrix from TEMPro OD matrix.

Parameters:
  • temproMatrix – TEMPro ODMatrix used as weights to disaggregate LAD matrix.
  • zoning – Zoning system with mapping between TEMPro and LAD zones.
Returns:

LAD based OD matrix.

createTEMProFromLadMatrix

public static ODMatrixArrayTempro createTEMProFromLadMatrix(ODMatrixArray ladODMatrix, ODMatrixArrayTempro baseTempro, Zoning zoning)

Creates tempro OD matrix from LAD OD matrix.

Parameters:
  • ladODMatrix – LAD to LAD OD matrix.
  • baseTempro – TEMPro ODMatrix used as weights to disaggregate LAD matrix.
  • zoning – Zoning system with mapping between TEMPro and LAD zones.
Returns:

TEMPro based OD matrix.

createUnitMatrix

public static ODMatrixArray createUnitMatrix(List<String> origins, List<String> destinations, Zoning zoning)

Creates a unit OD matrix for given lists of origin and destination zones.

Parameters:
  • origins – List of origin zones.
  • destinations – List of destination zones.
  • zoning – Zoning system.
Returns:

Unit OD matrix.

createUnitMatrix

public static ODMatrixArray createUnitMatrix(List<String> zones, Zoning zoning)

Creates a quadratic unit OD matrix for a given lists of zones.

Parameters:
  • zones – List of origin zones.
  • zoning – Zoning system.
Returns:

Unit OD matrix.

createUnitMatrix

public static ODMatrixArray createUnitMatrix(Set<String> zones, Zoning zoning)

Creates a quadratic unit OD matrix for a given lists of zones.

Parameters:
  • zones – Set of origin zones.
  • zoning – Zoning system.
Returns:

Unit OD matrix.

deleteInterzonalFlows

public void deleteInterzonalFlows(String zone)

Deletes all inter-zonal flows to/from a particular zone (leaving only intra-zonal flows)

Parameters:
  • zone – Zone for which inter-zonal flows need to be deleted from the origin-destination matrix.

getAbsoluteDifference

public int getAbsoluteDifference(ODMatrixArray other)

Gets sum of absolute differences between elements of two matrices.

Parameters:
  • other – The other matrix.
Returns:

Sum of absolute differences.

getFlow

public int getFlow(String originZone, String destinationZone)

Gets the flow for a given origin-destination pair.

Parameters:
  • originZone – Origin zone.
  • destinationZone – Destination zone.
Returns:

Origin-destination flow.

getFlow

public int getFlow(int originZoneID, int destinationZoneID)

Gets the flow for a given origin-destination pair.

Parameters:
  • originZoneID – Origin zone ID.
  • destinationZoneID – Destination zone ID.
Returns:

Origin-destination flow.

getIntFlow

public int getIntFlow(String originZone, String destinationZone)

Gets the flow for a given origin-destination pair as a whole number.

Parameters:
  • originZone – Origin zone.
  • destinationZone – Destination zone.
Returns:

Origin-destination flow.

getIntFlow

public int getIntFlow(int originZoneID, int destinationZoneID)

Gets the flow for a given origin-destination pair as a whole number.

Parameters:
  • originZoneID – Origin zone ID.
  • destinationZoneID – Destination zone ID.
Returns:

Origin-destination flow.

getSortedDestinations

public List<String> getSortedDestinations()

Gets the sorted list of destinations.

Returns:List of destinations.

getSortedOrigins

public List<String> getSortedOrigins()

Gets the sorted list of origins.

Returns:List of origins.

getTotalFlow

public int getTotalFlow()

Gets sum of all the flows in the matrix.

Returns:Sum of all the flows in the matrix (i.e. number of trips).

getTotalIntFlow

public int getTotalIntFlow()

Gets sum of all the flows in the matrix.

Returns:Sum of all the flows in the matrix (i.e. number of trips).

getUnsortedDestinations

public List<String> getUnsortedDestinations()

Gets the unsorted list of destinations.

Returns:List of destinations.

getUnsortedOrigins

public List<String> getUnsortedOrigins()

Gets the unsorted list of origins.

Returns:List of origins.

printMatrix

public void printMatrix()

Prints the full matrix.

printMatrixFormatted

public void printMatrixFormatted()

Prints the matrix as a formatted table.

printMatrixFormatted

public void printMatrixFormatted(String s)

Prints the matrix as a formatted table, with a print message.

Parameters:
  • s – Print message

saveMatrixFormatted

public void saveMatrixFormatted(String outputFile)

Saves the matrix into a csv file.

Parameters:
  • outputFile – Path to the output file.

saveMatrixFormattedList

public void saveMatrixFormattedList(String outputFile)

Saves the matrix into a csv file. Uses a list format (origin, destination, flow).

Parameters:
  • outputFile – Path to the output file.

scaleMatrixValue

public void scaleMatrixValue(double factor)

Scales (and rounds) matrix values with a scaling factor.

Parameters:
  • factor – Scaling factor.

setFlow

public void setFlow(int originZoneID, int destinationZoneID, int flow)

Sets the flow for a given origin-destination pair.

Parameters:
  • originZoneID – Origin zone ID.
  • destinationZoneID – Destination zone ID.
  • flow – Origin-destination flow.

setFlow

public void setFlow(String originZone, String destinationZone, int flow)

Sets the flow for a given origin-destination pair.

Parameters:
  • originZone – Origin zone.
  • destinationZone – Destination zone.
  • flow – Origin-destination flow.