Dijkstra's algorithm: the invariant #
This file proves the graph theory behind Dijkstra's algorithm Dijkstra
Cormen et al., Section 24.3, independently of the machine. The algorithm keeps a set
S of visited vertices and a tentative distance D v for every vertex, and
Cslib.Algorithms.Dijkstra.Instance.Inv states what it maintains: D bounds the
distance from above, is exact on S, and is already relaxed along every edge out of S.
The key step (Cslib.Algorithms.Dijkstra.Instance.Inv.step) is the classical cut
argument: on every path from the source to an unvisited vertex, either the source is unvisited,
with tentative distance 0, or the path has an edge from S to an unvisited vertex. Either way
its weight is at least the least tentative distance outside S. Hence an unvisited
vertex of least finite tentative distance has the exact distance, and relaxing its edges keeps
the invariant with that vertex visited.
Main definitions #
Cslib.Algorithms.Dijkstra.Instance.relax: relaxation of the edges out of a vertex.Cslib.Algorithms.Dijkstra.Instance.Inv: the invariant of Dijkstra's algorithm.
Main results #
Cslib.Algorithms.Dijkstra.Instance.le_maxWeight: every edge weight is at most the largest one.Cslib.Algorithms.Dijkstra.Instance.dist_le_edge: the distance to the head of an edge is at most the distance to its tail plus its weight.Cslib.Algorithms.Dijkstra.Instance.Inv.init: the invariant holds initially.Cslib.Algorithms.Dijkstra.Instance.Inv.step: visiting an unvisited vertex of least finite tentative distance and relaxing its edges keeps the invariant.Cslib.Algorithms.Dijkstra.Instance.Inv.eq_dist: once every unvisited vertex has infinite tentative distance, the tentative distances are the distances.
References #
The invariant of Dijkstra's algorithm, for the visited set S and the tentative
distances D.
The source has tentative distance
0.Tentative distances bound the distances from above.
Tentative distances are exact on visited vertices.
Every edge from a visited vertex to an unvisited one is relaxed.
Finite tentative distances are at most
|S|times the largest weight.
The invariant holds with no vertex visited, the source at tentative distance 0 and every
other vertex at ⊤.
Dijkstra's step. Visiting an unvisited vertex u of least finite tentative distance and
relaxing its edges keeps the invariant.