Documentation

CslibFrontier.DataStructure.KServer.DoubleCoverage

Double Coverage is k-competitive on the line #

This file proves the theorem of Chrobak, Karloff, Payne and Vishwanathan, New results on server problems: the Double Coverage algorithm for k servers on the line is k-competitive. Together with the general lower bound (CslibFrontier.DataStructure.KServer.LowerBound) this settles the deterministic competitive ratio of the k-server problem on the line: from any start with distinct servers it is exactly k, with an additive constant depending on the start. Double Coverage is not competitive with one additive constant for all starts (IsCompetitive). The proof is the standard potential-function argument for this algorithm (see also Borodin and El-Yaniv, Online Computation and Competitive Analysis, Chapter 10). The line is usually taken to be the real line; here the points are integers, which keeps distances natural numbers.

The algorithm #

Double Coverage (dcStep) serves a request r on the line ℤ with k = n + 1 servers as follows. If r lies left of all servers, the leftmost server moves to r; symmetrically on the right. Otherwise let a, b be the nearest servers with s a ≤ r < s b. Both move toward r by min (r - s a) (s b - r), so one of them reaches r. A request on a server costs nothing. When several servers share a position, only one of them moves. The implementation sorts the configuration (Tuple.sort), applies the sorted rule dcSorted and undoes the sort, so labels are preserved.

Potential function #

With M_min the minimum-cost matching between the Double Coverage and offline configurations (matchCost) and Σ_{i<j} |s_i - s_j| the pairwise spread, the potential is Φ = k * M_min + Σ_{i<j} |s_i - s_j|. We use the doubled potential 2 * Φ = 2 * k * matchCost + pairSum, since pairSum counts ordered pairs. Then each request satisfies 2 * cost_DC + Δ(2 * Φ) ≤ 2 * k * cost_OPT (dcStep_amortized_offline).

Main definitions #

Main results #

References #

Double Coverage on a sorted configuration #

def Cslib.DataStructure.KServer.countLe {n : ℕ} (t : Fin n → ℤ) (r : ℤ) :

Number of servers at or left of r.

theorem Cslib.DataStructure.KServer.lt_countLe_iff {n : ℕ} {t : Fin n → ℤ} (ht : Monotone t) (r : ℤ) (i : Fin n) :
↑i < countLe t r ↔ t i ≤ r

On a sorted configuration, the servers at or left of r are exactly the first countLe t r.

theorem Cslib.DataStructure.KServer.countLe_le {n : ℕ} (t : Fin n → ℤ) (r : ℤ) :
countLe t r ≤ n
def Cslib.DataStructure.KServer.dcSorted {n : ℕ} (t : Fin (n + 1) → ℤ) (r : ℤ) :
Fin (n + 1) → ℤ

Double Coverage on a sorted configuration of n + 1 servers. With c servers at or left of r: if c = 0 the leftmost server moves to r, if c = n + 1 the rightmost does, and otherwise servers c - 1 and c move toward r by min (r - t (c - 1)) (t c - r).

theorem Cslib.DataStructure.KServer.exists_dcSorted_eq {n : ℕ} (t : Fin (n + 1) → ℤ) (r : ℤ) :
∃ (i : Fin (n + 1)), dcSorted t r i = r

Double Coverage on a sorted configuration serves the request.

def Cslib.DataStructure.KServer.dcStep {n : ℕ} (s : Fin (n + 1) → ℤ) (r : ℤ) :
Fin (n + 1) → ℤ

Double Coverage on an arbitrary configuration: sort, apply dcSorted, unsort.

theorem Cslib.DataStructure.KServer.dcStep_comp_sort {n : ℕ} (s : Fin (n + 1) → ℤ) (r : ℤ) :
dcStep s r ∘ ⇑(Tuple.sort s) = dcSorted (s ∘ ⇑(Tuple.sort s)) r

Relabeling dcStep s r by the sorting permutation of s gives the sorted step.

