Documentation

CslibFrontier.Foundations.Combinatorics.WeightedCut.Contraction

Contracting two supervertices #

Contraction of a weighted multigraph W : Fin (m + 1) → Fin (m + 1) → ℕ (Cslib.WeightedCut.IsMultigraph) along a pair of distinct supervertices u ≠ v, keeping the supervertices as Fin m. Merging v into u (mergePair) redirects the edges at v to u and drops the edges between them. Swap-compaction (embedCompact, compactIdx) then moves the last supervertex Fin.last m into the freed slot v, so that a contraction step on m + 1 active supervertices only touches rows and columns 0, …, m, as in the O(n)-time matrix update of Karger and Stein, Section 3.2. The contracted matrix is contractMatrix W u v, the updated map from the original vertices to supervertices is contractPart part u v huv, and a cut of Fin (m + 1) that does not separate u and v becomes the cut contractCut v B of Fin m.

Contraction preserves Cslib.WeightedCut.IsContractionOf (isContractionOf_contract), so pulled back cuts keep their weight, and a cut that does not separate u and v keeps its weight (cutWeight_contractCut). The randomized algorithms of Karger and Karger–Stein (CslibFrontier.Algorithms.Karger.Graph) and the deterministic Stoer–Wagner algorithm (CslibFrontier.Algorithms.Lean.StoerWagner.Basic) are built on this API.

Main definitions #

Main results #

References #

Merging (mergePair) and swap-compaction (embedCompact / contractMatrix) #

def Cslib.WeightedCut.mergePair {k : ℕ} (W : Fin k → Fin k → ℕ) (u v i j : Fin k) :

Matrix update when merging active supervertex v into u (u ≠ v): edges incident to v are redirected to u, self-loops at u are cleared, and row/column v become isolated.

