Documentation

CslibFrontier.Algorithms.Lean.MaxFlow.LevelGraph

Level Networks, Blocking Flows, and the Dinitz Phase Lemma #

Formalizes the phase analysis of Dinitz's blocking-flow algorithm ([Din70]; [Sch03], Section 10.6; see [Din06] for the history of the original version): augmenting an integral flow by a blocking flow of the level network of its residual network strictly increases the residual distance from N.s to N.t, so at most |V| - 1 such phases can occur.

Mathematical overview #

  1. Level networks (Flow.levelNet): for vertex labels d : V → ℕ, the level network of f keeps the residual arcs u → v with d v = d u + 1, with residual capacity as capacity. For d = f.resDist (shortest residual distances from N.s, Flow.resDist) these are exactly the residual arcs from one breadth-first layer to the next. A level network has no antiparallel arcs (Flow.levelNet_cap_eq_zero_of_pos).
  2. Augmenting by a subnetwork flow (Flow.augmentBy, Flow.augmentLevel): a flow g of a network with the same terminals whose capacities are bounded by the residual capacities of f is added to f by first cancelling reverse flow. The value adds (Flow.value_augmentBy) and the residual capacities change by - g u v + g v u (Flow.resCap_augmentBy); compare [CLRS09], Lemma 26.1, stated there for networks without antiparallel arcs.
  3. Blocking flows (Flow.IsBlocking): every simple s-t path along arcs of positive capacity contains an arc saturated by the flow.
  4. Phase lemma: augmenting by any flow of the level network of f.resDist never decreases a residual distance from N.s (Flow.resDist_le_resDist_augmentLevel), and augmenting by a blocking flow strictly increases the residual distance of a reachable N.t (Flow.resDist_lt_resDist_augmentLevel): a shortest residual walk of the new flow that is no longer than before must run along unsaturated level arcs, contradicting blocking.
  5. Phase bound (Network.IsDinitzRun.length_le): the distance of N.t is at least 1 before the first phase and at most |V| (the unreachable value of Flow.resDist), so every run of Dinitz phases (Network.IsDinitzRun), from any initial flow, has at most |V| - 1 phases.
  6. Breadth-first layers (Flow.resBall, Flow.bfsDist): computable residual distances, proved equal to Flow.resDist (Flow.bfsDist_eq_resDist).
  7. Deciding blocking (Flow.slackNet, Flow.unsatArcs): g is blocking exactly when the network of unused capacities L.cap - g has no augmenting path for its zero flow (Flow.isBlocking_iff_not_exists_slackNet), which one breadth-first search decides (Flow.isBlocking_iff_bfsDist_slackNet, Decidable g.IsBlocking).

Main definitions #

Main results #

References #

Level networks #

The level network of the residual network of f with respect to vertex labels d: it keeps the residual arcs u → v with d v = d u + 1. With d = f.resDist these are the arcs on shortest residual paths from N.s.

