Documentation

CslibFrontier.Algorithms.Online.BipartiteMatching.Basic

Online bipartite matching: model, greedy 1/2-competitiveness, and deterministic hardness #

This module formalizes the online bipartite matching model of Karp, Vazirani, and Vazirani [KVV90]. A finite set L of offline vertices is known in advance; online vertices arrive sequentially, each revealing its neighborhood N : Finset L upon arrival. An online algorithm must irrevocably match the arriving vertex to an unmatched neighbor or leave it unmatched, without seeing future arrivals.

Model and conventions #

Main definitions #

Main results #

References #

Arrival sequences and maximal matchings #

The bipartite graph on L × Fin arrivals.length whose j-th online vertex has offline neighborhood arrivals[j].

def Cslib.Algorithms.Online.BipartiteMatching.IsMaximalMatching {L : Type u_1} {R : Type u_2} (G : L × R → Bool) (M : Finset (L × R)) :

M is a maximal matching in G if M is a matching and every edge of G shares an endpoint with some edge in M.

Every maximal matching in a bipartite graph has size at least half of every matching.

Deterministic online matching algorithms #

Admissible online matching step: match the arriving vertex to u if choice = some u with u ∈ N and u ∉ matched; otherwise leave it unmatched.

theorem Cslib.Algorithms.Online.BipartiteMatching.onlineStep_eq_some_iff {L : Type u_1} [DecidableEq L] {matched N : Finset L} {o : Option L} {u : L} :
onlineStep matched N o = some u ↔ o = some u ∧ u ∈ N ∧ u ∉ matched

Update the set of matched offline vertices after an admissible step choice c.

A deterministic online bipartite matching algorithm on offline vertex set L. At each step, given the list hist of previously revealed neighborhoods, the set matched of already-matched offline vertices, and the newly arrived vertex's neighborhood N, choose hist matched N selects an offline vertex to match (or none to leave the arriving vertex unmatched).

Execute A from history hist and already-matched offline set matched on the remaining arrival sequence, returning the per-arrival match choices (some u or none).

The list of per-arrival match choices made by A on arrivals.

The set of matched offline vertices after running A from (hist, matched) on rest.

The set of offline vertices matched by A on arrivals.

@[simp]
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.length_runChoicesFrom {L : Type u_1} [DecidableEq L] (A : DetAlg L) (hist : List (Finset L)) (matched : Finset L) (rest : List (Finset L)) :
(A.runChoicesFrom hist matched rest).length = rest.length
@[simp]
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.runChoicesFrom_append {L : Type u_1} [DecidableEq L] (A : DetAlg L) (hist : List (Finset L)) (matched : Finset L) (a₁ a₂ : List (Finset L)) :
A.runChoicesFrom hist matched (a₁ ++ a₂) = A.runChoicesFrom hist matched a₁ ++ A.runChoicesFrom (hist ++ a₁) (A.matchedLeftFrom hist matched a₁) a₂
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.runChoices_append {L : Type u_1} [DecidableEq L] (A : DetAlg L) (a₁ a₂ : List (Finset L)) :
A.runChoices (a₁ ++ a₂) = A.runChoices a₁ ++ A.runChoicesFrom a₁ (A.matchedLeft a₁) a₂

Online causality: the choices of A on a₁ ++ a₂ extend its choices on a₁ without depending on a₂.

theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.matchedLeftFrom_append {L : Type u_1} [DecidableEq L] (A : DetAlg L) (hist : List (Finset L)) (matched : Finset L) (a₁ a₂ : List (Finset L)) :
A.matchedLeftFrom hist matched (a₁ ++ a₂) = A.matchedLeftFrom (hist ++ a₁) (A.matchedLeftFrom hist matched a₁) a₂
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.subset_matchedLeftFrom {L : Type u_1} [DecidableEq L] (A : DetAlg L) (hist : List (Finset L)) (matched : Finset L) (rest : List (Finset L)) :
matched ⊆ A.matchedLeftFrom hist matched rest
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.mem_matchedLeftFrom_iff {L : Type u_1} [DecidableEq L] (A : DetAlg L) (hist : List (Finset L)) (matched : Finset L) (rest : List (Finset L)) (u : L) :
u ∈ A.matchedLeftFrom hist matched rest ↔ u ∈ matched ∨ some u ∈ A.runChoicesFrom hist matched rest
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.mem_matchedLeft_iff {L : Type u_1} [DecidableEq L] (A : DetAlg L) (arrivals : List (Finset L)) (u : L) :
u ∈ A.matchedLeft arrivals ↔ some u ∈ A.runChoices arrivals
theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.matchedLeft_take_subset {L : Type u_1} [DecidableEq L] (A : DetAlg L) (arrivals : List (Finset L)) (i : ℕ) :
A.matchedLeft (List.take i arrivals) ⊆ A.matchedLeft arrivals

Matched offline vertices grow monotonically with prefixes of the arrival sequence.

theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.runChoices_getElem {L : Type u_1} [DecidableEq L] (A : DetAlg L) (arrivals : List (Finset L)) {i : ℕ} (hi : i < arrivals.length) :
(A.runChoices arrivals)[i] = onlineStep (A.matchedLeft (List.take i arrivals)) arrivals[i] (A.choose (List.take i arrivals) (A.matchedLeft (List.take i arrivals)) arrivals[i])