Instances For
    theorem Cslib.WeightedCut.isMultigraph_mergePair {k : ℕ} {W : Fin k → Fin k → ℕ} (hW : IsMultigraph W) (u v : Fin k) :
    theorem Cslib.WeightedCut.mergePair_isolated_left {k : ℕ} (W : Fin k → Fin k → ℕ) (u v j : Fin k) :
    mergePair W u v v j = 0
    theorem Cslib.WeightedCut.mergePair_isolated_right {k : ℕ} (W : Fin k → Fin k → ℕ) (u v i : Fin k) :
    mergePair W u v i v = 0
    theorem Cslib.WeightedCut.rowDeg_mergePair_other {k : ℕ} {W : Fin k → Fin k → ℕ} (hW : IsMultigraph W) {u v x : Fin k} (huv : u ≠ v) (hxu : x ≠ u) (hxv : x ≠ v) :
    rowDeg (mergePair W u v) x = rowDeg W x
    theorem Cslib.WeightedCut.rowDeg_mergePair_u {k : ℕ} {W : Fin k → Fin k → ℕ} (hW : IsMultigraph W) {u v : Fin k} (huv : u ≠ v) :
    rowDeg (mergePair W u v) u = rowDeg W u - W u v + (rowDeg W v - W v u)
    theorem Cslib.WeightedCut.rowDeg_mergePair_v {k : ℕ} (W : Fin k → Fin k → ℕ) (u v : Fin k) :
    rowDeg (mergePair W u v) v = 0
    def Cslib.WeightedCut.embedCompact {m : ℕ} (v : Fin (m + 1)) (i : Fin m) :
    Fin (m + 1)

    Embedding Fin m → Fin (m + 1) corresponding to replacing removed slot v with Fin.last m and keeping all other slots < m in place.

    Instances For
      theorem Cslib.WeightedCut.embedCompact_ne {m : ℕ} (v : Fin (m + 1)) (i : Fin m) :
      def Cslib.WeightedCut.compactIdx {m : ℕ} (v a : Fin (m + 1)) (ha : a ≠ v) :
      Fin m

      Inverse of embedCompact v on {a : Fin (m + 1) // a ≠ v}.

      Instances For
        @[simp]
        theorem Cslib.WeightedCut.embedCompact_compactIdx {m : ℕ} (v a : Fin (m + 1)) (ha : a ≠ v) :
        @[simp]
        theorem Cslib.WeightedCut.compactIdx_embedCompact {m : ℕ} (v : Fin (m + 1)) (i : Fin m) :
        compactIdx v (embedCompact v i) ⋯ = i
        def Cslib.WeightedCut.contractMatrix {m : ℕ} (W : Fin (m + 1) → Fin (m + 1) → ℕ) (u v : Fin (m + 1)) (i j : Fin m) :

        Swap-compacted m × m adjacency matrix after merging v into u (u ≠ v) and moving active supervertex Fin.last m into slot v (when v ≠ Fin.last m).

        Instances For
          theorem Cslib.WeightedCut.isMultigraph_contractMatrix {m : ℕ} {W : Fin (m + 1) → Fin (m + 1) → ℕ} (hW : IsMultigraph W) (u v : Fin (m + 1)) :
          theorem Cslib.WeightedCut.sum_embedCompact_eq_sum_erase {m : ℕ} (v : Fin (m + 1)) (f : Fin (m + 1) → ℕ) :
          ∑ i : Fin m, f (embedCompact v i) = ∑ a ∈ Finset.univ.erase v, f a
          theorem Cslib.WeightedCut.rowDeg_contractMatrix {m : ℕ} (W : Fin (m + 1) → Fin (m + 1) → ℕ) (u v : Fin (m + 1)) (i : Fin m) :
          theorem Cslib.WeightedCut.totalDoubledWeight_contractMatrix {m : ℕ} {W : Fin (m + 1) → Fin (m + 1) → ℕ} (hW : IsMultigraph W) {u v : Fin (m + 1)} (huv : u ≠ v) :
          def Cslib.WeightedCut.contractPart {n m : ℕ} (part : Fin n → Fin (m + 1)) (u v : Fin (m + 1)) (huv : u ≠ v) (x : Fin n) :
          Fin m

          Updated supervertex partition Fin n → Fin m after merging v into u (u ≠ v) and swap-compacting slot v.

          Instances For
            @[simp]
            theorem Cslib.WeightedCut.embedCompact_contractPart {n m : ℕ} (part : Fin n → Fin (m + 1)) (u v : Fin (m + 1)) (huv : u ≠ v) (x : Fin n) :
            embedCompact v (contractPart part u v huv x) = if part x = v then u else part x
            theorem Cslib.WeightedCut.filter_contractPart_eq {n m : ℕ} (part : Fin n → Fin (m + 1)) (u v : Fin (m + 1)) (huv : u ≠ v) (i : Fin m) :
            {x : Fin n | contractPart part u v huv x = i} = if embedCompact v i = u then {x : Fin n | part x = u} ∪ {x : Fin n | part x = v} else {x : Fin n | part x = embedCompact v i}
            theorem Cslib.WeightedCut.isContractionOf_contract {n m : ℕ} {W₀ : Fin n → Fin n → ℕ} {part : Fin n → Fin (m + 1)} {W : Fin (m + 1) → Fin (m + 1) → ℕ} (hC : IsContractionOf W₀ part W) {u v : Fin (m + 1)} (huv : u ≠ v) :
            IsContractionOf W₀ (contractPart part u v huv) (contractMatrix W u v)
            def Cslib.WeightedCut.contractCut {m : ℕ} (v : Fin (m + 1)) (B : Finset (Fin (m + 1))) :

            Active cut induced on Fin m after contracting a non-crossing pair (u, v).

            Instances For
              theorem Cslib.WeightedCut.pullbackCut_contractCut {n m : ℕ} (part : Fin n → Fin (m + 1)) {u v : Fin (m + 1)} (huv : u ≠ v) {B : Finset (Fin (m + 1))} (hsame : u ∈ B ↔ v ∈ B) :
              pullbackCut (contractPart part u v huv) (contractCut v B) = pullbackCut part B

              Pulling a cut back along the identity gives the same cut.

              theorem Cslib.WeightedCut.cutWeight_contractCut {k : ℕ} {W : Fin (k + 1) → Fin (k + 1) → ℕ} (hW : IsMultigraph W) {s t : Fin (k + 1)} (hst : s ≠ t) {C : Finset (Fin (k + 1))} (hC : s ∈ C ↔ t ∈ C) :

              Merging t into s preserves the weight of the cuts that do not separate s and t.