@[simp]
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_s {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) :
(f.levelNet d).s = N.s
@[simp]
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_t {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) :
(f.levelNet d).t = N.t
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_cap {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) (u v : V) :
(f.levelNet d).cap u v = if d v = d u + 1 then f.resCap u v else 0
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_cap_le_resCap {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) (u v : V) :
(f.levelNet d).cap u v ≤ f.resCap u v
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_cap_pos_iff {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) (u v : V) :
0 < (f.levelNet d).cap u v ↔ d v = d u + 1 ∧ 0 < f.resCap u v
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.levelNet_cap_eq_zero_of_pos {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (d : V → ℕ) {u v : V} (h : 0 < (f.levelNet d).cap u v) :
(f.levelNet d).cap v u = 0

Augmenting by a flow of a residual subnetwork #

def Cslib.Algorithms.Lean.MaxFlow.Network.Flow.augmentByFun {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) (g : V → V → ℕ) (u v : V) :

Arc flows of f augmented by the arc flows g of a subnetwork of the residual network: the net amount g u v - g v u (if positive) first cancels reverse flow f v u, and the remainder is added to f u v.

def Cslib.Algorithms.Lean.MaxFlow.Network.Flow.augmentBy {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {L : Network V} (g : L.Flow) (hs : L.s = N.s) (ht : L.t = N.t) (hcap : ∀ (u v : V), L.cap u v ≤ f.resCap u v) :

Augment f by a flow g of a network L with the same terminals whose capacities are bounded by the residual capacities of f ([CLRS09], Lemma 26.1, there for networks without antiparallel arcs).

theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.augmentBy_apply {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {L : Network V} (g : L.Flow) (hs : L.s = N.s) (ht : L.t = N.t) (hcap : ∀ (u v : V), L.cap u v ≤ f.resCap u v) (u v : V) :
(f.augmentBy g hs ht hcap).toFun u v = f.augmentByFun g.toFun u v
theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.value_augmentBy {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {L : Network V} (g : L.Flow) (hs : L.s = N.s) (ht : L.t = N.t) (hcap : ∀ (u v : V), L.cap u v ≤ f.resCap u v) :
(f.augmentBy g hs ht hcap).value = f.value + g.value

Augmenting by g adds the value of g.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.resCap_augmentBy_coe {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {L : Network V} (g : L.Flow) (hs : L.s = N.s) (ht : L.t = N.t) (hcap : ∀ (u v : V), L.cap u v ≤ f.resCap u v) (u v : V) :
↑((f.augmentBy g hs ht hcap).resCap u v) = ↑(f.resCap u v) - ↑(g.toFun u v) + ↑(g.toFun v u)

Residual capacities after augmenting by g, as integers.

theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.resCap_augmentBy {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {L : Network V} (g : L.Flow) (hs : L.s = N.s) (ht : L.t = N.t) (hcap : ∀ (u v : V), L.cap u v ≤ f.resCap u v) (u v : V) :
(f.augmentBy g hs ht hcap).resCap u v = f.resCap u v - g.toFun u v + g.toFun v u

Residual capacities after augmenting by g: g u v is used up and g v u is freed.

Blocking flows #

A flow g of L is blocking if every simple L.s-L.t path along arcs of positive capacity contains an arc saturated by g ([Din70]; [Sch03], Section 10.6).

Instances For
    def Cslib.Algorithms.Lean.MaxFlow.Network.Flow.augmentLevel {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {d : V → ℕ} (g : (f.levelNet d).Flow) :

    Augment f by a flow g of its level network f.levelNet d.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.resCap_augmentLevel {V : Type u_1} [Fintype V] {N : Network V} (f : N.Flow) {d : V → ℕ} (g : (f.levelNet d).Flow) (u v : V) :
    (f.augmentLevel g).resCap u v = f.resCap u v - g.toFun u v + g.toFun v u

    Distance monotonicity: augmenting by any flow of the level network of shortest residual distances never decreases a residual distance from N.s ([Din70]; [Sch03], Section 10.6).

    Dinitz phase lemma ([Din70]; [Sch03], Section 10.6): if N.t is residually reachable and g is a blocking flow of the level network of shortest residual distances, then augmenting by g strictly increases the residual distance of N.t.

    One Dinitz phase from f to f': N.t is residually reachable from N.s and f' augments f by a blocking flow of the level network of shortest residual distances.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.isDinitzStep_of_isBlocking {V : Type u_1} [Fintype V] {N : Network V} {f : N.Flow} {d : V → ℕ} (hd : ∀ (v : V), d v = f.resDist v) (hreach : f.ResReachable N.s N.t) (g : (f.levelNet d).Flow) (hg : g.IsBlocking) :

    A Dinitz phase step through any labelling equal to the residual distances.

    Each Dinitz phase strictly increases the residual distance of N.t.

    A blocking flow exists only when N.s ≠ N.t: for N.s = N.t the one-vertex path has no arc.

    def Cslib.Algorithms.Lean.MaxFlow.Network.IsDinitzRun {V : Type u_1} [Fintype V] {N : Network V} (T : ℕ) (flows : ℕ → N.Flow) :

    A run of T Dinitz phases flows 0 → flows 1 → ⋯ → flows T.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.IsDinitzRun.resDist_add_le {V : Type u_1} [Fintype V] {N : Network V} {T : ℕ} {flows : ℕ → N.Flow} (h : IsDinitzRun T flows) :
    (flows 0).resDist N.t + T ≤ (flows T).resDist N.t

    After T Dinitz phases the residual distance of N.t has grown by at least T.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.IsDinitzRun.length_le {V : Type u_1} [Fintype V] {N : Network V} {T : ℕ} {flows : ℕ → N.Flow} (h : IsDinitzRun T flows) :

    Phase bound ([Din70]; [Sch03], Section 10.6): every run of Dinitz phases has at most |V| - 1 phases, from any initial flow.

    Breadth-first layers #

    Vertices reachable from N.s by residual walks of at most k arcs, computed layer by layer.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.mem_resBall_iff {V : Type u_1} [Fintype V] {N : Network V} [DecidableEq V] (f : N.Flow) (k : ℕ) (v : V) :
    v ∈ f.resBall k ↔ ∃ m ≤ k, f.HasResWalkOfLen v m

    Breadth-first layer index of v: the number of balls f.resBall k, k < |V|, that miss v. Equal to f.resDist v (bfsDist_eq_resDist), but computable.

    Slack networks and deciding blocking #

    The network of unused capacities L.cap u v - g u v of a flow g of L. Its residual arcs for the zero flow are the unsaturated arcs of g.

    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.resCap_zero_slackNet {V : Type u_1} [Fintype V] {L : Network V} (g : L.Flow) (u v : V) :
    (zero g.slackNet).resCap u v = L.cap u v - g.toFun u v

    If no path of unsaturated arcs joins the terminals, g is blocking.

    g is blocking exactly when no path of unsaturated arcs joins the terminals.

    Arcs not saturated by g.

    @[simp]
    theorem Cslib.Algorithms.Lean.MaxFlow.Network.Flow.mem_unsatArcs {V : Type u_1} [Fintype V] {L : Network V} (g : L.Flow) (e : V × V) :
    e ∈ g.unsatArcs ↔ g.toFun e.1 e.2 < L.cap e.1 e.2

    Blocking is decided by one breadth-first search in the slack network.