Documentation

CslibFrontier.Algorithms.Lean.Arborescence.Branching

Optimum branchings via Chu–Liu/Edmonds #

A branching in a directed graph G (Digraph.IsBranching) is a directed forest of disjoint out-arborescences (Edmonds1967Branchings, Section 1). Using the Option V super-root correspondence from CslibFrontier.Foundations.Combinatorics.Digraph.Branching (Digraph.superRootDigraph, Digraph.superRootExtend, Digraph.restrictOption), this module reduces maximum-weight branching on (G, w) to minimum-cost spanning in-arborescence on (G.superRootDigraph, superRootCost w, none) (optimumBranching).

Because every vertex some v has an arc to the super-root none of cost 0 while real arcs some v → some u carry negated cost -w u v, the super-root reduction preserves exact weights up to negation (arcCost_superRootExtend), always succeeds without a separate shift constant, and also yields minimum-weight branchings via -w (minBranching). We also formalize Edmonds' weight-shift reductions from [Edmonds1967Branchings, Section 2] (edmonds_shift_weight_branching, edmonds_rooted_outArborescence_of_shift) characterizing maximum-cardinality branchings and rooted spanning out-arborescences under weight shift h > ∑ |w_e|. Machine-level running-time certificates live in CslibFrontier.Algorithms.WordRAM.Arborescence (Word-RAM O(n³)) and CslibFrontier.Algorithms.Lean.Arborescence.PolyTime (multi-tape Turing-machine P).

Main definitions #

Main results #

References #

FinEnum (Option V) and super-root costs #

Equivalence identifying Option V with Fin (FinEnum.card V + 1) while keeping none at the last index.

@[instance_reducible]

Explicit FinEnum (Option V) with .card = FinEnum.card V + 1 definitionally.

def Cslib.Algorithms.Lean.Arborescence.superRootCost {V : Type u_1} {β : Type u_2} [Zero β] [Neg β] (w : V → V → β) :
Option V → Option V → β

Super-root arc cost on Option V: real reversed arcs some v → some u carry negated weight -w u v, while fallback arcs to none carry cost 0.

Extending a branching B to Option V negates its total arc weight under superRootCost w.

theorem Cslib.Algorithms.Lean.Arborescence.arcCost_neg {V : Type u_1} {β : Type u_2} [Fintype V] [AddCommGroup β] (B : Digraph V) [DecidableRel B.Adj] (w : V → V → β) :
(arcCost B fun (u v : V) => -w u v) = -arcCost B w

Negating all arc weights negates arcCost.

theorem Cslib.Algorithms.Lean.Arborescence.arcCost_congr {V : Type u_1} {β : Type u_2} (inst₁ inst₂ : Fintype V) [m : AddCommMonoid β] {T₁ T₂ : Digraph V} (d₁ : DecidableRel T₁.Adj) (d₂ : DecidableRel T₂.Adj) (h : T₁ = T₂) (c : V → V → β) :
arcCost T₁ c = arcCost T₂ c

Congruence of arcCost across Fintype, DecidableRel, and equal digraphs.

Restricting Option V parent maps and super-root feasibility #

Project an Option V → Option V parent map to V → V, turning none parents into fixed points (branching roots).

When parentDigraph none p is a spanning in-arborescence on Option V rooted at none, branchingDigraph (restrictParent p) coincides with Digraph.restrictOption (parentDigraph none p).

Running edmonds on (G.superRootDigraph, superRootCost w, none) always returns some p because fun _ => none is always a feasible spanning in-arborescence parent map.

def Cslib.Algorithms.Lean.Arborescence.optimumBranchingParent {β : Type u_1} [LinearOrder β] [AddCommGroup β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) :
V → V

Parent-towards-root map returned by the super-root Chu–Liu/Edmonds reduction for an optimum (maximum-weight) branching of (G, w).

def Cslib.Algorithms.Lean.Arborescence.optimumBranching {β : Type u_1} [LinearOrder β] [AddCommGroup β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) :

Maximum-weight branching digraph of (G, w) computed via the Option V super-root reduction to edmonds.

@[instance_reducible]

Correctness and optimality of optimumBranching: optimumBranching G w is a branching contained in G, and maximizes arcCost B w over all branchings B ≤ G.

theorem Cslib.Algorithms.Lean.Arborescence.optimumBranching_optimal {β : Type u_1} [LinearOrder β] [AddCommGroup β] [IsOrderedAddMonoid β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) (B : Digraph V) [DecidableRel B.Adj] (hB : B.IsBranching) (hBG : B ≤ G) :
def Cslib.Algorithms.Lean.Arborescence.minBranching {β : Type u_1} [LinearOrder β] [AddCommGroup β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) :

Minimum-weight branching of (G, w) via negated weights.

@[instance_reducible]
theorem Cslib.Algorithms.Lean.Arborescence.minBranching_optimal {β : Type u_1} [LinearOrder β] [AddCommGroup β] [IsOrderedAddMonoid β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) (B : Digraph V) [DecidableRel B.Adj] (hB : B.IsBranching) (hBG : B ≤ G) :