theorem Cslib.DataStructure.KServer.exists_dcStep_eq {n : ℕ} (s : Fin (n + 1) → ℤ) (r : ℤ) :
∃ (i : Fin (n + 1)), dcStep s r i = r

Double Coverage serves the request.

theorem Cslib.DataStructure.KServer.dcStep_of_monotone {n : ℕ} {s : Fin (n + 1) → ℤ} (hs : Monotone s) (r : ℤ) :
dcStep s r = dcSorted s r

On an already sorted configuration, dcStep is dcSorted.

The amortized step inequality #

theorem Cslib.DataStructure.KServer.dcStep_amortized {n : ℕ} (s o : Fin (n + 1) → ℤ) {r : ℤ} (hr : ∃ (j : Fin (n + 1)), o j = r) :

The doubled amortized step inequality when the offline configuration o already covers the request: 2 * cost_DC + Δ(2 * k * matchCost + pairSum) ≤ 0.

theorem Cslib.DataStructure.KServer.dcStep_amortized_offline {n : ℕ} (s o o' : Fin (n + 1) → ℤ) {r : ℤ} (hr : ∃ (j : Fin (n + 1)), o' j = r) :

The doubled amortized step inequality: if the offline schedule moves from o to o' to serve r, then 2 * cost_DC + Δ(2 * Φ) ≤ 2 * k * cost_OPT for 2 * Φ = 2 * k * matchCost + pairSum.

The strategy and its competitive ratio #

The Double Coverage strategy for n + 1 servers on the integer line.

theorem Cslib.DataStructure.KServer.doubleCoverage_costFrom_le {n : ℕ} (s s_off : Fin (n + 1) → ℤ) (reqs : List ℤ) (offStates : List (Fin (n + 1) → ℤ)) (hv : (problem NatMetric.line (n + 1)).ValidSchedule s_off reqs offStates) :
2 * (doubleCoverage n).costFrom s reqs ≤ 2 * (n + 1) * (problem NatMetric.line (n + 1)).scheduleCost s_off reqs offStates + (2 * (n + 1) * matchCost NatMetric.line s s_off + pairSum NatMetric.line s)

Telescoped doubled potential bound for Double Coverage from configuration s, against any valid offline schedule from s_off.

theorem Cslib.DataStructure.KServer.doubleCoverage_cost_le {n : ℕ} (s₀ s_off : Fin (n + 1) → ℤ) (reqs : List ℤ) (offStates : List (Fin (n + 1) → ℤ)) (hv : (problem NatMetric.line (n + 1)).ValidSchedule s_off reqs offStates) :
(doubleCoverage n).cost s₀ reqs ≤ (n + 1) * (problem NatMetric.line (n + 1)).scheduleCost s_off reqs offStates + ((n + 1) * matchCost NatMetric.line s₀ s_off + pairSum NatMetric.line s₀ / 2)

Chrobak–Karloff–Payne–Vishwanathan. With k = n + 1 servers on the line, Double Coverage from s₀ costs at most k times any valid offline schedule from any s_off, plus k * matchCost s₀ s_off + Σ_{i<j} |s₀ i - s₀ j|.

Chrobak–Karloff–Payne–Vishwanathan. Double Coverage with k = n + 1 servers on the line is k-competitive from every initial configuration s₀, with additive constant pairSum s₀ / 2 = Σ_{i<j} |s₀ i - s₀ j|.

theorem Cslib.DataStructure.KServer.doubleCoverage_cost_cons {n : ℕ} (s₀ : Fin (n + 1) → ℤ) (r : ℤ) (rs : List ℤ) :
(doubleCoverage n).cost s₀ (r :: rs) = moveCost NatMetric.line s₀ (dcStep s₀ r) + (doubleCoverage n).cost (dcStep s₀ r) rs

Double Coverage's cost on a nonempty request sequence: the first step plus the rest.

@[simp]