Documentation

CslibFrontier.Algorithms.Lean.MaxFlow.RelabelToFront

Goldberg–Tarjan Relabel-to-Front Scheduler and Combinatorial Potentials #

Pure Lean step toward #3373 formalizing the relabel-to-front topological list maximum-flow scheduler (following [GT88], Sections 3–4; [CLRS09], Section 26.5) on the generic push–relabel framework of CslibFrontier.Algorithms.Lean.MaxFlow.PushRelabel, with maximum-flow and minimum-cut correctness, PushRelabel push/relabel operation-count bounds, and pure state potentials (curPotential, rtfMeasure) consumed by CslibFrontier.Algorithms.WordRAM.PushRelabel. This module states pure correctness and combinatorial operation/potential bounds, not machine running times.

Model and source mapping #

Main definitions #

Main results #

Limitations #

This module defines pure mathematical functions (Preflow.relabelHeight over Finset.univ, Function.update, and list concatenation carry no machine cost here) and makes no machine running-time claim. Dense standard-basis Word-RAM O(|V|³) compilation is in CslibFrontier.Algorithms.WordRAM.PushRelabel; sparse CSR Word-RAM compilation, FIFO and highest-label (O(|V|² √|E|)) schedulers, gap and global-relabelling heuristics, dynamic trees, and verified primary-source locators remain open (#3373).

References #

Adjacency coverage #

Candidate neighbour lists adj cover every non-loop pair (u, v) that can ever carry positive residual capacity in N.

Exact neighbour lists of N : Network (Fin n): all v ≠ u with 0 < N.cap u v + N.cap v u.

Current-arc state and discharge #

State of the current-arc push–relabel machine: a PushRelabel.State N together with the unscanned suffix cur u of adj u at every vertex u.

  • The underlying preflow and height function.

  • cur : V → List V

    Unscanned suffix of adj u at each vertex u.

Initial current-arc state from PushRelabel.init N and full neighbor lists adj.

Current-arc invariant: every cur u is a suffix of adj u whose already-scanned prefix contains no admissible out-neighbor.

structure Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.CAInv {V : Type u_1} [Fintype V] {N : Network V} (adj : V → List V) (s : CAState N) :

Invariant of CAState: valid height-bounded preflow/labeling together with CurrentArcInv.

  • prInv : s.pr.Inv

    Underlying generic push–relabel invariant.

  • curInv : CurrentArcInv adj s.pr s.cur

    Current-arc prefix has no admissible arcs.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.caInv_init {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hst : N.s ≠ N.t) :
CAInv adj (CAState.init N adj)

Fuel sufficient for dischargeLoop to drain u completely from any CAInv state.

Pure current-arc scan potential across non-terminal vertices (#3373): ∑ u ∈ (Finset.univ.erase N.s).erase N.t, ((2 * |V| - 1 - height u) * |adj u| + |cur u|). Non-admissible cursor steps at u ∉ {N.s, N.t} strictly decrease curPotential by 1, pushes preserve it, and valid relabels do not increase it.

Initial current-arc potential equals 2 * |V| * ∑ u ∈ (univ.erase N.s).erase N.t, |adj u|.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.curPotential_init_le_of_nodup {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hnd : ∀ (v : V), (adj v).Nodup) :

Duplicate-free neighbor lists bound initial curPotential by 2 * |V| ^ 3.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.curPotential_advance_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (adj : V → List V) {s : CAState N} {u v : V} {vs : List V} (hus : u ≠ N.s) (hut : u ≠ N.t) (hcu : s.cur u = v :: vs) :
curPotential adj { pr := s.pr, cur := Function.update s.cur u vs } + 1 = curPotential adj s

Dropping the head of s.cur u at a non-terminal vertex strictly decreases curPotential by 1.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.curPotential_push_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (adj : V → List V) (s : CAState N) (u v : V) :
curPotential adj { pr := s.pr.apply (PushRelabel.Op.push u v), cur := s.cur } = curPotential adj s

Pushing flow preserves heights and current-arc suffixes, leaving curPotential unchanged.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.curPotential_relabel_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {s : CAState N} (hs : CAInv adj s) {u : V} (hact : s.pr.flow.IsActive u) (hcu : s.cur u = []) :
curPotential adj { pr := s.pr.apply (PushRelabel.Op.relabel u), cur := Function.update s.cur u (adj u) } ≤ curPotential adj s

Relabeling an active vertex u at s.cur u = [] and resetting cur u := adj u does not increase curPotential.

Result of discharging a single vertex u: the PushRelabel operations performed, the final current-arc state, and whether at least one relabel occurred.

  • Push and relabel operations performed during the discharge.

  • ca : CAState N

    Final current-arc state after the discharge.

  • relabeled : Bool

    Whether at least one relabel occurred during the discharge.

def Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.dischargeLoop {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (adj : V → List V) (norm : CAState N → CAState N) (u : V) :

Discharge loop on vertex u with fuel fuel, normalizing states with norm after each step: while u is active, push along cur u's head if admissible, drop cur u's head otherwise, or relabel u and reset cur u := adj u at [].

def Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (adj : V → List V) (norm : CAState N → CAState N) (u : V) (s : CAState N) :

Pure current-arc discharge on u with fuel dischargeFuel adj u (step toward #3373, following [CLRS09], Section 26.5, DISCHARGE).

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge_spec {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {norm : CAState N → CAState N} (hnorm : ∀ (s : CAState N), norm s = s) (u : V) {s : CAState N} (hs : CAInv adj s) :
have r := discharge adj norm u s; CAInv adj r.ca ∧ s.pr.IsRun r.ops ∧ r.ca.pr = s.pr.run r.ops ∧ ¬r.ca.pr.flow.IsActive u ∧ s.pr.numNonsatPushes r.ops ≤ 1 ∧ (r.relabeled = true ↔ 0 < s.pr.numRelabels r.ops) ∧ (∀ (x : V), x ≠ u → r.ca.cur x = s.cur x ∧ r.ca.pr.height x = s.pr.height x) ∧ s.pr.height u + s.pr.numRelabels r.ops ≤ r.ca.pr.height u ∧ curPotential adj r.ca ≤ curPotential adj s ∧ (r.relabeled = false → r.ca.pr.height = s.pr.height) ∧ (r.relabeled = false → ∀ (x y : V), 0 < r.ca.pr.flow.resCap x y ∧ r.ca.pr.height x = r.ca.pr.height y + 1 → 0 < s.pr.flow.resCap x y ∧ s.pr.height x = s.pr.height y + 1) ∧ (r.relabeled = false → ∀ (w : V), w ≠ u → ¬(0 < s.pr.flow.resCap u w ∧ s.pr.height u = s.pr.height w + 1) → r.ca.pr.flow.excess w = s.pr.flow.excess w) ∧ (r.relabeled = true → ∀ (w : V), w ≠ u → ¬(0 < r.ca.pr.flow.resCap w u ∧ r.ca.pr.height w = r.ca.pr.height u + 1)) ∧ ∀ (x y : V), x ≠ u → y ≠ u → r.ca.pr.flow.resCap x y = s.pr.flow.resCap x y

Pure specification of discharge (step toward #3373, following [CLRS09], Section 26.5): discharging u from any CAInv state executes a valid run of PushRelabel operations, preserves CAInv, renders u inactive, performs at most one nonsaturating push, does not increase curPotential, preserves heights and admissible arcs when not relabeling, and leaves no incoming admissible arcs at u when relabeling.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.curPotential_discharge_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {norm : CAState N → CAState N} (hnorm : ∀ (s : CAState N), norm s = s) (u : V) {s : CAState N} (hs : CAInv adj s) :
curPotential adj (discharge adj norm u s).ca ≤ curPotential adj s

Discharging any vertex u from a CAInv state does not increase curPotential.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge_eq_of_not_isActive {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (norm : CAState N → CAState N) {u : V} {s : CAState N} (hact : ¬s.pr.flow.IsActive u) :
discharge adj norm u s = { ops := [], ca := s, relabeled := false }

Evaluating discharge on an inactive vertex returns the trivial empty output.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge_relabel_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {u : V} {s : CAState N} (hs : CAInv adj s) (hact : s.pr.flow.IsActive u) (hcu : s.cur u = []) :
have s' := { pr := s.pr.apply (PushRelabel.Op.relabel u), cur := Function.update s.cur u (adj u) }; have r' := discharge adj id u s'; CAInv adj s' ∧ discharge adj id u s = { ops := PushRelabel.Op.relabel u :: r'.ops, ca := r'.ca, relabeled := true }

One relabel step of discharge adj id u s when s.cur u = [] (CAInv adj s preserved).

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge_push_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {u v : V} {vs : List V} {s : CAState N} (hs : CAInv adj s) (hact : s.pr.flow.IsActive u) (hcu : s.cur u = v :: vs) (hadm : 0 < s.pr.flow.resCap u v ∧ s.pr.height u = s.pr.height v + 1) :
have s' := { pr := s.pr.apply (PushRelabel.Op.push u v), cur := s.cur }; have r' := discharge adj id u s'; CAInv adj s' ∧ discharge adj id u s = { ops := PushRelabel.Op.push u v :: r'.ops, ca := r'.ca, relabeled := r'.relabeled }

One push step of discharge adj id u s when s.cur u = v :: vs is admissible.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.discharge_advance_step {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {adj : V → List V} (hadj : IsAdjacency N adj) {u v : V} {vs : List V} {s : CAState N} (hs : CAInv adj s) (hact : s.pr.flow.IsActive u) (hcu : s.cur u = v :: vs) (hadm : ¬(0 < s.pr.flow.resCap u v ∧ s.pr.height u = s.pr.height v + 1)) :
have s' := { pr := s.pr, cur := Function.update s.cur u vs }; CAInv adj s' ∧ discharge adj id u s = discharge adj id u s'

One non-admissible cursor step of discharge adj id u s when s.cur u = v :: vs.

Topological ordering and relabel-to-front #

Before u v l holds when u appears strictly before v in l.

Topological order of a vertex list L with respect to the admissible network of σ (following [CLRS09], Section 26.5): every admissible arc between vertices of L points forward in L.

Pure state of the relabel-to-front scheduler: current-arc state, scanned prefix done, and remaining suffix todo.

  • ca : CAState N

    Current preflow, heights, and current-arc cursors.

  • done : List V

    Vertices already scanned without relabel since the last move-to-front.

  • todo : List V

    Remaining vertices in the list after the cursor.

Initial state of relabel-to-front from vertex list vs and neighbor lists adj.

structure Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.RTFInv {V : Type u_1} [Fintype V] {N : Network V} (adj : V → List V) (st : RTFState N) :

Invariant of RTFState (following [CLRS09], Section 26.5): CAInv, done ++ todo is a duplicate-free enumeration of V \ {N.s, N.t} in topological order of the admissible network, and every vertex in done is inactive.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.rtfInv_init {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} {adj : V → List V} {vs : List V} (hst : N.s ≠ N.t) (hnodup : vs.Nodup) (hmem : ∀ (v : V), v ∈ vs ↔ v ≠ N.s ∧ v ≠ N.t) :
RTFInv adj (RTFState.init N adj vs)

Outer fuel for rtfLoop: (|V| - 2) * ((|V| - 2) * (2 * |V| - 1) + 1) + 1.

def Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.rtfLoop {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} (adj : V → List V) (caNorm : CAState N → CAState N) (stNorm : RTFState N → RTFState N) :

Relabel-to-front outer loop with fuel fuel, normalizing CAState with caNorm and RTFState with stNorm. Returns (ops, finalState).

Pure outer phase/pass potential on RTFState (#3373, following [GT88]; [CLRS09], Section 26.5): (sumHeightMax V - ∑ v, height v) * (|V| - 2) + |todo|. Strictly decreases on every vertex-list step of rtfLoop.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.rtfMeasure_init {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} (adj : V → List V) {vs : List V} (hnodup : vs.Nodup) (hmem : ∀ (v : V), v ∈ vs ↔ v ≠ N.s ∧ v ≠ N.t) (hst : N.s ≠ N.t) :
rtfMeasure V (RTFState.init N adj vs) = (Fintype.card V - 2) * ((Fintype.card V - 2) * (2 * Fintype.card V - 1) + 1)

Exact value of rtfMeasure on RTFState.init: (|V| - 2) * ((|V| - 2) * (2 * |V| - 1) + 1).

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.rtfMeasure_init_le {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} (adj : V → List V) {vs : List V} (hnodup : vs.Nodup) (hmem : ∀ (v : V), v ∈ vs ↔ v ≠ N.s ∧ v ≠ N.t) (hst : N.s ≠ N.t) :

Cubic upper bound rtfMeasure V (RTFState.init N adj vs) ≤ 2 * |V| ^ 3 when N.s ≠ N.t.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.RelabelToFront.rtfLoop_step {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} {adj : V → List V} (hadj : IsAdjacency N adj) {st : RTFState N} (hinv : RTFInv adj st) {u : V} {rest : List V} (htodo : st.todo = u :: rest) (hst : N.s ≠ N.t) :
have d := discharge adj id u st.ca; have st' := if d.relabeled = true then { ca := d.ca, done := [u], todo := st.done ++ rest } else { ca := d.ca, done := st.done ++ [u], todo := rest }; have r := rtfLoop adj id id (rtfFuel V) st; have r' := rtfLoop adj id id (rtfFuel V) st'; RTFInv adj st' ∧ rtfMeasure V st' + 1 ≤ rtfMeasure V st ∧ r.1 = d.ops ++ r'.1 ∧ r.2 = r'.2

One outer iteration of rtfLoop adj id id (rtfFuel V) st when st.todo = u :: rest: preserves RTFInv, strictly decreases rtfMeasure, prepends d.ops, and reaches the same final RTFState.

Sparse initial curPotential bound on Fin n: exactAdj N gives initial potential at most 4 * n * |N.posArcs| (#3373).

theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numRelabels_append {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} (σ : State N) (os₁ os₂ : List (Op V)) :
σ.numRelabels (os₁ ++ os₂) = σ.numRelabels os₁ + (σ.run os₁).numRelabels os₂

Relabel-operation count is additive along concatenated operation lists.

Relabel-to-front scheduler, operation-count bounds, and Fin n solvers #

Output of relabelToFrontWith: the PushRelabel operation run, the final flow, and the final gap cut.

The output read off a final RTFState: its preflow as a flow when every excess off N.s, N.t vanishes (the zero flow otherwise) and its gap cut.

Pure relabel-to-front maximum-flow scheduler (step toward #3373, following [GT88]; [CLRS09], Section 26.5), with initial vertex order vs, neighbor lists adj, and normalizers caNorm / stNorm.

theorem Cslib.Algorithms.Lean.MaxFlow.relabelToFrontWith_correct {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} {vs : List V} (hnodup : vs.Nodup) (hmem : ∀ (v : V), v ∈ vs ↔ v ≠ N.s ∧ v ≠ N.t) {adj : V → List V} (hadj : Network.RelabelToFront.IsAdjacency N adj) {caNorm : Network.RelabelToFront.CAState N → Network.RelabelToFront.CAState N} (hcaNorm : ∀ (s : Network.RelabelToFront.CAState N), caNorm s = s) {stNorm : Network.RelabelToFront.RTFState N → Network.RelabelToFront.RTFState N} (hstNorm : ∀ (st : Network.RelabelToFront.RTFState N), stNorm st = st) (hst : N.s ≠ N.t) :

Pure correctness and nonsaturating-push bound for relabelToFrontWith (step toward #3373, following [GT88]; [CLRS09], Section 26.5; makes no machine running-time claim): for N.s ≠ N.t, valid neighbor lists adj, a duplicate-free list vs of V \ {N.s, N.t}, and identity normalizers, relabelToFrontWith performs a valid run of PushRelabel operations ending in a maximum flow and a minimum cut of equal value, with at most (|V| - 2) * ((|V| - 2) * (2 * |V| - 1) + 1) nonsaturating pushes.

theorem Cslib.Algorithms.Lean.MaxFlow.relabelToFrontWith_bounds {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} {vs : List V} (hnodup : vs.Nodup) (hmem : ∀ (v : V), v ∈ vs ↔ v ≠ N.s ∧ v ≠ N.t) {adj : V → List V} (hadj : Network.RelabelToFront.IsAdjacency N adj) {caNorm : Network.RelabelToFront.CAState N → Network.RelabelToFront.CAState N} (hcaNorm : ∀ (s : Network.RelabelToFront.CAState N), caNorm s = s) {stNorm : Network.RelabelToFront.RTFState N → Network.RelabelToFront.RTFState N} (hstNorm : ∀ (st : Network.RelabelToFront.RTFState N), stNorm st = st) (hst : N.s ≠ N.t) :

Combinatorial PushRelabel operation-count bounds for relabelToFrontWith (step toward #3373, following [GT88]; [CLRS09], Sections 26.4–26.5; makes no machine running-time claim): at most 2 |V|² relabels, 2 |V| |E| saturating pushes, 2 |V|³ nonsaturating pushes, and 4 |V|³ total push/relabel operations.

Executable tabulated instances on Fin n #

Tabulate a CAState on Fin n: tabulated preflow/heights together with a Vector of current neighbor suffixes.

Canonical duplicate-free list of non-terminal vertices v ≠ N.s, N.t on Fin n.

Executable relabel-to-front solver on Network (Fin n) with candidate neighbor lists adj, tabulating state after every step so kernel evaluation (decide) avoids stacked updates.

Dense relabel-to-front solver on Network (Fin n) scanning defaultAdj n (List.finRange n) at every vertex.

Exact-adjacency relabel-to-front solver on Network (Fin n) scanning exactAdj N at every vertex.

Pure correctness and PushRelabel operation-count bounds for relabelToFront on Fin n (step toward #3373, following [GT88]; [CLRS09], Section 26.5; makes no machine running-time claim).

Pure correctness and PushRelabel operation-count bounds for relabelToFrontDense on Fin n (pure specification step consumed by CslibFrontier.Algorithms.WordRAM.PushRelabel, #3373).

Pure correctness and PushRelabel operation-count bounds for relabelToFrontExact on Fin n (step toward sparse CSR Word-RAM compilation in #3373; see curPotential_init_exactAdj_le for the 4 * n * |N.posArcs| current-arc potential bound).