aequilibrae.paths package

Subpackages

Submodules

aequilibrae.paths.AoN module

Purpose: Implement shortest path and network loading routines Original Author: Pedro Camargo (c@margo.co) Contributors: Last edited by: Arthur E. Website: www.AequilibraE.com Repository: https://github.com/AequilibraE/AequilibraE Created: 15/09/2013 Updated: 24/04/2018 Copyright: (c) AequilibraE authors Licence: See LICENSE.TXT ———————————————————————————————————–

aequilibrae.paths.AoN.bpr2_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.bpr_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.conical_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.copy_one_dimension_cython(double[:] target, double[:] source, int cores) void
aequilibrae.paths.AoN.copy_three_dimensions_cython(double[:, :, :] target, double[:, :, :] source, int cores) void
aequilibrae.paths.AoN.copy_two_dimensions_cython(double[:, :] target, double[:, :] source, int cores) void
aequilibrae.paths.AoN.dbpr2_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dbpr_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dconical_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dinrets_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.inrets_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.linear_combination_cython(double stepsize, double[:, :] results, double[:, :] array1, double[:, :] array2, int cores) void
aequilibrae.paths.AoN.linear_combination_cython_1d(double stepsize, double[:] results, double[:] array1, double[:] array2, int cores) void
aequilibrae.paths.AoN.linear_combination_skims_cython(double stepsize, double[:, :, :] results, double[:, :, :] array1, double[:, :, :] array2, int cores) void
aequilibrae.paths.AoN.network_loading(long classes, double[:, :] demand, long long[:] pred, long long[:] conn, double[:, :] link_loads, long long[:] no_path, long long[:] reached_first, double[:, :] node_load, long found) void
aequilibrae.paths.AoN.path_finding(long origin, double[:] graph_costs, long long[:] csr_indices, long long[:] graph_fs, long long[:] pred, long long[:] ids, long long[:] connectors, long long[:] reached_first) int
aequilibrae.paths.AoN.put_path_file_on_disk(unsigned int orig, unsigned int[:] pred, long long[:] predecessors, unsigned int[:] conn, long long[:] connectors, long long[:] all_nodes, unsigned int[:] origins_to_write, unsigned int[:] nodes_to_write) void
aequilibrae.paths.AoN.save_path_file(long origin_index, long num_links, long zones, long long[:] pred, long long[:] conn, string path_file, string index_file, bool write_feather) void
aequilibrae.paths.AoN.skim_multiple_fields(long origin, long nodes, long zones, long skims, double[:, :] node_skims, long long[:] pred, long long[:] conn, double[:, :] graph_costs, long long[:] reached_first, long found, double[:, :] final_skims) void
aequilibrae.paths.AoN.sum_a_times_b_minus_c_cython(double[:] array1, double[:] array2, double[:] array3, int cores) double
aequilibrae.paths.AoN.sum_axis1_cython(double[:] totals, double[:, :] multiples, int cores) void
aequilibrae.paths.AoN.triple_linear_combination_cython(double[:] stepsizes, double[:, :] results, double[:, :] array1, double[:, :] array2, double[:, :] array3, int cores) void
aequilibrae.paths.AoN.triple_linear_combination_cython_skims(double[:] stepsizes, double[:, :, :] results, double[:, :, :] array1, double[:, :, :] array2, double[:, :, :] array3, int cores) void

aequilibrae.paths.AoN module

Purpose: Implement shortest path and network loading routines Original Author: Pedro Camargo (c@margo.co) Contributors: Last edited by: Arthur E. Website: www.AequilibraE.com Repository: https://github.com/AequilibraE/AequilibraE Created: 15/09/2013 Updated: 24/04/2018 Copyright: (c) AequilibraE authors Licence: See LICENSE.TXT ———————————————————————————————————–

