Documentation

CslibFrontier.Algorithms.Online.BipartiteMatching.Ranking

The RANKING algorithm for online bipartite matching (1 - 1/e, tight) #

This module formalizes the randomized RANKING algorithm of Karp, Vazirani, and Vazirani [KVV90], proves its exact 1 - 1/e competitive ratio via the randomized primal-dual analysis of Devanur, Jain, and Kleinberg [DJK13], and proves the matching 1 - 1/e + o(1) Yao minimax upper bound for all randomized online bipartite matching algorithms against an oblivious adversary.

Proof structure #

  1. Key-based greedy matching (rankingByKey, rankingDet, rankingAlg): Given an injective priority key key : L → ℕ, rankingByKey key hkey greedily matches each arriving online vertex to its unmatched neighbor minimizing key. rankingAlg L samples a ranking π : L ≃ Fin (Fintype.card L) uniformly at random and runs rankingDet π.
  2. Dominance and monotonicity (rankingByKey_monotone_choice, rankingByKey_dominance): Comparing rankingByKey on arrivals and on deleteOffline u arrivals via a three-state alternating-path invariant (same, justU, shifted w) proves both:
    • Monotonicity: if online vertex j is matched to w without u, then with u it is matched to some a with key a ≤ key w.
    • Dominance: if u ∈ arrivals[j] remains unmatched in arrivals, then arrivals and deleteOffline u arrivals produce identical matchings and j is matched to some w with key w < key u.
  3. Discrete randomized primal-dual fitting (djkWeight, rankingGridAlg, rankingGrid_competitive_ratio): Sampling i.i.d. uniform discrete ranks y : L → Fin K (breaking ties by a fixed order ord : L ≃ Fin n) with discrete weight djkWeight K r = (K / (K + 1)) ^ (K - r), we define explicit primal-dual variables djkDualLeft and djkDualRight summing to the matching size (sum_djkDual_eq_card) whose average over y u ∈ Fin K is at least 1 - (K / (K + 1)) ^ K for every edge (sum_djkDual_update_ge). Averaging over y yields ratio 1 - (K / (K + 1)) ^ K for rankingGridAlg L K.
  4. Exact 1 - 1/e competitive ratio (ranking_competitive_ratio): Conditioned on y : L → Fin K being injective (which happens with probability K.descFactorial n / K ^ n → 1 as K → ∞), rankingGridDet y ord induces a uniform random permutation π : L ≃ Fin n. Passing to the limit K → ∞ gives the exact bound (1 - Real.exp (-1)) * M.card ≤ expectedMatchingSize (rankingAlg L) arrivals for every finite L, every arrival sequence arrivals, and every matching M.
  5. Tight 1 - 1/e Yao minimax upper bound (triArrivals, det_triArrivals_avg_le_harmonic, exists_rand_harmonic_upper_bound, exists_rand_exp_upper_bound, not_rand_competitive_of_gt_one_sub_exp_neg_one): On a uniformly permuted upper-triangular graph triArrivals n σ (which always has a perfect matching of size n), the symmetry σ ↦ σ * Equiv.swap t j yields the exact telescoping recurrence (n - t) * E[U_{t+1}] = (n - t - 1) * (E[U_t] - p_t), implying ∑ t, p_t / (n - t) ≤ 1 and hence E[|M|] ≤ n - s * (harmonic n - harmonic s) for every s ≤ n (in particular 3/4 * OPT at n = 2, and (1 - 1/e) * n + 2 for all n ≥ 1). Yao's principle transfers this bound to every randomized online algorithm.

Main definitions #

Main results #

References #

Key-ordered greedy matching and RANKING #

Binary minimum selector on Option L with respect to a key function key : L → ℕ.

Computable minimum-key element of a finite set U : Finset L for an injective key key : L → ℕ. Returns none iff U = ∅.

