RealODMatrixTempro

public class RealODMatrixTempro implements AssignableODMatrix

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

Author:Milan Lovric

Constructors

RealODMatrixTempro

public RealODMatrixTempro(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.

RealODMatrixTempro

public RealODMatrixTempro(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.

ceilMatrixValues

public void ceilMatrixValues()

Ceil OD matrix values.

clone

public RealODMatrixTempro clone()

createLadMatrixFromTEMProMatrix

public static RealODMatrix createLadMatrixFromTEMProMatrix(RealODMatrixTempro 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 RealODMatrixTempro createTEMProFromLadMatrix(RealODMatrix ladODMatrix, RealODMatrixTempro 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 RealODMatrixTempro createTEMProFromLadMatrix(ODMatrixMultiKey ladODMatrix, RealODMatrixTempro 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 RealODMatrixTempro 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 RealODMatrixTempro 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 RealODMatrixTempro 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 RealODMatrixTempro 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.

floorMatrixValues

public void floorMatrixValues()

Floor OD matrix values.

getAbsoluteDifference

public double getAbsoluteDifference(RealODMatrixTempro other)

Gets sum of absolute differences between elements of two matrices.

Parameters:
  • other – The other matrix.
Returns:

Sum of absolute differences.

getFlow

public double 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.

getSumOfFlows

public double getSumOfFlows()

Gets sum of all the flows.

Returns:Sum of flows.

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(int precision)

Prints the matrix as a formatted table.

Parameters:
  • precision – Number of decimal places for the matrix value.

printMatrixFormatted

public void printMatrixFormatted(String s, int precision)

Prints message followed by the formatted matrix.

Parameters:
  • s – Message.
  • precision – Number of decimal places.

roundMatrixValues

public void roundMatrixValues()

Rounds OD matrix values.

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(RealODMatrixTempro scalingMatrix)

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

Parameters:
  • scalingMatrix – Scaling matrix.

setFlow

public void setFlow(String originZone, String destinationZone, double 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, double 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 double 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.