Documentation

CslibFrontier.Algorithms.Lean.MaxFlow.PushRelabel

The Generic Push–Relabel Algorithm #

The generic push–relabel maximum-flow algorithm of Goldberg and Tarjan ([GT88]; [CLRS09], Section 26.4), with its operation bounds, its correctness at termination, and an executable scheduler.

Model and source mapping #

Main definitions #

Main results #

Limitations #

The bounds count operations; no cost is charged for selecting an operation, so this is not a machine running-time bound. Only the generic algorithm is treated here: see CslibFrontier.Algorithms.Lean.MaxFlow.RelabelToFront for the pure relabel-to-front scheduler and its O(|V|³) push/relabel operation, discharge, and current-arc advance count bounds. Word-RAM running times (O(|V|³)), FIFO and highest-label (O(|V|² √|E|)) selection rules, gap and global relabelling heuristics, and dynamic trees ([GT88]) are not formalized here.

References #

A state of the generic push–relabel algorithm: a preflow and vertex heights.

  • flow : N.Preflow

    The current preflow.

  • height : V → ℕ

    The current heights (distance labels).

A basic operation of the generic algorithm.

  • push {V : Type u_2} (u v : V) : Op V

    Push from the first vertex to the second.

  • relabel {V : Type u_2} (u : V) : Op V

    Relabel a vertex.

o is a relabel.

