Skip to main content

Module pathfinding

Module pathfinding 

Source
Expand description

Pathfinding — BFS / DFS orders, shortest paths (unweighted BFS + weighted Dijkstra), and all simple paths between two nodes. Directed (over the out view); pass an Adjacency built from undirected-doubled edges for undirected search.

Functions§

all_simple_paths
All simple paths from s to t (no repeated node), each up to max_len nodes long (a guard against exponential blow-up on dense graphs). Directed.
bfs
BFS order from s over the directed out view (nodes in the order first visited). Includes s first.
dfs
DFS pre-order from s over the directed out view (lowest-index neighbour first, so it’s deterministic). Includes s first.
dijkstra
Weighted shortest path (Dijkstra) from s to t over the directed out view. Edge weights must be non-negative. Returns (path, cost) or None.
shortest_path
Unweighted shortest path (BFS) from s to t over the directed out view. Returns the node sequence [s, …, t], or None if t is unreachable.