FreightMatrix

public class FreightMatrix

Origin-destination matrix for freight vehicles (following the format of DfT’s BYFM 2006 study).

Author:Milan Lovric

Fields

MAX_FREIGHT_ZONE_ID

public static final int MAX_FREIGHT_ZONE_ID

MAX_VEHICLE_ID

public static final int MAX_VEHICLE_ID

Constructors

FreightMatrix

public FreightMatrix()

FreightMatrix

public FreightMatrix(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

createUnitBYFMMatrix

public static FreightMatrix createUnitBYFMMatrix()

Creates a unit freight matrix for the specific DfT BYFM 2006 zoning system.

Returns:Unit BYFM freight matrix.

createUnitMatrix

public static FreightMatrix createUnitMatrix(List<Integer> origins, List<Integer> destinations)

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

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

Unit freight matrix.

deleteInterzonalFlows

public void deleteInterzonalFlows(int 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 freight matrix.

getAbsoluteDifference

public double getAbsoluteDifference(FreightMatrix 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(int origin, int destination, int vehicleType)

Gets the flow for a given origin-destination pair.

Parameters:
  • origin – Freight origin.
  • destination – Freight destination.
  • vehicleType – Vehicle type.
Returns:

Origin-destination flow.

getKeySet

public Set<MultiKey> getKeySet()

Gets the keyset of the multimap.

Returns:Key set.

getScaledMatrix

public FreightMatrix getScaledMatrix(double scale)

Multiplies each value of the matrix with a scaling factor.

Parameters:
  • scale – Scaling factor.
Returns:

Scaled freight matrix.

getSortedDestinations

public List<Integer> getSortedDestinations()

Gets the sorted list of destinations.

Returns:List of destinations.

getSortedOrigins

public List<Integer> getSortedOrigins()

Gets the sorted list of origins.

Returns:List of origins.

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<Integer> getUnsortedDestinations()

Gets the unsorted list of destinations.

Returns:List of destinations.

getUnsortedOrigins

public List<Integer> getUnsortedOrigins()

Gets the unsorted list of origins.

Returns:List of origins.

getVehicleTypes

public List<Integer> getVehicleTypes()

Gets the sorted list of vehicle types.

Returns:List of vehicle types.

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.

scaleMatrix

public void scaleMatrix(SkimMatrixFreight scale)

Scales matrix flows using a real-valued scaling matrix.

Parameters:
  • scale – Scaling factors.

setFlow

public void setFlow(int origin, int destination, int vehicleType, int flow)

Sets the flow for a given origin-destination pair.

Parameters:
  • origin – Freight origin.
  • destination – Freight destination.
  • vehicleType – Vehicle type.
  • flow – Origin-destination flow.