Documentation

CslibFrontier.Algorithms.Dijkstra.ListInstance

Shortest paths on adjacency lists #

An instance (Cslib.Algorithms.Dijkstra.ListInstance) is a directed graph on Fin n given by its adjacency lists of (target, weight) pairs, with natural-number weights, and a source vertex. The lists may repeat a pair of endpoints (parallel edges) and may contain self-loops. The instance determines a weight-matrix instance of Cslib.Algorithms.Dijkstra.Instance that keeps, for each pair of endpoints, the lightest of its edges (Cslib.Algorithms.Dijkstra.ListInstance.toInstance); the distance is the distance of that instance Dijkstra Cormen et al., Section 24.3.

Scanning the edges out of a vertex u in list order, and lowering the tentative distance of each target v to that of u plus the weight, has the effect of relaxing u in the weight-matrix instance (Cslib.Algorithms.Dijkstra.ListInstance.relaxEdges_eq_relax): the scan of all parallel edges to v has the effect of the lightest one. Nothing here refers to a machine: the interface client (CslibFrontier.Algorithms.Lean.Dijkstra.Client) uses this directly, and the word-RAM statements (CslibFrontier.Algorithms.WordRAM.Dijkstra.HeapStatement) add the input words.

Main definitions #

Main results #

References #

An instance of the single-source shortest-path problem by adjacency lists: a directed graph on Fin n and a source vertex. The list adj u holds a pair (v, c) for each edge from u to v of weight c; it may hold several pairs with the same v.

  • n : ℕ

    The number of vertices.

  • adj : Fin self.n → List (Fin self.n × ℕ)

    The adjacency lists.

  • source : Fin self.n

    The source.

The least weight of an edge from u to v, and none when there is no such edge.

The weight-matrix instance with the same vertices and source, whose entry for u and v is the least weight of an edge from u to v. Keeping a lightest edge between each pair preserves distances.

The shortest-path distance from u to v: the distance of the weight-matrix instance, Cslib.Algorithms.Dijkstra.Instance.dist.

The largest edge weight, and 0 when there is no edge.

theorem Cslib.Algorithms.Dijkstra.ListInstance.lightest_eq_some_iff (G : ListInstance) {u v : Fin G.n} {c : ℕ} :
G.lightest u v = some c ↔ (v, c) ∈ G.adj u ∧ ∀ (c' : ℕ), (v, c') ∈ G.adj u → c ≤ c'

The matrix entry of u and v is c exactly when c is the least weight of an edge from u to v.

The matrix entry of u and v is absent exactly when there is no edge from u to v.

Every edge weight is at most the largest weight.

The largest weight of the weight-matrix instance is at most the largest edge weight.

noncomputable def Cslib.Algorithms.Dijkstra.ListInstance.relaxEdges {N : ℕ} (b : ℕ∞) (es : List (Fin N × ℕ)) (v : Fin N) (d : ℕ∞) :

The tentative distance d of v after scanning the edges of es in order from a vertex at tentative distance b: each edge (v, c) lowers it to at most b + c.

theorem Cslib.Algorithms.Dijkstra.ListInstance.relaxEdges_eq_relax (G : ListInstance) (D : Fin G.n → ℕ∞) (u v : Fin G.n) :
relaxEdges (D u) (G.adj u) v (D v) = G.toInstance.relax D u v

Scanning the edges out of u relaxes the tentative distances: from tentative distances D, scanning the list of u lowers the tentative distance of v to its relaxation in the weight-matrix instance.