RealODMatrix

public class RealODMatrix implements AssignableODMatrix

Origin-destination matrix with real values.

Author:Milan Lovric

Constructors

RealODMatrix

public RealODMatrix()

RealODMatrix

public RealODMatrix(String fileName)

Constructor that reads OD matrix from an input csv file.

Parameters:
  • fileName – Path to the input file.
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 RealODMatrix clone()

createLadMatrixFromTEMProMatrix

public static RealODMatrix createLadMatrixFromTEMProMatrix(RealODMatrix 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 RealODMatrix createTEMProFromLadMatrix(RealODMatrix ladODMatrix, RealODMatrix 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 RealODMatrix createUnitMatrix(List<String> origins, List<String> destinations)

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

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

Unit OD matrix.

createUnitMatrix

public static RealODMatrix createUnitMatrix(List<String> zones)

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

Parameters:
  • zones – List of zones.
Returns:

Unit OD matrix.

createUnitMatrix

public static RealODMatrix createUnitMatrix(Set<String> zones)

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

Parameters:
  • zones – Set of zones.
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 double getAbsoluteDifference(RealODMatrix 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.

getKeySet

public Set<MultiKey> getKeySet()

Gets the keyset of the multimap.

Returns:Key set.

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.

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.

scaleMatrixValue

public void scaleMatrixValue(double factor)

Scales matrix values with a scaling factor.

Parameters:
  • factor – Scaling factor.

scaleMatrixValue

public void scaleMatrixValue(RealODMatrix 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.

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.