The i-th match choice of A on arrivals is the admissible online step from the state after arrivals.take i.

The matching (set of (offline, online) edges) produced by A on arrivals.

theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.mem_runMatching_iff {L : Type u_1} [DecidableEq L] (A : DetAlg L) (arrivals : List (Finset L)) (u : L) (j : Fin arrivals.length) :
(u, j) ∈ A.runMatching arrivals ↔ (A.runChoices arrivals)[↑j] = some u

Every deterministic online matching algorithm produces a valid matching on every arrival sequence.

The cardinality of A.runMatching arrivals equals the number of matched offline vertices.

theorem Cslib.Algorithms.Online.BipartiteMatching.DetAlg.card_runMatching_eq_sum {L : Type u_1} [DecidableEq L] (A : DetAlg L) (arrivals : List (Finset L)) :
(A.runMatching arrivals).card = ∑ j : Fin arrivals.length, if (A.runChoices arrivals)[↑j].isSome = true then 1 else 0

The cardinality of A.runMatching arrivals equals the sum of match indicators over arrivals.

The cardinality of A.runMatching arrivals equals the number of online vertices matched.

A deterministic online matching algorithm is greedy if it matches every arriving vertex that has at least one unmatched neighbor.

Every greedy deterministic online matching algorithm produces a maximal matching.

Greedy 1/2-competitiveness: every greedy deterministic online matching algorithm produces a matching of size at least half of every matching in the graph.

Deterministic 1/2 impossibility #

theorem Cslib.Algorithms.Online.BipartiteMatching.exists_det_half_witness_mul (k : ℕ) (A : DetAlg (Fin (2 * k))) :
∃ (arrivals : List (Finset (Fin (2 * k)))), arrivals.length = 2 * k ∧ (∃ (M : Finset (Fin (2 * k) × Fin arrivals.length)), Lean.MaxFlow.IsMatching (graphOfArrivals arrivals) M ∧ M.card = 2 * k) ∧ (A.runMatching arrivals).card ≤ k

2k + 2k deterministic lower bound: for every k and every deterministic online algorithm on Fin (2 * k), there is an arrival sequence admitting a perfect matching of size 2 * k on which the algorithm matches at most k edges.

theorem Cslib.Algorithms.Online.BipartiteMatching.exists_det_half_witness (A : DetAlg (Fin 2)) :
∃ (arrivals : List (Finset (Fin 2))), arrivals.length = 2 ∧ (∃ (M : Finset (Fin 2 × Fin arrivals.length)), Lean.MaxFlow.IsMatching (graphOfArrivals arrivals) M ∧ M.card = 2) ∧ (A.runMatching arrivals).card ≤ 1

Tight 1/2 deterministic lower bound on a 2 + 2 graph [KVV90]: for every deterministic online matching algorithm on Fin 2, there is a 2-arrival sequence admitting a perfect matching of size 2 on which the algorithm matches at most 1 edge.

theorem Cslib.Algorithms.Online.BipartiteMatching.not_det_competitive_of_gt_half {c : ℝ} (hc : 1 / 2 < c) (b : ℝ) :
∃ (k : ℕ), ∀ (A : DetAlg (Fin (2 * k))), ∃ (arrivals : List (Finset (Fin (2 * k)))) (M : Finset (Fin (2 * k) × Fin arrivals.length)), Lean.MaxFlow.IsMatching (graphOfArrivals arrivals) M ∧ ↑(A.runMatching arrivals).card < c * ↑M.card - b

No deterministic online matching algorithm achieves competitive ratio strictly above 1/2, even with an arbitrary additive slack b.

Randomized online matching algorithms and Yao's principle #

@[reducible, inline]

A randomized online matching algorithm against an oblivious adversary: a discrete (countably supported) probability distribution over deterministic online matching algorithms.

Expected matching size of μ : RandAlg L on a fixed arrival sequence arrivals.

theorem Cslib.Algorithms.Online.BipartiteMatching.RandAlg.expectedMatchingSize_map {L : Type u_1} [DecidableEq L] {α : Type u_2} [Fintype α] (ν : PMF α) (f : α → DetAlg L) (arrivals : List (Finset L)) :
expectedMatchingSize (PMF.map f ν) arrivals = ∑ a : α, (ν a).toReal * ↑((f a).runMatching arrivals).card

Expected matching size of a randomized algorithm drawn by mapping a finite distribution ν.

Expected matching size of a uniformly sampled finite family of deterministic algorithms.

theorem Cslib.Algorithms.Online.BipartiteMatching.RandAlg.exists_expectedMatchingSize_le {L : Type u_1} [DecidableEq L] {ι : Type u_2} [Fintype ι] (ν : PMF ι) (arrivals : ι → List (Finset L)) {B : ℝ} (hB : 0 ≤ B) (h : ∀ (A : DetAlg L), ∑ i : ι, (ν i).toReal * ↑(A.runMatching (arrivals i)).card ≤ B) (μ : RandAlg L) :
∃ i ∈ ν.support, μ.expectedMatchingSize (arrivals i) ≤ B

Yao's principle [Yao77] for expected matching size: if under an input distribution ν over arrival sequences, every deterministic online algorithm has expected matching size at most B, then every randomized online algorithm has some instance in the support of ν on which its expected matching size is at most B.