ODMatrixArrayTempro

public class ODMatrixArrayTempro implements AssignableODMatrix

Origin-destination matrix with real values, memory use optimised for Tempro.

Author:Milan Lovric

Constructors

ODMatrixArrayTempro

public ODMatrixArrayTempro(Zoning zoning)

Constructor for an empty OD matrix. Uses the maximum Tempro zone ID which will create a rather large matrix.

Parameters:
  • zoning – Zoning system.

ODMatrixArrayTempro

public ODMatrixArrayTempro(String fileName, Zoning zoning)

Constructor that reads OD matrix from an input csv file. Can use both matrix and list format.

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.

clone

public ODMatrixArrayTempro clone()

createLadMatrixFromTEMProMatrix

public static RealODMatrix createLadMatrixFromTEMProMatrix(ODMatrixArrayTempro temproMatrix, Zoning zoning)

Creates real-valued LAD OD matrix from real-valued TEMPro OD matrix.

Parameters:
  • temproMatrix – TEMPro ODMatrix which should be aggregated to LAD matrix.
  • zoning – Zoning system with mapping between TEMPro and LAD zones.
Returns:

LAD based real-valued 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.

createTEMProFromLadMatrix

public static ODMatrixArrayTempro createTEMProFromLadMatrix(ODMatrixMultiKey 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 ODMatrixArrayTempro 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 ODMatrixArrayTempro createUnitMatrix(List<String> zones, Zoning zoning)

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

Parameters:
  • zones – List of zones.
Returns:

Unit OD matrix.

createUnitMatrix

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

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

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

Unit OD matrix.

createUnitMatrix

public static ODMatrixArrayTempro createUnitMatrix(Zoning zoning)

Creates a quadratic unit OD matrix.

Parameters:
  • 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(ODMatrixArrayTempro 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.

getIntFlow

public int getIntFlow(String originZone, String destinationZone)

Gets the flow for a given origin-destination pair, rounded to a whole number.

Parameters:
  • originZone – Origin zone.
  • destinationZone – Destination zone.
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.

getTotalIntFlow

public int getTotalIntFlow()

Gets sum of all the (rounded) flows in the matrix.

Returns:Sum of all the (rounded) 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 message followed by the formatted matrix.

Parameters:
  • s – Message.

saveMatrixFormatted

public void saveMatrixFormatted(String outputFile)

Saves the matrix into a csv file. Uses a rectangular/matrix format.

Parameters:
  • outputFile – Path to the output file.

saveMatrixFormatted2

public void saveMatrixFormatted2(String outputFile)

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

Parameters:
  • outputFile – Path to the output file.

saveMatrixFormatted3

public void saveMatrixFormatted3(String outputFile)

Saves the matrix into a csv file. Uses a list format (origin, destination, flow) and number codes for zones.

Parameters:
  • outputFile – Path to the output file.

scaleMatrixValue

public void scaleMatrixValue(double factor)

Scales matrix values with a scaling factor.

Parameters:
  • factor – Scaling factor.

scaleMatrixValue

public void scaleMatrixValue(ODMatrixArrayTempro scalingMatrix)

Scales matrix values with another matrix (element-wise multiplication).

Parameters:
  • scalingMatrix – Scaling matrix.

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.

setFlow

public void setFlow(int originCode, int destinationCode, int flow)

Sets the flow for a given origin-destination pair.

Parameters:
  • originCode – Origin zone integer code.
  • destinationCode – Destination zone integer code.
  • flow – Origin-destination flow.

sumMatrixSubset

public int sumMatrixSubset(List<String> origins, List<String> destinations)

Sums the elements of a matrix subset (provided as two lists of origins and destinations).

Parameters:
  • origins – List of origin zones (a subset).
  • destinations – List of destination zones (a subset).
Returns:

Sum of the subset.