aequilibrae.paths.AoN.aggregate_link_costs_cython(double[:] actual, double[:] compressed, long long[:] crosswalk) void
aequilibrae.paths.AoN.assign_link_loads_cython(double[:, :] actual, double[:, :] compressed, long long[:] crosswalk, int cores) void
aequilibrae.paths.AoN.bpr2_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.bpr_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.conical_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.copy_one_dimension_cython(double[:] target, double[:] source, int cores) void
aequilibrae.paths.AoN.copy_three_dimensions_cython(double[:, :, :] target, double[:, :, :] source, int cores) void
aequilibrae.paths.AoN.copy_two_dimensions_cython(double[:, :] target, double[:, :] source, int cores) void
aequilibrae.paths.AoN.dbpr2_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dbpr_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dconical_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.dinrets_cython(double[:] deltaresult, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.inrets_cython(double[:] congested_time, double[:] link_flows, double[:] capacity, double[:] fftime, double[:] alpha, double[:] beta, int cores) void
aequilibrae.paths.AoN.linear_combination_cython(double stepsize, double[:, :] results, double[:, :] array1, double[:, :] array2, int cores) void
aequilibrae.paths.AoN.linear_combination_cython_1d(double stepsize, double[:] results, double[:] array1, double[:] array2, int cores) void
aequilibrae.paths.AoN.linear_combination_skims_cython(double stepsize, double[:, :, :] results, double[:, :, :] array1, double[:, :, :] array2, int cores) void
aequilibrae.paths.AoN.network_loading(long classes, double[:, :] demand, long long[:] pred, long long[:] conn, double[:, :] link_loads, long long[:] no_path, long long[:] reached_first, double[:, :] node_load, long found) void
aequilibrae.paths.AoN.path_finding(long origin, double[:] graph_costs, long long[:] csr_indices, long long[:] graph_fs, long long[:] pred, long long[:] ids, long long[:] connectors, long long[:] reached_first) int
aequilibrae.paths.AoN.perform_select_link_analysis(long origin, int classes, double[:, :] demand, long long[:] pred, long long[:] conn, long long[:] aux_link_flows, double[:, :] critical_array, int query_type) void
aequilibrae.paths.AoN.put_path_file_on_disk(unsigned int orig, unsigned int[:] pred, long long[:] predecessors, unsigned int[:] conn, long long[:] connectors, long long[:] all_nodes, unsigned int[:] origins_to_write, unsigned int[:] nodes_to_write) void
aequilibrae.paths.AoN.save_path_file(long origin_index, long num_links, long zones, long long[:] pred, long long[:] conn, string path_file, string index_file, bool write_feather) void
aequilibrae.paths.AoN.skim_multiple_fields(long origin, long nodes, long zones, long skims, double[:, :] node_skims, long long[:] pred, long long[:] conn, double[:, :] graph_costs, long long[:] reached_first, long found, double[:, :] final_skims) void
aequilibrae.paths.AoN.sum_a_times_b_minus_c_cython(double[:] array1, double[:] array2, double[:] array3, int cores) double
aequilibrae.paths.AoN.sum_axis1_cython(double[:] totals, double[:, :] multiples, int cores) void
aequilibrae.paths.AoN.triple_linear_combination_cython(double[:] stepsizes, double[:, :] results, double[:, :] array1, double[:, :] array2, double[:, :] array3, int cores) void
aequilibrae.paths.AoN.triple_linear_combination_cython_skims(double[:] stepsizes, double[:, :, :] results, double[:, :, :] array1, double[:, :, :] array2, double[:, :, :] array3, int cores) void

aequilibrae.paths.all_or_nothing module

class aequilibrae.paths.all_or_nothing.allOrNothing(matrix: AequilibraeMatrix, graph: Graph, results: AssignmentResults)

Bases: aequilibrae.utils.worker_thread.WorkerThread

assignment
__init__(matrix: AequilibraeMatrix, graph: Graph, results: AssignmentResults) None
doWork()
execute()
func_assig_thread(origin, all_threads)

aequilibrae.paths.assignment_paths module

class aequilibrae.paths.assignment_paths.TrafficClassIdentifier(name: str, id: str)

Bases: object

__init__(name: str, id: str)
class aequilibrae.paths.assignment_paths.AssignmentResultsTable(table_name: str)

Bases: object

__init__(table_name: str) None
get_traffic_class_names_and_id() List[aequilibrae.paths.assignment_paths.TrafficClassIdentifier]
class aequilibrae.paths.assignment_paths.AssignmentPaths(table_name: str)

Bases: object

Class for accessing path files optionally generated during assignment.

paths = AssignmentPath(table_name_with_assignment_results)
paths.get_path_for_destination(origin, destination, iteration, traffic_class_id)
__init__(table_name: str) None
Instantiates the class
Args:

table_name (str): Name of the traffic assignment result table used to generate the required path files

read_path_file(origin: int, iteration: int, traffic_class_id: str) -> (<class 'pandas.core.frame.DataFrame'>, <class 'pandas.core.frame.DataFrame'>)
get_path_for_destination(origin: int, destination: int, iteration: int, traffic_class_id: str)

Return all link ids, i.e. the full path, for a given destination

static get_path_for_destination_from_files(path_o: pandas.core.frame.DataFrame, path_o_index: pandas.core.frame.DataFrame, destination: int)

for a given path file and path index file, and a given destination, return the path links in o-d order

aequilibrae.paths.basic_path_finding module

aequilibrae.paths.bpr module

aequilibrae.paths.bpr2 module

aequilibrae.paths.conical module

aequilibrae.paths.graph module

class aequilibrae.paths.graph.Graph

Bases: object

Graph class

__init__()
default_types(tp: str)

Returns the default integer and float types used for computation

Args:

tp (str): data type. ‘int’ or ‘float’

prepare_graph(centroids: numpy.ndarray) None

Prepares the graph for a computation for a certain set of centroids

Under the hood, if sets all centroids to have IDs from 1 through n, which should correspond to the index of the matrix being assigned.

This is what enables having any node IDs as centroids, and it relies on the inference that all links connected to these nodes are centroid connectors.

Args:

centroids (np.ndarray): Array with centroid IDs. Mandatory type Int64, unique and positive

Excludes a list of links from a graph by setting their B node equal to their A node

Args:

links (list): List of link IDs to be excluded from the graph

set_graph(cost_field) None

Sets the field to be used for path computation

Args:

cost_field (str): Field name. Must be numeric

set_skimming(skim_fields: list) None

Sets the list of skims to be computed

Args:

skim_fields (list): Fields must be numeric

set_blocked_centroid_flows(block_centroid_flows) None

Chooses whether we want to block paths to go through centroids or not.

Default value is True

Args:

block_centroid_flows (bool): Blocking or not

save_to_disk(filename: str) None

Saves graph to disk

Args:

filename (str): Path to file. Usual file extension is aeg

load_from_disk(filename: str) None

Loads graph from disk

Args:

filename (str): Path to file

available_skims() List[str]

Returns graph fields that are available to be set as skims

Returns:

list (str): Field names

save_compressed_correspondence(path, mode_name, mode_id)

Save graph and nodes_to_indices to disk

aequilibrae.paths.inrets module

aequilibrae.paths.linear_approximation module

class aequilibrae.paths.linear_approximation.LinearApproximation(assig_spec, algorithm)

Bases: aequilibrae.utils.worker_thread.WorkerThread

equilibration
assignment
__init__(assig_spec, algorithm) None
calculate_conjugate_stepsize()
calculate_biconjugate_direction()
doWork()
execute()
calculate_stepsize()

Calculate optimal stepsize in descent direction

check_convergence()

Calculate relative gap and return True if it is smaller than desired precision

signal_handler(val)

aequilibrae.paths.multi_threaded_aon module

class aequilibrae.paths.multi_threaded_aon.MultiThreadedAoN

Bases: object

__init__()
prepare(graph, results)

aequilibrae.paths.multi_threaded_skimming module

class aequilibrae.paths.multi_threaded_skimming.MultiThreadedNetworkSkimming

Bases: object

__init__()
prepare(graph, results)

aequilibrae.paths.network_skimming module

class aequilibrae.paths.network_skimming.NetworkSkimming(graph, origins=None)

Bases: aequilibrae.utils.worker_thread.WorkerThread

from aequilibrae.paths.network_skimming import NetworkSkimming
from aequilibrae.project import Project

project = Project()
project.open(self.proj_dir)
network = self.project.network

network.build_graphs()
graph = network.graphs['c']
graph.set_graph(cost_field="distance")
graph.set_skimming("distance")

skm = NetworkSkimming(graph)
skm.execute()

# The skim report (if any error generated) is available here
skm.report

# To access the skim matrix directly from its temporary file
matrix = skm.results.skims

# Or you can save the results to disk
skm.save_to_project('skimming result')

# Or specify the AequilibraE's matrix file format
skm.save_to_project('skimming result', 'aem')

project.close()
skimming
__init__(graph, origins=None)
doWork()
execute()

Runs the skimming process as specified in the graph

save_to_project(name: str, format='omx') None

Saves skim results to the project folder and creates record in the database

Args:

name (str): Name of the matrix. Same value for matrix record name and file (plus extension) format (str, Optional): File format (‘aem’ or ‘omx’). Default is ‘omx’

aequilibrae.paths.parallel_numpy module

aequilibrae.paths.path_file_saving module

aequilibrae.paths.setup_Assignment module

aequilibrae.paths.traffic_assignment module

class aequilibrae.paths.traffic_assignment.TrafficAssignment

Bases: object

Traffic assignment class

For a comprehensive example on use, see the Use examples page.

from os.path import join
from aequilibrae.matrix import AequilibraeMatrix
from aequilibrae.paths import TrafficAssignment, TrafficClass


fldr = 'D:/release/Sample models/sioux_falls_2020_02_15'
proj_name = 'SiouxFalls.sqlite'
dt_fldr = '0_tntp_data'
prj_fldr = '1_project'

demand = AequilibraeMatrix()
demand.load(join(fldr, dt_fldr, 'demand.omx'))
demand.computational_view(['matrix']) # We will only assign one user class stored as 'matrix' inside the OMX file

project = Project()
project.load(join(fldr, prj_fldr))
project.network.build_graphs()

graph = project.network.graphs['c'] # we grab the graph for cars
graph.set_graph('free_flow_time') # let's say we want to minimize time
graph.set_skimming(['free_flow_time', 'distance']) # And will skim time and distance
graph.set_blocked_centroid_flows(True)

# Creates the assignment class
assigclass = TrafficClass(graph, demand)

assig = TrafficAssignment()
# The first thing to do is to add at list of traffic classes to be assigned
assig.set_classes([assigclass])

assig.set_vdf("BPR")  # This is not case-sensitive # Then we set the volume delay function

assig.set_vdf_parameters({"alpha": "b", "beta": "power"}) # And its parameters

assig.set_capacity_field("capacity") # The capacity and free flow travel times as they exist in the graph
assig.set_time_field("free_flow_time")

# And the algorithm we want to use to assign
assig.set_algorithm('bfw')

# since I haven't checked the parameters file, let's make sure convergence criteria is good
assig.max_iter = 1000
assig.rgap_target = 0.00001

assig.execute() # we then execute the assignment

# Convergence report is here
import pandas as pd
convergence_report = pd.DataFrame(assig.assignment.convergence_report)
convergence_report.head()

# Assignment results can be viewed as a Pandas DataFrame
results_df = assig.results()

# information on the assignment setup can be recovered with
info = assig.info()

# Or save it directly to the results database
results = assig.save_results(table_name='example_from_the_documentation')

# skims are here
avg_skims = assigclass.results.skims # blended ones
last_skims = assigclass._aon_results.skims # those for the last iteration
bpr_parameters = ['alpha', 'beta']
all_algorithms = ['all-or-nothing', 'msa', 'frank-wolfe', 'fw', 'cfw', 'bfw']
__init__() None
set_vdf(vdf_function: str) None

Sets the Volume-delay function to be used

Args:

vdf_function(str:) Name of the VDF to be used

set_classes(classes: List[aequilibrae.paths.traffic_class.TrafficClass]) None

Sets Traffic classes to be assigned

Args:

classes (List[TrafficClass]:) List of Traffic classes for assignment

add_class(traffic_class: aequilibrae.paths.traffic_class.TrafficClass) None

Adds a traffic class to the assignment

Args:

traffic_class (TrafficClass:) Traffic class

algorithms_available() list

Returns all algorithms available for use

Returns:

list: List of string values to be used with set_algorithm

set_algorithm(algorithm: str)

Chooses the assignment algorithm. e.g. ‘frank-wolfe’, ‘bfw’, ‘msa’

‘fw’ is also accepted as an alternative to ‘frank-wolfe’

Args:

algorithm (list): Algorithm to be used

set_vdf_parameters(par: dict) None

Sets the parameters for the Volume-delay function.

Parameter values can be scalars (same values for the entire network) or network field names (link-specific values) - Examples: {‘alpha’: 0.15, ‘beta’: 4.0} or {‘alpha’: ‘alpha’, ‘beta’: ‘beta’}

Args:

par (dict): Dictionary with all parameters for the chosen VDF

set_cores(cores: int) None

Allows one to set the number of cores to be used AFTER traffic classes have been added

Inherited from AssignmentResults

Args:

cores (int): Number of CPU cores to use

set_save_path_files(save_it: bool) None

Turn path saving on or off.

Args:

save_it (bool): Boolean to indicate whether paths should be saved

set_path_file_format(file_format: str) None

Specify path saving format. Either parquet or feather.

Args:

file_format (str): Name of file format to use for path files

set_time_field(time_field: str) None

Sets the graph field that contains free flow travel time -> e.g. ‘fftime’

Args:

time_field (str): Field name

set_capacity_field(capacity_field: str) None

Sets the graph field that contains link capacity for the assignment period -> e.g. ‘capacity1h’

Args:

capacity_field (str): Field name

execute() None

Processes assignment

save_results(table_name: str, keep_zero_flows=True) None

Saves the assignment results to results_database.sqlite

Method fails if table exists

Args:

table_name (str): Name of the table to hold this assignment result keep_zero_flows (bool): Whether we should keep records for zero flows. Defaults to True

results() pandas.core.frame.DataFrame

Prepares the assignment results as a Pandas DataFrame

Returns:

DataFrame (pd.DataFrame): Pandas dataframe with all the assignment results indexed on link_id

report() pandas.core.frame.DataFrame

Returns the assignment convergence report

Returns:

DataFrame (pd.DataFrame): Convergence report

info() dict

Returns information for the traffic assignment procedure

Dictionary contains keys ‘Algorithm’, ‘Classes’, ‘Computer name’, ‘Procedure ID’, ‘Maximum iterations’ and ‘Target RGap’.

The classes key is also a dictionary with all the user classes per traffic class and their respective matrix totals

Returns:

info (dict): Pandas dataframe with all the assignment results indexed on link_id

save_skims(matrix_name: str, which_ones='final', format='omx') None

Saves the skims (if any) to the skim folder and registers in the matrix list

Args:

name (str): Name of the matrix record to hold this matrix (same name used for file name) which_ones (str,optional): {‘final’: Results of the final iteration, ‘blended’: Averaged results for all iterations, ‘all’: Saves skims for both the final iteration and the blended ones} Default is ‘final’ format (str, Optional): File format (‘aem’ or ‘omx’). Default is ‘omx’

aequilibrae.paths.traffic_class module

class aequilibrae.paths.traffic_class.TrafficClass(name: str, graph: aequilibrae.paths.graph.Graph, matrix: aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix)

Bases: object

Traffic class for equilibrium traffic assignment

from aequilibrae.paths import TrafficClass

tc = TrafficClass(graph, demand_matrix)
tc.set_pce(1.3)
__init__(name: str, graph: aequilibrae.paths.graph.Graph, matrix: aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix) None

Instantiates the class

Args:

name (str): UNIQUE class name.

graph (Graph): Class/mode-specific graph

matrix (AequilibraeMatrix): Class/mode-specific matrix. Supports multiple user classes

set_pce(pce: Union[float, int]) None

Sets Passenger Car equivalent

Args:

pce (Union[float, int]): PCE. Defaults to 1 if not set

set_fixed_cost(field_name: str, multiplier=1)

Sets value of time

Args:

field_name (str): Name of the graph field with fixed costs for this class multiplier (Union[float, int]): Multiplier for the fixed cost. Defaults to 1 if not set

set_vot(value_of_time: float) None

Sets value of time

Args:

value_of_time (Union[float, int]): Value of time. Defaults to 1 if not set

aequilibrae.paths.vdf module

class aequilibrae.paths.vdf.VDF

Bases: object

Volume-Delay function

  from aequilibrae.paths import VDF

  vdf = VDF()
  vdf.functions_available()
['bpr', 'bpr2', 'conical', 'inrets']
__init__()
functions_available() list

returns a list of all functions available

Module contents