@[simp]
theorem Cslib.Algorithms.Online.BipartiteMatching.minByKey_eq_some_iff {L : Type u_1} (key : L → ℕ) (hkey : Function.Injective key) (U : Finset L) (u : L) :
minByKey key hkey U = some u ↔ u ∈ U ∧ ∀ w ∈ U, key u ≤ key w
theorem Cslib.Algorithms.Online.BipartiteMatching.minByKey_congr_order {L : Type u_1} {key₁ key₂ : L → ℕ} (h₁ : Function.Injective key₁) (h₂ : Function.Injective key₂) {U : Finset L} (hord : ∀ a ∈ U, ∀ b ∈ U, key₁ a ≤ key₁ b ↔ key₂ a ≤ key₂ b) :
minByKey key₁ h₁ U = minByKey key₂ h₂ U

Deterministic greedy online matching algorithm matching each arriving vertex to the unmatched neighbor minimizing key.

theorem Cslib.Algorithms.Online.BipartiteMatching.onlineStep_rankingByKey {L : Type u_1} [DecidableEq L] (key : L → ℕ) (hkey : Function.Injective key) (hist : List (Finset L)) (matched N : Finset L) :
onlineStep matched N ((rankingByKey key hkey).choose hist matched N) = minByKey key hkey (N \ matched)
theorem Cslib.Algorithms.Online.BipartiteMatching.rankingByKey_congr_order {L : Type u_1} [DecidableEq L] {key₁ key₂ : L → ℕ} (h₁ : Function.Injective key₁) (h₂ : Function.Injective key₂) (arrivals : List (Finset L)) (hord : ∀ N ∈ arrivals, ∀ a ∈ N, ∀ b ∈ N, key₁ a ≤ key₁ b ↔ key₂ a ≤ key₂ b) :
(rankingByKey key₁ h₁).runChoices arrivals = (rankingByKey key₂ h₂).runChoices arrivals

Deterministic RANKING with a fixed ranking bijection π : L ≃ Fin (Fintype.card L).

The randomized RANKING algorithm [KVV90]: sample a ranking π : L ≃ Fin (Fintype.card L) uniformly at random and run rankingDet π.

Dominance and monotonicity (three-state alternating-path invariant) #

Delete offline vertex u from every neighborhood in an arrival sequence.

@[simp]
theorem Cslib.Algorithms.Online.BipartiteMatching.length_deleteOffline {L : Type u_1} [DecidableEq L] (u : L) (arrivals : List (Finset L)) :
(deleteOffline u arrivals).length = arrivals.length
theorem Cslib.Algorithms.Online.BipartiteMatching.rankingByKey_monotone_choice {L : Type u_1} [DecidableEq L] {key : L → ℕ} (hkey : Function.Injective key) (u : L) (arrivals : List (Finset L)) (j : Fin arrivals.length) {w : L} (hw : ((rankingByKey key hkey).runChoices (deleteOffline u arrivals))[↑j] = some w) :
∃ (a : L), ((rankingByKey key hkey).runChoices arrivals)[↑j] = some a ∧ key a ≤ key w

Monotonicity lemma [DJK13]: if online vertex j is matched to w when offline vertex u is deleted, then in the full graph j is matched to some vertex a of priority key a ≤ key w.

theorem Cslib.Algorithms.Online.BipartiteMatching.rankingByKey_dominance {L : Type u_1} [DecidableEq L] {key : L → ℕ} (hkey : Function.Injective key) (u : L) (arrivals : List (Finset L)) (j : Fin arrivals.length) (huj : u ∈ arrivals[↑j]) (hnot : u ∉ (rankingByKey key hkey).matchedLeft arrivals) :
(rankingByKey key hkey).runChoices arrivals = (rankingByKey key hkey).runChoices (deleteOffline u arrivals) ∧ ∃ (w : L), ((rankingByKey key hkey).runChoices (deleteOffline u arrivals))[↑j] = some w ∧ key w < key u

