Documentation

CslibFrontier.Algorithms.Lean.MaxFlow.Preflow

Preflows, Valid Labelings, Push and Relabel #

The basic objects of the Goldberg–Tarjan push–relabel method ([GT88]; [CLRS09], Section 26.4) on the integral networks of CslibFrontier.Algorithms.Lean.MaxFlow.Basic.

Model and source mapping #

Main definitions #

Main results #

References #

An integral preflow on N: arc flows bounded by the capacities, with inflow at least outflow at every vertex other than N.s ([CLRS09], Section 26.4).

  • toFun : V → V → ℕ

    Integral flow on each directed arc (u, v).

  • le_cap (u v : V) : self.toFun u v ≤ N.cap u v

    Capacity bound on every directed arc.

  • out_le_in (v : V) : v ≠ N.s → ∑ w : V, self.toFun v w ≤ ∑ u : V, self.toFun u v

    Outflow is at most inflow at every vertex other than the source.

Instances For
    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.ext_iff {V : Type u_1} {inst✝ : Fintype V} {N : Network V} {x y : N.Preflow} :
    x = y ↔ x.toFun = y.toFun
    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.ext {V : Type u_1} {inst✝ : Fintype V} {N : Network V} {x y : N.Preflow} (toFun : x.toFun = y.toFun) :
    x = y
    @[instance_reducible]

    The excess e(v) of v: inflow minus outflow.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_nonneg {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) {v : V} (hv : v ≠ N.s) :
    0 ≤ f.excess v

    Residual capacity c_f(u, v): unused capacity on (u, v) plus cancellable flow on (v, u).

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_coe {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (u v : V) :
    ↑(f.resCap u v) = ↑(N.cap u v) - (↑(f.toFun u v) - ↑(f.toFun v u))
    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_le_cap_add_cap {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (u v : V) :
    f.resCap u v ≤ N.cap u v + N.cap v u

    A vertex other than N.s and N.t is active when it has positive excess.

    Instances For

      Residual reachability: v is reachable from u along arcs of positive residual capacity.

      def Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.toFlow {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) :

      A preflow with zero excess at every vertex other than N.s and N.t is a flow.

      @[simp]
      theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.toFlow_apply {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) (u v : V) :
      (f.toFlow h).toFun u v = f.toFun u v
      theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_toFlow {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) (u v : V) :
      (f.toFlow h).resCap u v = f.resCap u v
      theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resReachable_toFlow {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) (u v : V) :

      Valid labelings #

      A valid labeling (height function) for f ([CLRS09], Section 26.4).

      • source : h N.s = Fintype.card V

        The source has height |V|.

      • sink : h N.t = 0

        The sink has height 0.

      • le_add_one (u v : V) : 0 < f.resCap u v → h u ≤ h v + 1

        Residual arcs descend by at most one level.

      Instances For
        theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.isValidLabeling_iff {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} :
        f.IsValidLabeling h ↔ h N.s = Fintype.card V ∧ h N.t = 0 ∧ ∀ (u v : V), 0 < f.resCap u v → h u ≤ h v + 1
        theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.le_add_card {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) {u w : V} (huw : f.ResReachable u w) :
        h u + 1 ≤ h w + Fintype.card V

        No residual s–t path ([CLRS09], Lemma 26.17).

        Excess and residual reachability #

        Overflowing vertices reach the source ([CLRS09], Lemma 26.19): in a preflow, every vertex with positive excess has a residual path to N.s.

        theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.le_of_excess_pos {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) {x : V} (hx : 0 < f.excess x) :
        h x ≤ 2 * Fintype.card V - 1

        Height bound ([CLRS09], Lemma 26.20): under a valid labeling, a vertex with positive excess has height at most 2|V| - 1.

        Push and relabel #

        The amount min (e(u), c_f(u, v)) moved by a push from u to v ([CLRS09], Section 26.4, procedure PUSH).

        Residual out-neighbours of u.

        theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.mem_resNbrs {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (u v : V) :
        v ∈ f.resNbrs u ↔ 0 < f.resCap u v
        def Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.relabelHeight {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : V → ℕ) (u : V) :

        The height 1 + min {h v | c_f(u, v) > 0} assigned by a relabel of u ([CLRS09], Section 26.4, procedure RELABEL); h u when u has no residual out-arc.

        structure Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanPush {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : V → ℕ) (u v : V) :

        Precondition of a push from u to v ([CLRS09], Section 26.4): u is active and (u, v) is a residual arc going down one level.

        • active : f.IsActive u

          u is active.

        • resCap_pos : 0 < f.resCap u v

          (u, v) is a residual arc.

        • height_eq : h u = h v + 1

          (u, v) goes down one level.

        Instances For
          structure Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanRelabel {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (h : V → ℕ) (u : V) :

          Precondition of a relabel of u ([CLRS09], Section 26.4): u is active and no residual arc leaving u goes downhill.

          • active : f.IsActive u

            u is active.

          • le_height (v : V) : 0 < f.resCap u v → h u ≤ h v

            No residual arc leaving u goes downhill.

          Instances For
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.canPush_iff {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u v : V} :
            f.CanPush h u v ↔ f.IsActive u ∧ 0 < f.resCap u v ∧ h u = h v + 1
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.canRelabel_iff {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u : V} :
            f.CanRelabel h u ↔ f.IsActive u ∧ ∀ (v : V), 0 < f.resCap u v → h u ≤ h v
            @[instance_reducible]
            @[instance_reducible]
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanPush.ne {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u v : V} (hp : f.CanPush h u v) :
            u ≠ v
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanPush.pushAmount_pos {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u v : V} (hp : f.CanPush h u v) :
            0 < f.pushAmount u v
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.exists_canPush_or_canRelabel {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u : V} (hh : f.IsValidLabeling h) (hu : f.IsActive u) :
            (∃ (v : V), f.CanPush h u v) ∨ f.CanRelabel h u

            Every active vertex admits a push or a relabel ([CLRS09], Lemma 26.14).

            Termination and the gap cut #

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_eq_zero_of_forall_not_isActive {V : Type u_1} [Fintype V] {N : Network V} (f : N.Preflow) (hno : ∀ (v : V), ¬f.IsActive v) (v : V) :
            v ≠ N.s → v ≠ N.t → f.excess v = 0

            With no active vertex, every vertex other than N.s and N.t has zero excess.

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.isMaxFlow_toFlow {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) (hz : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) :

            Optimality at termination ([CLRS09], Theorem 26.18): a preflow with a valid labeling and no active vertex is a maximum flow.

            The least level 0 < k < |V| occupied by no vertex (0 if there is none).

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.exists_gap {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) :
            ∃ (k : ℕ), 0 < k ∧ k < Fintype.card V ∧ ∀ (v : V), h v ≠ k

            By pigeonhole, a valid labeling leaves some level strictly between 0 and |V| empty.

            The gap cut of a labeling: the vertices strictly above gapLevel h.

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.resCap_eq_zero_of_mem_gapCut {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) {u w : V} (hu : u ∈ gapCut h) (hw : w ∉ gapCut h) :
            f.resCap u w = 0
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.isMinCut_gapCut {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {f : N.Preflow} {h : V → ℕ} (hh : f.IsValidLabeling h) (hz : ∀ (v : V), v ≠ N.s → v ≠ N.t → f.excess v = 0) :
            N.IsMinCut (gapCut h) ∧ (f.toFlow hz).value = ↑(N.cutCapacity (gapCut h))

            Gap cut at termination: for a preflow with a valid labeling and no active vertex, the vertices above the least empty level form a minimum cut whose capacity is the flow value.

            The push operation #

            def Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.pushFun {V : Type u_1} [DecidableEq V] (f : V → V → ℕ) (u v : V) (δ : ℕ) (x y : V) :

            Arc flows after pushing δ units from u to v: first cancel up to δ units of the reverse flow f v u, then add the remainder to f u v.

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.pushFun_sub_pushFun {V : Type u_1} [DecidableEq V] (f : V → V → ℕ) (u v : V) (δ : ℕ) (x y : V) :
            ↑(pushFun f u v δ x y) - ↑(pushFun f u v δ y x) = (↑(f x y) - ↑(f y x) + if x = u ∧ y = v then ↑δ else 0) - if x = v ∧ y = u then ↑δ else 0
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.sum_pushFun_sub {V : Type u_1} [Fintype V] [DecidableEq V] (f : V → V → ℕ) (u v : V) (δ : ℕ) (x : V) :
            ∑ y : V, ↑(pushFun f u v δ y x) - ∑ y : V, ↑(pushFun f u v δ x y) = (∑ y : V, ↑(f y x) - ∑ y : V, ↑(f x y) - if x = u then ↑δ else 0) + if x = v then ↑δ else 0

            Push f.pushAmount u v units from u to v, cancelling reverse flow first ([CLRS09], Section 26.4, procedure PUSH).

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.push_apply {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (u v x y : V) :
            (f.push u v).toFun x y = pushFun f.toFun u v (f.pushAmount u v) x y
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_push {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (u v x : V) :
            (f.push u v).excess x = (f.excess x - if x = u then ↑(f.pushAmount u v) else 0) + if x = v then ↑(f.pushAmount u v) else 0
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_push_coe {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (u v x y : V) :
            ↑((f.push u v).resCap x y) = (↑(f.resCap x y) - if x = u ∧ y = v then ↑(f.pushAmount u v) else 0) + if x = v ∧ y = u then ↑(f.pushAmount u v) else 0
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_push_self {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v : V} (huv : u ≠ v) :
            (f.push u v).resCap u v = f.resCap u v - f.pushAmount u v
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_push_swap {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v : V} (huv : u ≠ v) :
            (f.push u v).resCap v u = f.resCap v u + f.pushAmount u v
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.resCap_push_of_ne {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v x y : V} (h1 : ¬(x = u ∧ y = v)) (h2 : ¬(x = v ∧ y = u)) :
            (f.push u v).resCap x y = f.resCap x y
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_push_self {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v : V} (huv : u ≠ v) :
            (f.push u v).excess u = f.excess u - ↑(f.pushAmount u v)
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_push_target {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v : V} (huv : u ≠ v) :
            (f.push u v).excess v = f.excess v + ↑(f.pushAmount u v)
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.excess_push_of_ne {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v x : V} (hu : x ≠ u) (hv : x ≠ v) :
            (f.push u v).excess x = f.excess x
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.isActive_push_of_ne {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) {u v x : V} (hu : x ≠ u) (hv : x ≠ v) :
            (f.push u v).IsActive x ↔ f.IsActive x
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.push {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {f : N.Preflow} {h : V → ℕ} {u v : V} (hh : f.IsValidLabeling h) (hp : f.CanPush h u v) :

            Pushes preserve valid labelings ([CLRS09], Lemma 26.16).

            The relabel operation #

            def Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.relabel {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (h : V → ℕ) (u : V) :
            V → ℕ

            Relabel u: replace its height by f.relabelHeight h u ([CLRS09], Section 26.4, procedure RELABEL).

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.relabel_self {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (h : V → ℕ) (u : V) :
            f.relabel h u u = f.relabelHeight h u
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.relabel_of_ne {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Preflow) (h : V → ℕ) {u x : V} (hx : x ≠ u) :
            f.relabel h u x = h x
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.relabelHeight_le {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u v : V} (hpos : 0 < f.resCap u v) :
            f.relabelHeight h u ≤ h v + 1
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanRelabel.lt_relabelHeight {V : Type u_1} [Fintype V] {N : Network V} {f : N.Preflow} {h : V → ℕ} {u : V} (hr : f.CanRelabel h u) :
            h u < f.relabelHeight h u

            A relabel strictly raises the height of the relabelled vertex ([CLRS09], Lemma 26.15).

            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.CanRelabel.le_relabel {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {f : N.Preflow} {h : V → ℕ} {u : V} (hr : f.CanRelabel h u) (x : V) :
            h x ≤ f.relabel h u x
            theorem Cslib.Algorithms.Lean.MaxFlow.Network.Preflow.IsValidLabeling.relabel {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] {f : N.Preflow} {h : V → ℕ} {u : V} (hh : f.IsValidLabeling h) (hr : f.CanRelabel h u) :

            Relabels preserve valid labelings ([CLRS09], Lemma 26.16).

            Initialization #

            The initial preflow: saturate every arc leaving the source ([CLRS09], Section 26.4, procedure INITIALIZE-PREFLOW).

            The initial heights: |V| at the source and 0 elsewhere ([CLRS09], Section 26.4).