SkimMatrixMultiKey

public class SkimMatrixMultiKey implements SkimMatrix

Skim matrix for storing inter-zonal travel times or costs (for passenger vehicles).

Author:Milan Lovric

Constructors

SkimMatrixMultiKey

public SkimMatrixMultiKey(Zoning zoning)

Skim matrix constructors.

Parameters:
  • zoning – Zoning system.

SkimMatrixMultiKey

public SkimMatrixMultiKey(String fileName, Zoning zoning)

Constructor that reads skim 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

getAbsoluteDifference

public double getAbsoluteDifference(SkimMatrix other)

Gets sum of absolute differences between elements of two matrices.

Parameters:
  • other – The other matrix.
Returns:

Sum of absolute differences.

getAverageCost

public double getAverageCost()

Gets average OD cost.

Returns:Average cost.

getAverageCost

public double getAverageCost(ODMatrixMultiKey flows)

Gets average OD cost weighted by demand.

Parameters:
  • flows – The demand as an origin-destination matrix.
Returns:

Average cost.

getAverageZonalCosts

public HashMap<String, Double> getAverageZonalCosts(List<String> zones)

Gets average zonal cost (used for the rail model).

Parameters:
  • zones – Zones for which zonal costs are required.
Returns:

Map of average zonal costs.

getAverageZonalCosts

public HashMap<String, Double> getAverageZonalCosts(List<String> zones, ODMatrixMultiKey flows)

Gets average zonal cost weighted by demand (used for the rail model).

Parameters:
  • zones – Zones for which zonal costs are required.
  • flows – The demand as an origin-destination matrix.
Returns:

Map of average zonal costs.

getCost

public double getCost(String originZone, String destinationZone)

Gets cost for a given origin-destination pair.

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

Origin-destination cost.

getCost

public double getCost(int originZoneID, int destinationZoneID)

Gets cost for a given origin-destination pair.

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

Origin-destination cost.

getKeySet

public Set<MultiKey> getKeySet()

Gets the keyset of the multimap.

Returns:Keyset.

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.

getSumOfCosts

public double getSumOfCosts()

Gets sum of OD costs.

Returns:Sum of costs.

getSumOfCosts

public double getSumOfCosts(ODMatrixMultiKey flows)

Gets sum of costs multiplied by demand flows.

Parameters:
  • flows – The demand as an origin-destination matrix.
Returns:

Sum of costs.

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 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, cost).

Parameters:
  • outputFile – Path to the output file.

setCost

public void setCost(String originZone, String destinationZone, double cost)

Sets cost for a given origin-destination pair.

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

setCost

public void setCost(int originZoneID, int destinationZoneID, double cost)

Sets cost for a given origin-destination pair.

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