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])

available_skims()

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_compressed_link_network_mapping()

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): 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 path

destination (int): destination for the path

early_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 is False.

a_star (bool): whether or not to use A* over Dijkstra’s algorithm. When True, early_exit is always True. Default is False.

heuristic (str): heuristic to use if a_star is enabled. Default is None.

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 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()
Returns:

idx (np.array): index array for data

data (np.array): array of link ids

node_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’

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.ndarray): Array with centroid IDs. Mandatory type Int64, unique and positive remove_dead_ends (bool): Whether or not to remove dead ends from the graph. (Optional, default is “True”).

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 is ‘aeg’

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

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#