Edmonds (1967, Section 2) weight-shift and rooted reductions #

theorem Cslib.Algorithms.Lean.Arborescence.arcCost_add_const {V : Type u_2} {β : Type u_3} [Fintype V] [AddCommMonoid β] (T : Digraph V) [DecidableRel T.Adj] (w : V → V → β) (h : β) :
(arcCost T fun (u v : V) => w u v + h) = arcCost T w + {e : V × V | T.Adj e.1 e.2}.card • h

Adding a uniform constant h to every arc shifts arcCost by card_arcs * h.

theorem Cslib.Algorithms.Lean.Arborescence.arcCost_sub_arcCost_le {β : Type u_1} [LinearOrder β] [AddCommGroup β] [IsOrderedAddMonoid β] {V : Type u_2} [Fintype V] {B₁ B₂ G : Digraph V} [DecidableRel B₁.Adj] [DecidableRel B₂.Adj] [DecidableRel G.Adj] (h1 : B₁ ≤ G) (h2 : B₂ ≤ G) (w : V → V → β) :
arcCost B₁ w - arcCost B₂ w ≤ ∑ e : V × V with G.Adj e.1 e.2, max (w e.1 e.2) (-w e.1 e.2)

For any two subdigraphs B₁, B₂ ≤ G, the weight difference arcCost B₁ w - arcCost B₂ w is bounded above by the sum of max (w e) (-w e) over all arcs of G.

theorem Cslib.Algorithms.Lean.Arborescence.edmonds_shift_weight_branching {β : Type u_1} [LinearOrder β] [AddCommGroup β] [IsOrderedAddMonoid β] {V : Type u_2} [FinEnum V] (G : Digraph V) [DecidableRel G.Adj] (w : V → V → β) (h : β) (hh : ∑ e : V × V with G.Adj e.1 e.2, max (w e.1 e.2) (-w e.1 e.2) < h) :
let Bstar := optimumBranching G fun (u v : V) => w u v + h; Bstar.IsBranching ∧ Bstar ≤ G ∧ (∀ (B : Digraph V) [inst : DecidableRel B.Adj], B.IsBranching → B ≤ G → {e : V × V | B.Adj e.1 e.2}.card ≤ {e : V × V | Bstar.Adj e.1 e.2}.card ∧ ({e : V × V | B.Adj e.1 e.2}.card = {e : V × V | Bstar.Adj e.1 e.2}.card → arcCost B w ≤ arcCost Bstar w)) ∧ (Nonempty V → (∃ (r : V) (T : Digraph V), T.IsOutArborescence r ∧ T ≤ G) → (∃ (r : V), Bstar.IsOutArborescence r) ∧ ∀ (r : V) (T : Digraph V) [inst : DecidableRel T.Adj], T.IsOutArborescence r → T ≤ G → arcCost T w ≤ arcCost Bstar w)

Edmonds (1967, Section 2) weight-shift reduction: Adding h > ∑_{e ∈ G} |w_e| to every arc weight makes an optimum branching maximize the number of arcs across all branchings B ≤ G, and break ties by arcCost · w. When G contains a spanning out-arborescence, the shifted optimum branching is a maximum-weight spanning out-arborescence of (G, w).

Subgraph obtained from G by deleting all arcs entering a designated root r₀.

@[simp]
theorem Cslib.Algorithms.Lean.Arborescence.rootedDigraph_adj {V : Type u_2} {G : Digraph V} {r₀ u v : V} :
(rootedDigraph G r₀).Adj u v ↔ v ≠ r₀ ∧ G.Adj u v
theorem Cslib.Algorithms.Lean.Arborescence.edmonds_rooted_outArborescence_of_shift {β : Type u_1} [LinearOrder β] [AddCommGroup β] [IsOrderedAddMonoid β] {V : Type u_2} [FinEnum V] [Nonempty V] (G : Digraph V) [DecidableRel G.Adj] (r₀ : V) (w : V → V → β) (h : β) (hh : ∑ e : V × V with (rootedDigraph G r₀).Adj e.1 e.2, max (w e.1 e.2) (-w e.1 e.2) < h) (hexists : ∃ (T : Digraph V), T.IsOutArborescence r₀ ∧ T ≤ G) :
let Bstar := optimumBranching (rootedDigraph G r₀) fun (u v : V) => w u v + h; Bstar.IsOutArborescence r₀ ∧ Bstar ≤ G ∧ ∀ (T : Digraph V) [inst : DecidableRel T.Adj], T.IsOutArborescence r₀ → T ≤ G → arcCost T w ≤ arcCost Bstar w

Edmonds (1967, Section 2) rooted spanning out-arborescence reduction: Deleting incoming arcs of r₀ and shifting remaining arc weights by h > ∑ |w_e| reduces maximum-weight r₀-rooted spanning out-arborescences to optimum branchings.