aequilibrae.transit#

Classes

TransitAssignment(*args[, project])

TransitAssignmentResults()

Transit loads are owned by the hyperpath computation.

TransitClass(*, name, matrix, graph, results)

Transit demand bound to a transit graph for hyperpath assignment.

TransitGraph(network, centroids, time_field, ...)

class aequilibrae.transit.TransitAssignment(*args, project=None, **kwargs)[source]#
add_class(transport_class: TransitClass) → None[source]#

Adds a Transit class to the assignment

Arguments:

transport_class (TransitClass): Transit class

algorithms_available() → list#

Returns all algorithms available for use

Returns:

list: Available algorithm names

execute(log_specification=True) → None#

Processes assignment

get_skim_results() → dict#

Return assignment skims by class name.

info() → dict[source]#

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()[source]#
report() → DataFrame#

Returns the assignment convergence report

Returns:

DataFrame (pd.DataFrame): Convergence report

results() → DataFrame[source]#

Prepares the assignment results as a Pandas DataFrame

Returns:

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

save_results(table_name: str, keep_zero_flows=True, project=None) → None[source]#

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 explicitly supplied constructor project

set_algorithm(algorithm: str)[source]#

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_classes(classes: list[TransitClass]) → None[source]#

Sets Transit classes to be assigned

Arguments:

classes (List[TransitClass]): List of TransitClass’s for assignment

set_cores(cores: int, threading_threshold: int | None = None, elementwise_cores: int | None = None) → None[source]#

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

threading_threshold (int, Optional): Minimum number of array elements for elementwise operations to be threaded. Negative values disable threading for those operations. When not provided, the current value is kept

elementwise_cores (int, Optional): Number of CPU cores for elementwise (parallel_numpy/VDF) operations. When not provided, it is resolved from the AEQ_ELEMENTWISE_CPUS environment variable or parameters.yml, defaulting to at most 8 threads

set_frequency_field(frequency_field: str) → None[source]#

Sets the graph field that contains the frequency -> e.g. ‘freq’

Arguments:

frequency_field (str): Field name

set_skimming_fields(skimming_fields: list[str] = None) → None[source]#

Sets the skimming fields for the transit assignment.

Also accepts predefined skimming fields:
  • discrete: ‘boardings’, ‘alightings’, ‘inner_transfers’, ‘outer_transfers’, and ‘transfers’.

  • continuous: ‘trav_time’, ‘on_board_trav_time’, ‘dwelling_time’, ‘egress_trav_time’, ‘access_trav_time’, ‘walking_trav_time’, ‘transfer_time’, ‘in_vehicle_trav_time’, and ‘waiting_time’.

Provide no argument to disable.

Arguments:

skimming_fields (list[str]): Optional list of field names, or predefined skimming type.

set_time_field(time_field: str) → None[source]#

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

Arguments:

time_field (str): Field name

algorithm: str#
all_algorithms = ['optimal-strategies', 'os']#
classes: list#
cores: int#
description: str#
elementwise_cores: int#
free_flow_tt: ndarray#
threading_threshold: int#
time_field: str#
total_flow: ndarray#
class aequilibrae.transit.TransitAssignmentResults[source]#

Transit loads are owned by the hyperpath computation.

get_load_results()[source]#
prepare(graph, matrix)[source]#
reset()[source]#
set_cores(cores, threading_threshold=None, elementwise_cores=None)#

Set thread counts without reallocating or clearing existing results.

class aequilibrae.transit.TransitClass(*, name: str, matrix: AequilibraeMatrix | AequilibraeSparseMatrix, graph: object = None, results: TransitAssignmentResults = <factory>)[source]#

Transit demand bound to a transit graph for hyperpath assignment.

graph: object = None#
property info#
matrix: AequilibraeMatrix | AequilibraeSparseMatrix#
name: str#
results: TransitAssignmentResults#
class aequilibrae.transit.TransitGraph(network: DataFrame, centroids: ndarray, time_field: str, frequency_field: str, od_node_mapping: DataFrame, a_node_field: str = 'a_node', b_node_field: str = 'b_node', skimming_fields: list[str] | None = None, config: dict | None = None)[source]#
available_skims() → List[str]#

