aequilibrae.paths.graph#

Classes

Graph(*args, **kwargs)

GraphBase([logger])

Graph class.

NetworkGraphIndices(network_ab_idx, ...)

TransitGraph([config, od_node_mapping])

class aequilibrae.paths.graph.Graph(*args, **kwargs)[source]#
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 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()

>>> project.close()
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 or None, optional): Array with centroid IDs. Mandatory type Int64, unique and positive.

remove_dead_ends (bool, optional): Whether or not to remove dead ends from the graph. Defaults to 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 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

class aequilibrae.paths.graph.GraphBase(logger=None)[source]#

Graph class.

AequilibraE graphs implement two forms of compression.
  • link contraction, and

  • dead end removal.

Link contraction creates a topological equivalent graph by contracting sequences of links between nodes with degrees of two. This compresses long streams of links, such as along highways or curved roads, into single links.

Dead end removal attempts to remove dead ends and fish spines from the network. It does this based on the observation that in a graph with non-negative weights a dead end will only ever appear in the results of a short(est) path if the origin or destination is present within that dead end.

Dead end removal is applied before link contraction and does not create a strictly topological equivalent graph, however, all centroids are preserved.

The compressed graph is used internally.

available_skims() List[str][source]#

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)[source]#

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)[source]#

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

>>> project.close()
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)[source]#

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[source]#

Loads graph from disk

Arguments:

filename (str): Path to file

prepare_graph(centroids: ndarray | None = None, remove_dead_ends: bool = True) None[source]#

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 or None, optional): Array with centroid IDs. Mandatory type Int64, unique and positive.

remove_dead_ends (bool, optional): Whether or not to remove dead ends from the graph. Defaults to True.

save_compressed_correspondence(path, mode_name, mode_id)[source]#

Save graph and nodes_to_indices to disk

save_to_disk(filename: str) None[source]#

Saves graph to disk

Arguments:

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

set_blocked_centroid_flows(block_centroid_flows) None[source]#

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[source]#

Sets the field to be used for path computation

Arguments:

cost_field (str): Field name. Must be numeric

set_skimming(skim_fields: list) None[source]#

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

class aequilibrae.paths.graph.NetworkGraphIndices(network_ab_idx: <built-in function array>, network_ba_idx: <built-in function array>, graph_ab_idx: <built-in function array>, graph_ba_idx: <built-in function array>)[source]#
graph_ab_idx: array#
graph_ba_idx: array#
network_ab_idx: array#
network_ba_idx: array#
class aequilibrae.paths.graph.TransitGraph(config: dict | None = None, od_node_mapping: DataFrame | None = None, *args, **kwargs)[source]#
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 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()

>>> project.close()
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 or None, optional): Array with centroid IDs. Mandatory type Int64, unique and positive.

remove_dead_ends (bool, optional): Whether or not to remove dead ends from the graph. Defaults to 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 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#