aequilibrae.paths package#
Subpackages#
Submodules#
aequilibrae.paths.AoN module#
- aequilibrae.paths.AoN.aggregate_link_costs(actual_costs, compressed_costs, crosswalk)#
- aequilibrae.paths.AoN.aggregate_link_costs_cython(double[:] actual, double[:] compressed, long long[:] crosswalk) void #
- aequilibrae.paths.AoN.assign_link_loads(actual_links, compressed_links, crosswalk, cores)#
- aequilibrae.paths.AoN.assign_link_loads_cython(double[:, :] actual, double[:, :] compressed, long long[:] crosswalk, int cores) void #
- aequilibrae.paths.AoN.bpr(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.bpr2(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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.build_compressed_graph(graph)#
- aequilibrae.paths.AoN.conical(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(target, source, cores)#
- aequilibrae.paths.AoN.copy_one_dimension_cython(double[:] target, double[:] source, int cores) void #
- aequilibrae.paths.AoN.copy_three_dimensions(target, source, cores)#
- aequilibrae.paths.AoN.copy_three_dimensions_cython(double[:, :, :] target, double[:, :, :] source, int cores) void #
- aequilibrae.paths.AoN.copy_two_dimensions(target, source, cores)#
- 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.delta_bpr(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_bpr2(dbpr2, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_conical(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_inrets(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(results, array1, array2, stepsize, cores)#
- aequilibrae.paths.AoN.linear_combination_1d(results, array1, array2, stepsize, cores)#
- 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(results, array1, array2, stepsize, cores)#
- 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.one_to_all(origin, matrix, graph, result, aux_result, curr_thread)#
- aequilibrae.paths.AoN.path_computation(origin, destination, graph, results)#
- Parameters
graph – AequilibraE graph. Needs to have been set with number of centroids and list of skims (if any)
results – AequilibraE Matrix properly set for computation using matrix.computational_view([matrix list])
skimming – if we will skim for all nodes or not
- aequilibrae.paths.AoN.path_finding(long origin, long destination, 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.path_finding_a_star(long origin, long destination, double[:] graph_costs, long long[:] csr_indices, long long[:] graph_fs, long long[:] nodes_to_indices, double[:] lats, double[:] lons, long long[:] pred, long long[:] ids, long long[:] connectors, long long[:] reached_first, Heuristic heuristic) int #
Based on the pseudocode presented at https://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode The following variables have been renamed to be consistent with out Dijkstra’s implementation
openSet: pqueue
cameFrom: pred
fScore: pqueue.Elements[idx].key, for some idx
- 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.skimming_single_origin(origin, graph, result, aux_result, curr_thread)#
- Parameters
origin –
graph –
results –
- Returns
- aequilibrae.paths.AoN.sum_a_times_b_minus_c(array1, array2, array3, cores)#
- aequilibrae.paths.AoN.sum_a_times_b_minus_c_cython(double[:] array1, double[:] array2, double[:] array3, int cores) double #
- aequilibrae.paths.AoN.sum_axis1(totals, multiples, cores)#
- aequilibrae.paths.AoN.sum_axis1_cython(double[:] totals, double[:, :] multiples, int cores) void #
- aequilibrae.paths.AoN.triple_linear_combination(results, array1, array2, array3, stepsizes, cores)#
- 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.triple_linear_combination_skims(results, array1, array2, array3, stepsizes, cores)#
- aequilibrae.paths.AoN.update_path_trace(results, destination, graph)#
If results.early_exit is True, early exit will be enabled if the path is to be recomputed. If results.a_star is True, A* will be used if the path is to be recomputed.
- Parameters
graph – AequilibraE graph. Needs to have been set with number of centroids and list of skims (if any)
results – AequilibraE Matrix properly set for computation using matrix.computational_view([matrix list])
skimming – if we will skim for all nodes or not
early_exit – Exit Dijkstra’s once the destination has been found if the shortest path tree must be reconstructed.
aequilibrae.paths.AoN module#
- aequilibrae.paths.AoN.aggregate_link_costs(actual_costs, compressed_costs, crosswalk)#
- aequilibrae.paths.AoN.aggregate_link_costs_cython(double[:] actual, double[:] compressed, long long[:] crosswalk) void #
- aequilibrae.paths.AoN.assign_link_loads(actual_links, compressed_links, crosswalk, cores)#
- aequilibrae.paths.AoN.assign_link_loads_cython(double[:, :] actual, double[:, :] compressed, long long[:] crosswalk, int cores) void #
- aequilibrae.paths.AoN.bpr(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.bpr2(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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.build_compressed_graph(graph)#
- aequilibrae.paths.AoN.conical(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(target, source, cores)#
- aequilibrae.paths.AoN.copy_one_dimension_cython(double[:] target, double[:] source, int cores) void #
- aequilibrae.paths.AoN.copy_three_dimensions(target, source, cores)#
- aequilibrae.paths.AoN.copy_three_dimensions_cython(double[:, :, :] target, double[:, :, :] source, int cores) void #
- aequilibrae.paths.AoN.copy_two_dimensions(target, source, cores)#
- 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.delta_bpr(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_bpr2(dbpr2, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_conical(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- aequilibrae.paths.AoN.delta_inrets(dbpr, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(congested_times, link_flows, capacity, fftime, alpha, beta, cores)#
- 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(results, array1, array2, stepsize, cores)#
- aequilibrae.paths.AoN.linear_combination_1d(results, array1, array2, stepsize, cores)#
- 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(results, array1, array2, stepsize, cores)#
- 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.one_to_all(origin, matrix, graph, result, aux_result, curr_thread)#
- aequilibrae.paths.AoN.path_computation(origin, destination, graph, results)#
- Parameters
graph – AequilibraE graph. Needs to have been set with number of centroids and list of skims (if any)
results – AequilibraE Matrix properly set for computation using matrix.computational_view([matrix list])
skimming – if we will skim for all nodes or not
- aequilibrae.paths.AoN.path_finding(long origin, long destination, 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.path_finding_a_star(long origin, long destination, double[:] graph_costs, long long[:] csr_indices, long long[:] graph_fs, long long[:] nodes_to_indices, double[:] lats, double[:] lons, long long[:] pred, long long[:] ids, long long[:] connectors, long long[:] reached_first, Heuristic heuristic) int #
Based on the pseudocode presented at https://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode The following variables have been renamed to be consistent with out Dijkstra’s implementation
openSet: pqueue
cameFrom: pred
fScore: pqueue.Elements[idx].key, for some idx
- 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.skimming_single_origin(origin, graph, result, aux_result, curr_thread)#
- Parameters
origin –
graph –
results –
- Returns
- aequilibrae.paths.AoN.sum_a_times_b_minus_c(array1, array2, array3, cores)#
- aequilibrae.paths.AoN.sum_a_times_b_minus_c_cython(double[:] array1, double[:] array2, double[:] array3, int cores) double #
- aequilibrae.paths.AoN.sum_axis1(totals, multiples, cores)#
- aequilibrae.paths.AoN.sum_axis1_cython(double[:] totals, double[:, :] multiples, int cores) void #
- aequilibrae.paths.AoN.triple_linear_combination(results, array1, array2, array3, stepsizes, cores)#
- 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.triple_linear_combination_skims(results, array1, array2, array3, stepsizes, cores)#
- aequilibrae.paths.AoN.update_path_trace(results, destination, graph)#
If results.early_exit is True, early exit will be enabled if the path is to be recomputed. If results.a_star is True, A* will be used if the path is to be recomputed.
- Parameters
graph – AequilibraE graph. Needs to have been set with number of centroids and list of skims (if any)
results – AequilibraE Matrix properly set for computation using matrix.computational_view([matrix list])
skimming – if we will skim for all nodes or not
early_exit – Exit Dijkstra’s once the destination has been found if the shortest path tree must be reconstructed.
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#
- 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
- class aequilibrae.paths.assignment_paths.AssignmentResultsTable(table_name: str, project=None)#
Bases:
object
- get_traffic_class_names_and_id() List[aequilibrae.paths.assignment_paths.TrafficClassIdentifier] #
- class aequilibrae.paths.assignment_paths.AssignmentPaths(table_name: str, project=None)#
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)
- 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.GraphBase(logger=None)#
Bases:
abc.ABC
Graph class
- default_types(tp: str)#
Returns the default integer and float types used for computation
- Arguments
tp (
str
): data type. ‘int’ or ‘float’
- prepare_graph(centroids: Optional[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.
- Arguments
centroids (
np.ndarray
): Array with centroid IDs. Mandatory type Int64, unique and positive
- exclude_links(links: list) None #
Excludes a list of links from a graph by setting their B node equal to their A node
- Arguments
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
- Arguments
cost_field (
str
): Field name. Must be numeric
- set_skimming(skim_fields: list) None #
Sets the list of skims to be computed
Skimming with A* may produce results that differ from tradditional Dijkstra’s due to its use a heuristic.
- Arguments
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
- Arguments
block_centroid_flows (
bool
): Blocking or not
- save_to_disk(filename: str) None #
Saves graph to disk
- Arguments
filename (
str
): Path to file. Usual file extension is aeg
- load_from_disk(filename: str) None #
Loads graph from disk
- Arguments
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
- class aequilibrae.paths.graph.Graph(*args, **kwargs)#
- class aequilibrae.paths.graph.TransitGraph(config: Optional[dict] = None, od_node_mapping: Optional[pandas.core.frame.DataFrame] = None, *args, **kwargs)#
aequilibrae.paths.graph_building module#
aequilibrae.paths.hyperpath module#
aequilibrae.paths.inrets module#
aequilibrae.paths.linear_approximation module#
- class aequilibrae.paths.linear_approximation.LinearApproximation(assig_spec, algorithm, project=None)#
Bases:
aequilibrae.utils.worker_thread.WorkerThread
- equilibration#
- assignment#
- 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#
aequilibrae.paths.multi_threaded_skimming module#
aequilibrae.paths.network_skimming module#
- class aequilibrae.paths.network_skimming.NetworkSkimming(graph, origins=None, project=None)#
Bases:
aequilibrae.utils.worker_thread.WorkerThread
>>> from aequilibrae import Project >>> from aequilibrae.paths.network_skimming import NetworkSkimming >>> project = Project.from_path("/tmp/test_project") >>> network = 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('/tmp/skimming result.omx') # Or specify the AequilibraE's matrix file format >>> skm.save_to_project('skimming result', 'aem') >>> project.close()
- skimming#
- doWork()#
- execute()#
Runs the skimming process as specified in the graph
- set_cores(cores: int) None #
Sets number of cores (threads) to be used in computation
Value of zero sets number of threads to all available in the system, while negative values indicate the number of threads to be left out of the computational effort.
Resulting number of cores will be adjusted to a minimum of zero or the maximum available in the system if the inputs result in values outside those limits
- Arguments
cores (
int
): Number of cores to be used in computation
- save_to_project(name: str, format='omx', project=None) None #
Saves skim results to the project folder and creates record in the database
- Arguments
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’ project (Project
, Optional): Project we want to save the results to. Defaults to the active project
aequilibrae.paths.optimal_strategies module#
aequilibrae.paths.parallel_numpy module#
aequilibrae.paths.path_file_saving module#
aequilibrae.paths.pq_4ary_heap module#
aequilibrae.paths.public_transport module#
- class aequilibrae.paths.public_transport.HyperpathGenerating(edges, tail='tail', head='head', trav_time='trav_time', freq='freq', check_edges=False)#
Bases:
object
A class for hyperpath generation.
- Arguments
edges (
pandas.DataFrame
): The edges of the graph.tail (
str
): The column name for the tail of the edge (optional, default is “tail”).head (
str
): The column name for the head of the edge (optional, default is “head”).trav_time (
str
): The column name for the travel time of the edge (optional, default is “trav_time”).freq (
str
): The column name for the frequency of the edge (optional, default is “freq”).check_edges (
bool
): If True, check the validity of the edges (optional, default is False).
- assign(origin_column, destination_column, demand_column, check_demand=False, threads=None)#
Assigns demand to the edges of the graph.
Assumes the
*_column
arguments are provided as numpy arrays that form a COO sprase matrix.- Arguments
origin_column (
np.ndarray
): The column for the origin vertices (optional, default is “orig_vert_idx”).destination_column (
np.ndarray
): The column or the destination vertices (optional, default is “dest_vert_idx”).demand_column (
np.ndarray
): The column for the demand values (optional, default is “demand”).check_demand (
bool
): If True, check the validity of the demand data (optional, default is False).threads (
int
):The number of threads to use for computation (optional, default is 0, using all available threads).
- info() dict #
- run(origin, destination, volume, return_inf=False)#
- save_results(table_name: str, keep_zero_flows=True, project=None) None #
Saves the assignment results to results_database.sqlite
Method fails if table exists
- Arguments
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 project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- aequilibrae.paths.public_transport.convert_graph_to_csc_uint32(edges, tail, head, data, vertex_count)#
Convert an edge dataframe in COO format into CSC format.
The data vector is of uint32 type.
- edgespandas.core.frame.DataFrame
The edges dataframe.
- tailstr
The column name in the edges dataframe for the tail vertex index.
- headstr
The column name in the edges dataframe for the head vertex index.
- datastr
The column name in the edges dataframe for the int edge attribute.
- vertex_countint
The vertex count in the given network edges.
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
aequilibrae.paths.public_transport module#
- class aequilibrae.paths.public_transport.HyperpathGenerating(edges, tail='tail', head='head', trav_time='trav_time', freq='freq', check_edges=False)#
Bases:
object
A class for hyperpath generation.
- Arguments
edges (
pandas.DataFrame
): The edges of the graph.tail (
str
): The column name for the tail of the edge (optional, default is “tail”).head (
str
): The column name for the head of the edge (optional, default is “head”).trav_time (
str
): The column name for the travel time of the edge (optional, default is “trav_time”).freq (
str
): The column name for the frequency of the edge (optional, default is “freq”).check_edges (
bool
): If True, check the validity of the edges (optional, default is False).
- assign(origin_column, destination_column, demand_column, check_demand=False, threads=None)#
Assigns demand to the edges of the graph.
Assumes the
*_column
arguments are provided as numpy arrays that form a COO sprase matrix.- Arguments
origin_column (
np.ndarray
): The column for the origin vertices (optional, default is “orig_vert_idx”).destination_column (
np.ndarray
): The column or the destination vertices (optional, default is “dest_vert_idx”).demand_column (
np.ndarray
): The column for the demand values (optional, default is “demand”).check_demand (
bool
): If True, check the validity of the demand data (optional, default is False).threads (
int
):The number of threads to use for computation (optional, default is 0, using all available threads).
- info() dict #
- run(origin, destination, volume, return_inf=False)#
- save_results(table_name: str, keep_zero_flows=True, project=None) None #
Saves the assignment results to results_database.sqlite
Method fails if table exists
- Arguments
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 project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- aequilibrae.paths.public_transport.convert_graph_to_csc_uint32(edges, tail, head, data, vertex_count)#
Convert an edge dataframe in COO format into CSC format.
The data vector is of uint32 type.
- edgespandas.core.frame.DataFrame
The edges dataframe.
- tailstr
The column name in the edges dataframe for the tail vertex index.
- headstr
The column name in the edges dataframe for the head vertex index.
- datastr
The column name in the edges dataframe for the int edge attribute.
- vertex_countint
The vertex count in the given network edges.
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
aequilibrae.paths.setup_assignment module#
aequilibrae.paths.traffic_assignment module#
- class aequilibrae.paths.traffic_assignment.AssignmentBase(project=None)#
Bases:
abc.ABC
- algorithms_available() list #
Returns all algorithms available for use
- Returns
list
: List of string values to be used with set_algorithm
- abstract set_algorithm(algorithm: str)#
- abstract set_cores(cores: int) None #
- execute(log_specification=True) None #
Processes assignment
- abstract log_specification()#
- abstract save_results(table_name: str, keep_zero_flows=True, project=None) None #
- abstract results() pandas.core.frame.DataFrame #
- report() pandas.core.frame.DataFrame #
Returns the assignment convergence report
- Returns
DataFrame (
pd.DataFrame
): Convergence report
- abstract info() dict #
- set_classes(classes: List[aequilibrae.paths.traffic_class.TransportClassBase]) None #
Sets Transport classes to be assigned
- Arguments
classes (
List[TransportClassBase]
:) List of TransportClass’s for assignment
- add_class(transport_class: aequilibrae.paths.traffic_class.TransportClassBase) None #
Adds a Transport class to the assignment
- Arguments
transport_class (
TransportClassBase
:) Transport class
- set_time_field(time_field: str) None #
- class aequilibrae.paths.traffic_assignment.TrafficAssignment(project=None)#
Bases:
aequilibrae.paths.traffic_assignment.AssignmentBase
Traffic assignment class.
For a comprehensive example on use, see the Use examples page.
>>> from aequilibrae import Project >>> from aequilibrae.matrix import AequilibraeMatrix >>> from aequilibrae.paths import TrafficAssignment, TrafficClass >>> project = Project.from_path("/tmp/test_project") >>> 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) >>> proj_matrices = project.matrices >>> demand = AequilibraeMatrix() >>> demand = proj_matrices.get_matrix("demand_omx") # We will only assign one user class stored as 'matrix' inside the OMX file >>> demand.computational_view(['matrix']) # Creates the assignment class >>> assigclass = TrafficClass("car", graph, demand) >>> assig = TrafficAssignment() # The first thing to do is to add at list of traffic classes to be assigned >>> assig.set_classes([assigclass]) # Then we set the volume delay function >>> assig.set_vdf("BPR") # This is not case-sensitive # And its parameters >>> assig.set_vdf_parameters({"alpha": "b", "beta": "power"}) # The capacity and free flow travel times as they exist in the graph >>> assig.set_capacity_field("capacity") >>> assig.set_time_field("free_flow_time") # And the algorithm we want to use to assign >>> assig.set_algorithm('bfw') # Since we 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 # If you want, it is possible to access the convergence report >>> import pandas as pd >>> convergence_report = pd.DataFrame(assig.assignment.convergence_report) # 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='base_year_assignment') # 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']#
- set_vdf(vdf_function: str) None #
Sets the Volume-delay function to be used
- Arguments
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
- Arguments
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
- Arguments
traffic_class (
TrafficClass
:) Traffic class
- set_algorithm(algorithm: str)#
Chooses the assignment algorithm. e.g. ‘frank-wolfe’, ‘bfw’, ‘msa’
‘fw’ is also accepted as an alternative to ‘frank-wolfe’
- Arguments
algorithm (
str
): 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’}
- Arguments
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
AssignmentResultsBase
- Arguments
cores (
int
): Number of CPU cores to use
- set_save_path_files(save_it: bool) None #
Turn path saving on or off.
- Arguments
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.
- Arguments
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’
- Arguments
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’
- Arguments
capacity_field (
str
): Field name
- log_specification()#
- save_results(table_name: str, keep_zero_flows=True, project=None) None #
Saves the assignment results to results_database.sqlite
Method fails if table exists
- Arguments
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 project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- 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
- 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
): Dictionary with summary information
- save_skims(matrix_name: str, which_ones='final', format='omx', project=None) None #
Saves the skims (if any) to the skim folder and registers in the matrix list
- Arguments
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’ project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- select_link_flows() Dict[str, pandas.core.frame.DataFrame] #
Returns a dataframe of the select link flows for each class
- save_select_link_flows(table_name: str, project=None) None #
Saves the select link link flows for all classes into the results database. Additionally, it exports the OD matrices into OMX format.
- Arguments
table_name (
str
): Name of the table being inserted to. Note the traffic class project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- save_select_link_matrices(file_name: str) None #
Saves the Select Link matrices for each TrafficClass in the current TrafficAssignment class
- save_select_link_results(name: str) None #
Saves both the Select Link matrices and flow results at the same time, using the same name.
Note
Note the Select Link matrices will have _SL_matrices.omx appended to the end for ease of identification. e.g. save_select_link_results(“Car”) will result in the following names for the flows and matrices: Select Link Flows: inserts the select link flows for each class into the database with the table name: Car Select Link Matrices (only exports to OMX format): Car.omx
- Arguments
name (
str
): name of the matrices
- class aequilibrae.paths.traffic_assignment.TransitAssignment(*args, project=None, **kwargs)#
Bases:
aequilibrae.paths.traffic_assignment.AssignmentBase
- all_algorithms = ['optimal-strategies', 'os']#
- set_algorithm(algorithm: str)#
Chooses the assignment algorithm. Currently only ‘optimal-strategies’ is available.
‘os’ is also accepted as an alternative to ‘optimal-strategies’
- Arguments
algorithm (
str
): Algorithm to be used
- set_cores(cores: int) None #
Allows one to set the number of cores to be used AFTER transit classes have been added
Inherited from
AssignmentResultsBase
- Arguments
cores (
int
): Number of CPU cores to use
- info() dict #
Returns information for the transit assignment procedure
Dictionary contains keys ‘Algorithm’, ‘Classes’, ‘Computer name’, ‘Procedure ID’.
The classes key is also a dictionary with all the user classes per transit class and their respective matrix totals
- Returns
info (
dict
): Dictionary with summary information
- log_specification()#
- save_results(table_name: str, keep_zero_flows=True, project=None) None #
Saves the assignment results to results_database.sqlite
Method fails if table exists
- Arguments
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 project (Project
, Optional): Project we want to save the results to. Defaults to the active project
- 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
- set_time_field(time_field: str) None #
Sets the graph field that contains free flow travel time -> e.g. ‘trav_time’
- Arguments
time_field (
str
): Field name
- set_frequency_field(frequency_field: str) None #
Sets the graph field that contains the frequency -> e.g. ‘freq’
- Arguments
frequency_field (
str
): Field name
aequilibrae.paths.traffic_class module#
- class aequilibrae.paths.traffic_class.TransportClassBase(name: str, graph: aequilibrae.paths.graph.GraphBase, matrix: aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix)#
Bases:
abc.ABC
- property info: dict#
- class aequilibrae.paths.traffic_class.TrafficClass(name: str, graph: aequilibrae.paths.graph.Graph, matrix: aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix)#
Bases:
aequilibrae.paths.traffic_class.TransportClassBase
Traffic class for equilibrium traffic assignment
>>> from aequilibrae import Project >>> from aequilibrae.matrix import AequilibraeMatrix >>> from aequilibrae.paths import TrafficClass >>> project = Project.from_path("/tmp/test_project") >>> 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) >>> proj_matrices = project.matrices >>> demand = AequilibraeMatrix() >>> demand = proj_matrices.get_matrix("demand_omx") >>> demand.computational_view(['matrix']) >>> tc = TrafficClass("car", graph, demand) >>> tc.set_pce(1.3)
- set_pce(pce: Union[float, int]) None #
Sets Passenger Car equivalent
- Arguments
pce (
Union[float, int]
): PCE. Defaults to 1 if not set
- set_fixed_cost(field_name: str, multiplier=1)#
Sets value of time
- Arguments
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
- Arguments
value_of_time (
Union[float, int]
): Value of time. Defaults to 1 if not set
- set_select_links(links: Dict[str, List[Tuple[int, int]]])#
Set the selected links. Checks if the links and directions are valid. Translates link_id and direction into unique link id used in compact graph. Supply links=None to disable select link analysis.
- Arguments
- links (
Union[None, Dict[str, List[Tuple[int, int]]]]
): name of link set and Link IDs and directions to be used in select link analysis
- links (
- class aequilibrae.paths.traffic_class.TransitClass(name: str, graph: aequilibrae.paths.graph.TransitGraph, matrix: aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix, matrix_core: Optional[str] = None)#
Bases:
aequilibrae.paths.traffic_class.TransportClassBase
- set_demand_matrix_core(core: str)#
Set the matrix core to use for demand.
- Arguments
core (
str
):