Skip to main content
Ctrl+K

AequilibraE

    • Main menu
    • The AequilibraE Project
    • Run module
    • Network manipulation
    • Distribution Procedures
    • Path Computation
    • Traffic Assignment
    • Public Transport
    • Route choice
    • Other Applications
  • Python
  • QGIS
  • GitHub
    • Main menu
    • The AequilibraE Project
    • Run module
    • Network manipulation
    • Distribution Procedures
    • Path Computation
    • Traffic Assignment
    • Public Transport
    • Route choice
    • Other Applications
  • Python
  • QGIS
  • GitHub

Section Navigation

Network Manipulation

  • Importing and exporting the network
  • Dealing with Geometries
  • Turn Restrictions
  • Examples
    • Create project from Overture Maps (or OpenStreetMap)
    • Editing network geometry: Nodes
    • Editing network geometry: Links
    • Exporting network to GMNS
    • Exploring the network on a notebook
    • Editing network geometry: Splitting link
    • Create centroid connectors
    • Create project from GMNS
    • Finding disconnected links
    • Create project from a link layer
    • Network simplifier
  • Network Manipulation
  • Examples
  • Finding disconnected links

Note

Go to the end to download the full example code.

Finding disconnected links#

In this example, we show how to find disconnected links in an AequilibraE network.

We use the Nauru example to find disconnected links.

See also

Several functions, methods, classes and modules are used in this example:

  • aequilibrae.routing.results.path_results()

# Imports
from uuid import uuid4
from tempfile import gettempdir
from os.path import join
from datetime import datetime
import pandas as pd
import numpy as np
from aequilibrae.examples import create_example
from aequilibrae.routing import PathResults
# We create an empty project on an arbitrary folder
fldr = join(gettempdir(), uuid4().hex)

# Let's use the Nauru example project for display
project = create_example(fldr, "nauru")

# Let's analyse the mode car or 'c' in our model
mode = "c"

We can create an uncompressed graph without any centroids or changes to the project.

# We get the project nodes for reporting and load an independent network snapshot.
nodes = project.tables.nodes
network = project.road.build_network()
# No centroid changes need reverting: the project nodes have not been modified.

We set the graph for computation

graph = network.build_graph(mode=mode, cost="distance", skimming=["distance"], block_centroid_flows=False)

Get the nodes that are part of the car network

missing_nodes = nodes.data.query("modes.str.contains(@mode)")["node_id"].values

Now we can compute all the path islands we have

islands = []
idx_islands = 0

while missing_nodes.shape[0] >= 2:
    print(datetime.now().strftime("%H:%M:%S"), f" - Computing island: {idx_islands}")
    res = PathResults(graph, missing_nodes[0], missing_nodes[1])
    connected = res.node_ids[res.terminal_states != res.search_results.sentinel]
    connected = np.intersect1d(missing_nodes, connected)
    missing_nodes = np.setdiff1d(missing_nodes, connected)
    print(f"    Nodes to find: {missing_nodes.shape[0]:,}")
    df = pd.DataFrame({"node_id": connected, "island": idx_islands})
    islands.append(df)
    idx_islands += 1

print(f"\nWe found {idx_islands} islands")
08:26:53  - Computing island: 0
    Nodes to find: 2
08:26:53  - Computing island: 1
    Nodes to find: 0

We found 2 islands

Let’s consolidate everything into a single DataFrame

islands = pd.concat(islands)

# And save to disk alongside our model
islands.to_csv(join(fldr, "island_outputs_complete.csv"), index=False)

If you join the node_id field in the CSV file generated above with the a_node or b_node fields in the links table, you will have the corresponding links in each disjoint island found.

project.close()

Total running time of the script: (0 minutes 0.108 seconds)

Download Jupyter notebook: plot_find_disconnected.ipynb

Download Python source code: plot_find_disconnected.py

Download zipped: plot_find_disconnected.zip

Gallery generated by Sphinx-Gallery

previous

Create project from GMNS

next

Create project from a link layer

Show Source

© Copyright 2026-11-19, AequilibraE developers.

Created using Sphinx 9.0.4.

Built with the PyData Sphinx Theme 0.24.0.