Dominance lemma [DJK13]: if (u, j) is an edge (u ∈ arrivals[j]) and offline vertex u remains unmatched by rankingByKey key hkey on arrivals, then:

  1. deleting u leaves all match choices unchanged; and
  2. in deleteOffline u arrivals, online vertex j is matched to some offline vertex w of strictly higher priority (key w < key u).

Discrete Devanur–Jain–Kleinberg randomized primal-dual analysis #

Discrete DJK dual weight g_K(r) = (K / (K + 1)) ^ (K - r) for rank r ≤ K.

theorem Cslib.Algorithms.Online.BipartiteMatching.djkWeight_mono {K r₁ r₂ : ℕ} (h : r₁ ≤ r₂) :
djkWeight K r₁ ≤ djkWeight K r₂
def Cslib.Algorithms.Online.BipartiteMatching.gridKey {L : Type u_1} [Fintype L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (u : L) :

Lexicographic priority key n * y(u) + ord(u) for discrete ranks y : L → Fin K with deterministic tie-breaking ord : L ≃ Fin (Fintype.card L).

Deterministic RANKING on discrete ranks y : L → Fin K with tie-breaker ord.

noncomputable def Cslib.Algorithms.Online.BipartiteMatching.rankingGridAlg (L : Type u_2) [Fintype L] [DecidableEq L] (K : ℕ) (hK : 0 < K) (ord : L ≃ Fin (Fintype.card L)) :

Randomized RANKING sampling i.i.d. uniform discrete ranks y : L → Fin K with fixed tie-breaker ord.

noncomputable def Cslib.Algorithms.Online.BipartiteMatching.djkDualLeft {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) (u : L) :

DJK dual variable α(y, u) for offline vertex u: djkWeight K (y u) if u is matched, else 0.

noncomputable def Cslib.Algorithms.Online.BipartiteMatching.djkDualRight {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) (j : Fin arrivals.length) :

DJK dual variable β(y, j) for online vertex j: 1 - djkWeight K (y a) if j is matched to a, else 0.

theorem Cslib.Algorithms.Online.BipartiteMatching.djkDualLeft_nonneg {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) (u : L) :
0 ≤ djkDualLeft y ord arrivals u
theorem Cslib.Algorithms.Online.BipartiteMatching.djkDualRight_nonneg {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) (j : Fin arrivals.length) :
0 ≤ djkDualRight y ord arrivals j
theorem Cslib.Algorithms.Online.BipartiteMatching.sum_djkDual_eq_card {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) :
∑ u : L, djkDualLeft y ord arrivals u + ∑ j : Fin arrivals.length, djkDualRight y ord arrivals j = ↑((rankingGridDet y ord).runMatching arrivals).card

Exact primal-dual equality: for every discrete rank vector y, the dual variables sum to the matching size |M(y)|.

theorem Cslib.Algorithms.Online.BipartiteMatching.sum_djkDual_update_ge {L : Type u_1} [Fintype L] [DecidableEq L] {K : ℕ} (y : L → Fin K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) (u : L) (j : Fin arrivals.length) (huj : u ∈ arrivals[↑j]) :
↑K * (1 - (↑K / (↑K + 1)) ^ K) ≤ ∑ k : Fin K, (djkDualLeft (Function.update y u k) ord arrivals u + djkDualRight (Function.update y u k) ord arrivals j)

Expected dual feasibility on every edge [DJK13]: for any edge (u, j) (u ∈ arrivals[j]) and any ranks y on the other vertices, summing α + β over all K choices of y u is at least K * (1 - (K / (K + 1)) ^ K).

theorem Cslib.Algorithms.Online.BipartiteMatching.rankingGrid_competitive_ratio {L : Type u_1} [Fintype L] [DecidableEq L] (K : ℕ) (hK : 0 < K) (ord : L ≃ Fin (Fintype.card L)) (arrivals : List (Finset L)) {M : Finset (L × Fin arrivals.length)} (hM : Lean.MaxFlow.IsMatching (graphOfArrivals arrivals) M) :
(1 - (↑K / (↑K + 1)) ^ K) * ↑M.card ≤ (rankingGridAlg L K hK ord).expectedMatchingSize arrivals

Discrete RANKING competitive ratio: with uniform i.i.d. ranks in Fin K, rankingGridAlg L K achieves expected matching size at least (1 - (K / (K + 1)) ^ K) * |M| for every matching M.

Exact 1 - 1/e competitive ratio of RANKING #

Karp–Vazirani–Vazirani (1990) / Devanur–Jain–Kleinberg (2013) exact 1 - 1/e theorem: for every finite offline vertex set L, every arrival sequence arrivals, and every matching M of graphOfArrivals arrivals, rankingAlg L achieves expected matching size at least (1 - e⁻¹) * |M|.

Tight 1 - 1/e Yao minimax upper bound (permuted upper-triangular graph) #

Permuted upper-triangular arrival sequence triArrivals n σ on Fin n: online vertex j is adjacent to {σ(i) | j ≤ i < n}, i.e. {u | j ≤ σ⁻¹(u)}.

The canonical perfect matching {(σ(j), j) | j : Fin n} of triArrivals n σ.

theorem Cslib.Algorithms.Online.BipartiteMatching.det_triArrivals_avg_le_harmonic {n s : ℕ} (hn : 1 ≤ n) (hs : s ≤ n) (A : DetAlg (Fin n)) :
(∑ σ : Equiv.Perm (Fin n), ↑(A.runMatching (triArrivals n σ)).card) / ↑(Fintype.card (Equiv.Perm (Fin n))) ≤ ↑n - ↑s * (↑(harmonic n) - ↑(harmonic s))

Harmonic deterministic average upper bound on triArrivals n σ [KVV90]: for every n ≥ 1, every s ≤ n, and every deterministic online algorithm A : DetAlg (Fin n), the average matching size of A over all n! permutations σ is at most n - s * (harmonic n - harmonic s).

theorem Cslib.Algorithms.Online.BipartiteMatching.exists_rand_harmonic_upper_bound {n s : ℕ} (hn : 1 ≤ n) (hs : s ≤ n) (μ : RandAlg (Fin n)) :
∃ (σ : Equiv.Perm (Fin n)), μ.expectedMatchingSize (triArrivals n σ) ≤ ↑n - ↑s * (↑(harmonic n) - ↑(harmonic s))

Yao harmonic upper bound for all randomized algorithms: for every n ≥ 1, every s ≤ n, and every randomized online matching algorithm μ : RandAlg (Fin n), there exists a permutation σ such that triArrivals n σ admits a perfect matching of size n while μ.expectedMatchingSize (triArrivals n σ) ≤ n - s * (harmonic n - harmonic s).

Explicit 1 - 1/e + 2/n Yao upper bound: for every n ≥ 1 and every randomized online matching algorithm μ : RandAlg (Fin n), there exists a permutation σ such that triArrivals n σ admits a perfect matching of size n while μ.expectedMatchingSize (triArrivals n σ) ≤ (1 - e⁻¹) * n + 2.

theorem Cslib.Algorithms.Online.BipartiteMatching.not_rand_competitive_of_gt_one_sub_exp_neg_one {c : ℝ} (hc : 1 - Real.exp (-1) < c) (b : ℝ) :
∃ (n : ℕ), 1 ≤ n ∧ ∀ (μ : RandAlg (Fin n)), ∃ (arrivals : List (Finset (Fin n))) (M : Finset (Fin n × Fin arrivals.length)), Lean.MaxFlow.IsMatching (graphOfArrivals arrivals) M ∧ μ.expectedMatchingSize arrivals < c * ↑M.card - b

Tight 1 - 1/e randomized impossibility [KVV90]: no randomized online bipartite matching algorithm μ : RandAlg (Fin n) (where RandAlg L := PMF (DetAlg L) ranges over discrete, countably supported mixtures of deterministic online algorithms against an oblivious adversary) achieves competitive ratio strictly above 1 - 1/e, even with an arbitrary additive slack b.