Instances For

    The initial state: the initial preflow and heights ([CLRS09], Section 26.4).

    The effect of an operation (meaningful when it is admissible).

    The precondition of an operation.

    Instances For

      The state reached by applying a list of operations in order.

      os is a run of the generic algorithm from σ: each operation is admissible when applied.

      Instances For
        @[instance_reducible]

        A saturating push: it moves the whole residual capacity of its arc.

        Instances For
          def Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.countOps {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (p : State N → Op V → Prop) [(σ : State N) → (o : Op V) → Decidable (p σ o)] (σ : State N) :
          List (Op V) → ℕ

          The number of operations of os satisfying p in the state they are applied to.

          The number of relabels in a run.

          The number of saturating pushes in a run.

          The number of nonsaturating pushes in a run.

          The number of saturating pushes from a to b in a run.

          @[simp]
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.run_cons {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (σ : State N) (o : Op V) (os : List (Op V)) :
          σ.run (o :: os) = (σ.apply o).run os
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.isRun_cons {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} {o : Op V} {os : List (Op V)} :
          σ.IsRun (o :: os) ↔ σ.Admissible o ∧ (σ.apply o).IsRun os
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numSatPushesAt_cons {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (a b : V) (σ : State N) (o : Op V) (os : List (Op V)) :
          numSatPushesAt a b σ (o :: os) = (if o = Op.push a b ∧ σ.IsSatPush o then 1 else 0) + numSatPushesAt a b (σ.apply o) os
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.run_append {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (σ : State N) (os₁ os₂ : List (Op V)) :
          σ.run (os₁ ++ os₂) = (σ.run os₁).run os₂
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.isRun_append {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} {os₁ os₂ : List (Op V)} :
          σ.IsRun os₁ → (σ.run os₁).IsRun os₂ → σ.IsRun (os₁ ++ os₂)
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numNonsatPushes_append {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (σ : State N) (os₁ os₂ : List (Op V)) :
          σ.numNonsatPushes (os₁ ++ os₂) = σ.numNonsatPushes os₁ + (σ.run os₁).numNonsatPushes os₂

          Every operation of a run is a relabel, a saturating push or a nonsaturating push.

          Invariants #

          The invariant of the generic algorithm: a valid labeling with heights at most 2|V| - 1.

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.Inv.apply {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} (hσ : σ.Inv) {o : Op V} (ho : σ.Admissible o) :
          (σ.apply o).Inv
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.Inv.run {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} (hσ : σ.Inv) {os : List (Op V)} (hos : σ.IsRun os) :
          (σ.run os).Inv
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.Inv.not_isActive {V : Type u_1} [Fintype V] {N : Network V} {σ : State N} (hσ : σ.Inv) (hstop : ∀ (o : Op V), ¬σ.Admissible o) (v : V) :

          A state satisfying the invariant and admitting no operation has no active vertex ([CLRS09], Lemma 26.14).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.le_height_apply {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} {o : Op V} (ho : σ.Admissible o) (x : V) :
          σ.height x ≤ (σ.apply o).height x

          Relabels #

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numRelabels_add_sum_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} {os : List (Op V)} (hos : σ.IsRun os) :
          σ.numRelabels os + ∑ v : V, σ.height v ≤ ∑ v : V, (σ.run os).height v

          Saturating pushes #

          The bookkeeping behind the saturating-push bound: after c saturating pushes from a to b, heights have grown by about 2c ([CLRS09], proof of Lemma 26.22).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.PairInv.apply {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {a b : V} {σ : State N} {c : ℕ} (hc : PairInv a b σ c) {o : Op V} (ho : σ.Admissible o) :
          PairInv a b (σ.apply o) (c + if o = Op.push a b ∧ σ.IsSatPush o then 1 else 0)
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.PairInv.run {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {a b : V} {σ : State N} {c : ℕ} (hc : PairInv a b σ c) {os : List (Op V)} (hos : σ.IsRun os) :
          PairInv a b (σ.run os) (c + numSatPushesAt a b σ os)
          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numSatPushesAt_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} (hσ : σ.Inv) {os : List (Op V)} (hos : σ.IsRun os) (a b : V) :

          At most |V| saturating pushes from a to b ([CLRS09], proof of Lemma 26.22).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numSatPushesAt_eq_zero {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {a b : V} (hab : (a, b) ∉ N.symArcs) (σ : State N) {os : List (Op V)} (hos : σ.IsRun os) :
          numSatPushesAt a b σ os = 0

          Nonsaturating pushes #

          The potential Φ = ∑_{v active} h(v) of [CLRS09], proof of Lemma 26.23.

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.potential_apply_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} (hσ : σ.Inv) {o : Op V} (ho : σ.Admissible o) :
          ((σ.apply o).potential + ∑ v : V, σ.height v + if o.IsPush ∧ ¬σ.IsSatPush o then 1 else 0) ≤ σ.potential + ∑ v : V, (σ.apply o).height v + (2 * Fintype.card V - 1) * if σ.IsSatPush o then 1 else 0

          One admissible operation raises the potential by at most the height increase, plus 2|V| - 1 for a saturating push, and lowers it by at least one for a nonsaturating push ([CLRS09], proof of Lemma 26.23).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.numNonsatPushes_add_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {σ : State N} (hσ : σ.Inv) {os : List (Op V)} (hos : σ.IsRun os) :
          σ.numNonsatPushes os + (σ.run os).potential + ∑ v : V, σ.height v ≤ σ.potential + ∑ v : V, (σ.run os).height v + (2 * Fintype.card V - 1) * σ.numSatPushes os

          Bounds from the initial state #

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.numRelabels_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (hst : N.s ≠ N.t) {os : List (Op V)} (hos : (init N).IsRun os) :

          Relabel bound ([CLRS09], Corollary 26.21): a run from the initial state performs at most (|V| - 2)(2|V| - 1) relabels.

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.numRelabels_lt {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (hst : N.s ≠ N.t) {os : List (Op V)} (hos : (init N).IsRun os) :

          Relabel bound, [CLRS09]'s form (Corollary 26.21): fewer than 2|V|² relabels.

          Saturating-push bound ([CLRS09], Lemma 26.22): a run from the initial state performs at most |V| saturating pushes per pair of N.symArcs.

          Saturating-push bound, [CLRS09]'s form (Lemma 26.22): at most 2|V| |E| saturating pushes, where E = N.posArcs. The source states <; the non-strict form also covers E = ∅.

          Nonsaturating-push bound ([CLRS09], Lemma 26.23): a run from the initial state performs at most (|V| - 2)(2|V| - 1) + (2|V| - 1) |V| |N.symArcs| nonsaturating pushes.

          Nonsaturating-push bound, [CLRS09]'s form (Lemma 26.23): fewer than 4|V|²(|V| + |E|) nonsaturating pushes, where E = N.posArcs.

          The total operation bound 2 (|V| - 2)(2|V| - 1) + 2|V| · |V| |N.symArcs|; at most 4|V|²(1 + |E|) by maxOps_le.

          maxOps N ≤ 4|V|²(1 + |E|) with E = N.posArcs, so maxOps N = O(|V|² (|E| + 1)).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.length_le {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (hst : N.s ≠ N.t) {os : List (Op V)} (hos : (init N).IsRun os) :

          Operation bound ([CLRS09], Theorem 26.24, operation count): every run of the generic algorithm from the initial state has at most maxOps N ≤ 4|V|²(1 + |E|) operations (maxOps_le).

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.isMaxFlow_isMinCut_of_isRun {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (hst : N.s ≠ N.t) {os : List (Op V)} (hos : (init N).IsRun os) (hstop : ∀ (o : Op V), ¬((init N).run os).Admissible o) :
          ∃ (hz : ∀ (v : V), v ≠ N.s → v ≠ N.t → ((init N).run os).flow.excess v = 0), (((init N).run os).flow.toFlow hz).IsMaxFlow ∧ N.IsMinCut (Preflow.gapCut ((init N).run os).height) ∧ (((init N).run os).flow.toFlow hz).value = ↑(N.cutCapacity (Preflow.gapCut ((init N).run os).height))

          Correctness of every run ([CLRS09], Lemma 26.14 and Theorem 26.18): if a run of the generic algorithm from the initial state, under any selection rule, reaches a state admitting no operation, then its preflow is a maximum flow and the gap cut of its heights is a minimum cut of the same value. By length_le, every run reaches such a state within maxOps N operations.

          An executable scheduler #

          The operation chosen by scanning vs: the first active vertex u of vs pushes to the first v of vs with (u, v) admissible, or is relabelled if there is none; none if no vertex of vs is active.

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.admissible_of_selectOp_eq_some {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {vs : List V} (hvs : ∀ (v : V), v ∈ vs) {σ : State N} (hσ : σ.flow.IsValidLabeling σ.height) {o : Op V} (h : selectOp vs σ = some o) :
          def Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.loop {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (vs : List V) (norm : State N → State N) :
          ℕ → State N → List (Op V) × State N

          Apply operations chosen by selectOp vs until none applies or fuel runs out, normalizing the state with norm after every step; returns the operations performed and the final state. Executable instances use norm to tabulate the state (see PushRelabel.tabulate); correctness assumes that norm is the identity.

          theorem Cslib.Algorithms.Lean.MaxFlow.Network.PushRelabel.State.loop_spec {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {vs : List V} (hvs : ∀ (v : V), v ∈ vs) {norm : State N → State N} (hnorm : ∀ (σ : State N), norm σ = σ) (fuel : ℕ) (σ : State N) :
          σ.Inv → (loop vs norm fuel σ).2 = σ.run (loop vs norm fuel σ).1 ∧ σ.IsRun (loop vs norm fuel σ).1 ∧ ((loop vs norm fuel σ).1.length < fuel → ∀ (v : V), ¬(loop vs norm fuel σ).2.flow.IsActive v)

          Tabulated states on Fin n #

          Tabulate a preflow on Fin n as an n × n matrix.

          Tabulate a state on Fin n: the preflow as a matrix and the heights as a vector.

          The executable algorithm #

          The output of pushRelabelWith.

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

          The generic push–relabel algorithm with the scheduler State.selectOp vs, normalizing states with norm, for at most maxOps N + 1 steps from the initial state.

          theorem Cslib.Algorithms.Lean.MaxFlow.pushRelabelWith_correct {V : Type u_1} [Fintype V] [DecidableEq V] {N : Network V} {vs : List V} (hvs : ∀ (v : V), v ∈ vs) {norm : Network.PushRelabel.State N → Network.PushRelabel.State N} (hnorm : ∀ (σ : Network.PushRelabel.State N), norm σ = σ) (hst : N.s ≠ N.t) :

          Correctness of the executable generic algorithm ([CLRS09], Theorems 26.18 and 26.24): if vs lists every vertex, norm is the identity and N.s ≠ N.t, then pushRelabelWith N vs norm performs a run of at most maxOps N operations of the generic algorithm from the initial state and returns a maximum flow and a minimum cut of equal value.

          The generic push–relabel algorithm on Fin n: scan the vertices in increasing order, tabulating the state after every operation.