aequilibrae.paths.TransitGraph#
- class aequilibrae.paths.TransitGraph(config: dict | None = None, od_node_mapping: DataFrame | None = None, *args, **kwargs)[source]#
- __init__(config: dict | None = None, od_node_mapping: DataFrame | None = None, *args, **kwargs)[source]#
Methods
__init__([config, od_node_mapping])Returns graph fields that are available to be set as skims.
compute_path(origin, destination[, ...])Returns the results from path computation result holder.
compute_skims([cores])Returns the results from network skimming result holder.
Create three arrays providing a mapping of compressed ID to link ID.
default_types(tp)Returns the default integer and float types used for computation
exclude_links(links)Excludes a list of links from a graph by setting their B node equal to their A node
load_from_disk(filename)Loads graph from disk
prepare_graph([centroids, remove_dead_ends])Prepares the graph for a computation for a certain set of centroids.
save_compressed_correspondence(path, ...)Save graph and nodes_to_indices to disk
save_to_disk(filename)Saves graph to disk
set_blocked_centroid_flows(block_centroid_flows)Chooses whether we want to block paths to go through centroids or not.
set_graph(cost_field)Sets the field to be used for path computation
set_skimming(skim_fields)Sets the list of skims to be computed
Attributes
- available_skims() List[str]#
Returns graph fields that are available to be set as skims.
- Returns:
list (
str): Skimmeable field names
- compute_path(origin: int, destination: int, early_exit: bool = False, a_star: bool = False, heuristic: str | None = None)#
Returns the results from path computation result holder.
- Arguments:
origin (
int): origin for the pathdestination (
int): destination for the pathearly_exit (
bool): stop constructing the shortest path tree once the destination is found. Doing so may cause subsequent calls to ‘update_trace’ to recompute the tree. Default isFalse.a_star (
bool): whether or not to use A* over Dijkstra’s algorithm. WhenTrue, ‘early_exit’ is alwaysTrue. Default isFalse.heuristic (
str): heuristic to use ifa_staris enabled. Default isNone.
- compute_skims(cores: int | None = None)#
Returns the results from network skimming result holder.
- Arguments:
cores (
Union[int, None]): number of cores (threads) to be used in computation
- create_compressed_link_network_mapping()#
Create three arrays providing a mapping of compressed ID to link ID.
Uses sparse compression. Index ‘idx’ by the by compressed ID and compressed ID + 1, the network IDs are then in the range
idx[id]:idx[id + 1].Links not in the compressed graph are not contained within the ‘data’ array.
‘node_mapping’ provides an easy way to check if a node index is present within the compressed graph. If the value is -1 then the node has been removed, either by compression of dead end link removal. If the value is greater than or equal to 0, then that value is the compressed node index.
>>> project = create_example(project_path) >>> project.network.build_graphs() >>> graph = project.network.graphs['c'] >>> graph.prepare_graph(np.arange(1,25)) >>> idx, data, node_mapping = graph.create_compressed_link_network_mapping() >>> project.close()
- Returns:
idx (
np.array): index array fordatadata (
np.array): array of link idsnode_mapping: (
np.array): array of node_mapping ids
- default_types(tp: str)#
Returns the default integer and float types used for computation
- Arguments:
tp (
str): data type. ‘int’ or ‘float’
- 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
- load_from_disk(filename: str) None#
Loads graph from disk
- Arguments:
filename (
str): Path to file
- prepare_graph(centroids: ndarray | None = None, remove_dead_ends: bool = True) 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.ndarrayorNone, optional): Array with centroid IDs. Mandatory typeInt64, unique and positive.remove_dead_ends (
bool, optional): Whether or not to remove dead ends from the graph. Defaults toTrue.
- save_compressed_correspondence(path, mode_name, mode_id)#
Save graph and nodes_to_indices to disk
- save_to_disk(filename: str) None#
Saves graph to disk
- Arguments:
filename (
str): Path to file. Usual file extension isaeg.
- 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 paths to go through centroids.
- 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 traditional Dijkstra’s due to its use a heuristic.
- Arguments:
skim_fields (
list): Fields must be numeric
- property config#