Minimum-cost arborescences: the Chu–Liu/Edmonds algorithm #
Given a finite digraph G with decidable arcs, arc costs c : V → V → β in a linearly ordered
additive commutative monoid (for example ℕ, ℤ or ℚ; negative costs are allowed), and a root
r, the algorithm Cslib.Algorithms.Lean.Arborescence.edmonds returns a spanning in-arborescence
of G rooted at r of minimum total arc cost, or none if G has no spanning in-arborescence
rooted at r ([CL65], [Edm67a]).
An in-arborescence is represented by its parent function p : V → V: p r = r, v → p v is an arc
of G for v ≠ r, and every vertex reaches r by iterating p
(Cslib.Algorithms.Lean.Arborescence.IsInArborescenceParent). Its cost is
∑ v ≠ r, c v (p v). Parent functions correspond exactly to the spanning in-arborescences
T ≤ G of Digraph.IsInArborescence (isInArborescenceParent_iff, built on the parent-function
API Digraph.parentDigraph of CslibFrontier.Foundations.Combinatorics.Digraph.Arborescence), and
edmonds_optimal states optimality directly over those digraphs. Out-arborescences (arcs
directed away from the root, Edmonds' convention) are handled by reversing the arcs
(edmondsOut_spec).
The algorithm #
Every non-root vertex selects a cheapest arc v → cheapestParent v to another vertex. If the
selection has no cycle, it is an arborescence, and it is optimal because each vertex pays the least
it can. Otherwise, take a cycle C of the selection and contract it onto one of its vertices x0,
keeping the vertex type:
- an arc
u → x0fromu ∉ Cstands for the cheapest arc fromuintoC(bestEntry); - an arc
x0 → wtow ∉ Cstands for the cheapest way to leaveCtowardsw: an arcx → wwithx ∈ C, plus the selected arcs of the other vertices ofC(bestExit,exitCost); - the other vertices of
Ckeep only an arc of cost0to the root.
Then the contracted instance is solved recursively and the result expanded (expandParent): the
vertex of C that attains the exit leaves C, the other vertices of C keep their selected arcs,
and an arc into x0 becomes the cheapest arc into C. Expansion preserves cost exactly
(expandParent_spec). Conversely, every arborescence of the original instance contracts to one of
the contracted instance of at most the same cost (exists_contract_le), the exchange argument: the
vertex of C closest to the root keeps its arc out of C, and the other vertices of C gain
nothing over their selected arcs. Hence an optimal solution of the contracted instance expands to an
optimal solution of the original one.
The contracted cost of leaving the cycle includes the selected costs of the other cycle vertices,
rather than subtracting the selected cost of the leaving vertex as in the usual presentation with
reduced costs. This is the same up to a constant, and needs no subtraction, so the costs may lie in
an ordered monoid such as ℕ. Contraction strictly shrinks the set of vertices with an arc to a
vertex other than themselves and the root, so |V| levels of recursion suffice (edmonds runs
edmondsAux with fuel FinEnum.card V).
Main definitions #
Cslib.Algorithms.Lean.Arborescence.IsInArborescenceParent: parent functions of spanning in-arborescences.Cslib.Algorithms.Lean.Arborescence.parentCost: the cost of a parent function.Cslib.Algorithms.Lean.Arborescence.arcCost: the arc cost of a digraph, to state optimality overDigraph.IsInArborescence(withDigraph.parentDigraph, the digraph of a parent function).Cslib.Algorithms.Lean.Arborescence.edmonds: the Chu–Liu/Edmonds algorithm.Cslib.Algorithms.Lean.Arborescence.edmondsOut: the same for out-arborescences.
Main results #
Cslib.Algorithms.Lean.Arborescence.edmonds_spec: ifedmonds G c r = some p, thenpis a spanning in-arborescence ofGrooted atrof minimum cost; if it isnone, there is none.Cslib.Algorithms.Lean.Arborescence.edmonds_eq_none_iff:edmonds G c r = noneiffGhas no spanning in-arborescence rooted atr.Cslib.Algorithms.Lean.Arborescence.edmonds_optimal: optimality over all spanning in-arborescencesT ≤ G(Digraph.IsInArborescence), measured by their arc costarcCost.Cslib.Algorithms.Lean.Arborescence.edmondsOut_spec: the out-arborescence form.Cslib.Algorithms.Lean.Arborescence.expandParent_spec,Cslib.Algorithms.Lean.Arborescence.exists_contract_le: the contraction lemmas.
Source mapping #
[Edm67a] treats spanning arborescences with arcs directed away from a prescribed
root, maximum or minimum weight, real weights. Section 2 reduces optimum spanning arborescences to
optimum branchings. Theorem 1, stated in Section 3, asserts a good (polynomially bounded)
algorithm for optimum branchings; Section 4 gives the algorithm, which selects the best arc into
each node and contracts cycles, and its proof. This module proves correctness and optimality of
that cycle-contraction algorithm, specialised to rooted minimum-cost spanning arborescences. It
does not prove the polynomial-time content of Theorem 1 (see Limitations). [CL65] gives the
same contraction algorithm for shortest arborescences (not inspected here). [Sch03],
Section 52.1 ("Finding a shortest r-arborescence"), is a textbook locator (from the table of
contents; not inspected). The theorems here are for in-arborescences, with costs in any linearly
ordered additive commutative monoid; edmondsOut_spec is Edmonds' orientation.
Limitations #
edmonds is executable but not efficient, and no running-time bound is proved. Each level of the
recursion receives the contracted arcs and costs as closures over those of the previous level,
without memoisation, so evaluating one contracted arc or cost re-evaluates the previous level many
times, and the worst-case running time is exponential in the number of nested contractions. A
polynomial version, such as the O(n m) bound, needs materialised per-level arc and cost tables;
Tarjan's O(m log n) and the Gabow–Galil–Spencer–Tarjan O(m + n log n) implementations are not
formalized either. Optimum
branchings (forests of maximum weight, Edmonds' Theorem 1 itself) and the branching polytope
(Edmonds' Theorem 2) are not treated.
References #
Parent functions of arborescences #
p is the parent function of a spanning in-arborescence rooted at r in the relation R:
the root is fixed, every other vertex has an arc v → p v, and every vertex reaches r by
iterating p.
In an arborescence no vertex other than the root is its own parent.
The cost ∑ v ≠ r, c v (p v) of the arcs v → p v of a parent function.
Correspondence with Digraph.IsInArborescence #
Parent functions of spanning in-arborescences of G are exactly the parent functions whose
digraph is a spanning in-arborescence (Digraph.IsInArborescence) contained in G.
The arc cost ∑_{v → w ∈ T} c v w of a digraph.
The arc cost of the digraph of a parent function is its cost.
Cheapest arcs #
The root, for r; otherwise a cheapest candidate parent (or v itself if there is none).
Cycles of the selection #
A vertex other than r on a cycle of f, if there is one.
The orbit of x0 under f; the cycle through x0 when x0 is periodic.
Contraction and expansion #
The cost of leaving C from x along x → w, plus the selected arcs y → f y of the other
vertices of C.
A vertex of C with an arc to w of least exit cost, if any.
A cheapest arc from u into C, by its head, if any.
The arcs after contracting C onto x0: x0 has an arc to w ∉ C if some vertex of C
has, u ∉ C has an arc to x0 if it has one into C, the other vertices of C have only an arc
to r, and arcs outside C are unchanged.
The arc costs after contracting C onto x0: leaving x0 costs the best exit cost,
entering x0 costs the cheapest arc into C, the other vertices of C pay 0, and arcs outside
C keep their costs.
Expand a parent function q of the contracted instance: the vertex of C attaining the best
exit towards q x0 takes that arc, the other vertices of C keep f, and an arc into x0
becomes the cheapest arc into C.
Expansion. If C is a cycle of f avoiding r, along arcs of a, then every
arborescence q of the contracted instance expands to an arborescence of the original instance
of the same cost.
Exchange. If every vertex v ≠ r selects a cheapest arc v → f v, then every
arborescence t of the original instance contracts to an arborescence of the contracted instance
of at most the same cost: the vertex of C closest to r in t keeps its arc out of C, the
other vertices of C point to r, and arcs into C are redirected to x0.
The algorithm #
The vertices other than r with an arc to a vertex other than themselves and r. Contraction
strictly shrinks this set (liveVertices_ssubset).
Contraction strictly shrinks the set of live vertices.
A graph has strictly fewer live vertices than FinEnum.card V (since r is not live).
The Chu–Liu/Edmonds recursion with fuel n, on arcs a and costs c: select cheapest
arcs; return them if they form no cycle, otherwise contract a cycle, recurse and expand.
The Chu–Liu/Edmonds algorithm: a minimum-cost spanning in-arborescence of G rooted at
r, as a parent function, or none if G has no spanning in-arborescence rooted at r.
The Chu–Liu/Edmonds algorithm for out-arborescences, with arcs directed away from the root:
p v → v is an arc of G for v ≠ r, and the cost is ∑ v ≠ r, c (p v) v.
Correctness of Chu–Liu/Edmonds. If edmonds G c r = some p, then p is the parent
function of a spanning in-arborescence of G rooted at r whose cost is at most that of every
other one; if edmonds G c r = none, then G has no spanning in-arborescence rooted at r.
edmonds fails exactly when there is no spanning in-arborescence rooted at r.
Optimality over spanning in-arborescences. If edmonds G c r = some p, then the digraph
of p is a spanning in-arborescence of G rooted at r (Digraph.IsInArborescence), and its
arc cost is at most that of every spanning in-arborescence T ≤ G rooted at r.
Correctness for out-arborescences. If edmondsOut G c r = some p, then every vertex
v ≠ r has an arc p v → v of G, iterating p reaches r, and the cost
∑ v ≠ r, c (p v) v is least among all such p; if it is none, there is no such p.