Returns graph fields that are available to be set as skims.

Returns:

list (str): Skimmeable field names

clear_turn_restrictions() → None#

Clears all turn restrictions and rebuilds the prepared graph.

compute_path(origin: int, destination: int, early_exit: bool = False, a_star: bool = False, heuristic: str | None = None, *, coordinates: pd.DataFrame | None = None, heuristic_scale: float | None = None) → PathResults#

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): euclidean (default) or haversine if A* is enabled.

coordinates (pandas.DataFrame, optional): Planar x and y columns indexed by external node ID, required for Euclidean A*. Haversine uses the graph’s longitude/latitude.

heuristic_scale (float): Finite, nonnegative coefficient required for A*. Use aequilibrae.routing.estimate_heuristic_scale for a conservative bound. A larger scale can give non-shortest paths.

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.

Road graphs expose the corresponding arrays through graph.mapping. These use directed network link indices and dense network node indices, rather than the legacy graph IDs and external node IDs used by this method.

>>> project = create_example(project_path)

>>> network = project.road.build_network()
>>> graph = network.build_graph("c", centroids=np.arange(1, 25), compact=True, remove_dead_ends=True)

>>> idx = graph.mapping.expansion_offsets
>>> data = graph.mapping.expansion_links
>>> node_mapping = graph.mapping.network_node_to_graph

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

disconnected_nodes() → ndarray#

Identify disconnected nodes using strongly connected components analysis.

This method is not available for builder graphs. Use a prepared Graph instead.

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

prepare_graph(centroids: ndarray | None = None, remove_dead_ends: bool = True, allow_uturns_everywhere: bool = False) → 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.

allow_uturns_everywhere (bool, optional): Allow U-turns at all possible places within the

graph. This will allow U-turns anywhere that has both an incoming and outgoing link, severely hindering the effectiveness of graph compression. This is option should rarely be used. The U-turns allowed by this option will never be taken unless turn penalties are set. Refer to graph.set_turn_restrictions to allow U-turns at intersections. This option will reduce the effectiveness of dead-end link removal and graph compression.

reverse()#
save_compressed_correspondence(path, mode_name, mode_id)#

Save graph and nodes_to_indices to disk

set_blocked_centroid_flows(block_centroid_flows) → None#

Chooses whether paths are allowed to pass through centroid connector turns.

With explicit turn restrictions, turn restrictions between centroid connectors are inserted.

Default value is True.

Arguments:

block_centroid_flows (bool): Whether to block flows 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

set_skimming_fields(skimming_fields: list[str] | None = None) → None[source]#

Set the fields to skim and rebuild the hyperpath context if needed.

set_turn_penalty_dimension(unit: str)#

Sets the unit for turn penalties.

set_turn_restrictions(turn_restrictions: DataFrame, allow_path_uturns: bool = False) → None#

Sets turn restrictions for the graph. When turn restrictions are set, the graph will use arc-based Dijkstra for path computation.

Turn penalties are in the same time unit as the graph’s cost field. Prepared graphs are rebuilt using their existing preparation settings, and their cost and skim fields are restored.

Arguments:
turn_restrictions (pd.DataFrame): DataFrame with columns:
  • from_node: incoming leg origin node

  • via_node: turn node

  • to_node: outgoing leg destination node

  • penalty: turn penalty in time units

None, NaN and +inf are treated as prohibited turns. Negative values are not allowed.

Restrictions are interpreted as directed movement sequences from_node -> via_node -> to_node. All three nodes and both directed legs must exist in the full graph.

allow_path_uturns (bool): Whether U-turns are allowed within paths.

U-turns are transitions that return to the same node immediately before the turn. Default is False.

property allow_path_uturns: bool#

Returns the current allow path U-turn permission setting.

property allow_uturns_everywhere: bool#

Returns the allow U-turns everywhere setting that was used to build the graph.

property config#
property has_turn_restrictions: bool#

Returns True if the graph has turn restrictions loaded and active.