AequilibraE Graphs#

A Network stores source link attributes, modes, centroids, and turn restrictions. Its build_graph() method returns an array-backed Graph for routing. The graph has fixed topology. Its costs can change without a rebuild.

Graphs from a model#

A project network can supply the source tables:

>>> project = create_example(project_path, "coquimbo")
>>> network = project.road.build_network()
>>> graph = network.build_graph('c', cost='distance')

The source tables do not retain project connections. Later changes to project data do not change this network or its prepared graphs.

To restrict the source data to an area, supply a polygon:

>>> from shapely.geometry import Polygon

>>> polygon = Polygon([(-71.35, -29.95), (-71.35, -29.90), (-71.30, -29.90), (-71.30, -29.95), (-71.35, -29.95)])
>>> network = project.road.build_network(limit_to_area=polygon)

The area filter uses a spatial index. It does not clip links to the polygon boundary.

Skimming and centroids#

Skim fields, centroids, and centroid-flow blocking are graph construction options:

>>> graph = network.build_graph(
...     'c', cost='distance',
...     centroids=network.centroids[:5],
...     skimming=['distance'], block_centroid_flows=False,
... )
>>> skimmer = graph.compute_skims()

Without an explicit centroid array, the graph uses network.centroids. Centroids must be unique, positive node IDs from the network. Their order determines the row and column order of skim matrices. To change centroids or skim fields, build a new graph.

Compact graphs#

A compact graph contracts chains of links. Dead-end removal is an additional, separate option. These reductions can reduce routing work for traffic assignment and centroid-to-centroid skimming. Both are opt-in when building a graph, and both require centroids. PathResults.path contains local graph-link indices, and get_network_links() expands these to physical link IDs and directions in traversal order.

To enable both reductions:

>>> compact = network.build_graph('c', cost='distance', compact=True, remove_dead_ends=True)

Traffic assignment enables both reductions by default. Each TrafficClass can override compact and remove_dead_ends through its graph_options. Congestion calculations still use individual directed network links.

Blocking centroid flows#

By default, prepared graphs block paths through intermediate centroids. For turn-based routing, automatic turn prohibitions prevent traversal between centroid connectors at the same centroid.

Suppose a path from N1 to C3 follows N1 -> N3 -> C2 -> N6 -> C3 in the figure. Centroid-flow blocking prohibits the connector-to-connector transition at C2. The path must use another route.

If regular network nodes serve as centroids, consider whether routes must pass through those nodes. Use block_centroid_flows=False to permit those routes.

example of aequilibrae graph