aryagraph.algorithms.paths.dijkstra#

aryagraph.algorithms.paths.dijkstra(g: Graph, source: Hashable, weight: str | Callable[[Hashable, Hashable, dict], float] | None = 'weight', *, target: Hashable | None = None, cutoff: float | None = None) → tuple[NodeMap, dict[Hashable, list[Hashable]]][source]#

Dijkstra’s algorithm: distances and shortest-path predecessors from source.

Returns (dist, pred) where pred[v] lists every predecessor of v on some shortest path (pred[source] == []), which is enough to rebuild all shortest paths. With target, the search stops once target (and any node tied with it) is settled; with cutoff, nodes farther than it are left out. Weights must be non-negative (ValueError otherwise). O((n + m) log n).