Documentation

CslibFrontier.DataStructure.KServer.Basic

The k-server problem #

This file defines the k-server problem of Manasse, McGeoch and Sleator, Competitive algorithms for server problems (see also Borodin and El-Yaniv, Online Computation and Competitive Analysis, Chapter 10) as an instance of the online framework Cslib.DataStructure.Online.Problem, together with the matching distance between configurations used by potential-function analyses.

k servers occupy points of a metric space. Each request is a point, and to serve it some server must move onto it. Serving a request costs the total distance moved by all servers.

Model #

Main definitions #

Main results #

References #

A metric on α with natural-number distances.

  • dist : α → α → ℕ

    The distance between two points.

  • dist_self (x : α) : self.dist x x = 0
  • eq_of_dist_eq_zero {x y : α} : self.dist x y = 0 → x = y
  • dist_comm (x y : α) : self.dist x y = self.dist y x
  • dist_triangle (x y z : α) : self.dist x z ≤ self.dist x y + self.dist y z

The line metric on ℤ, dist x y = |x - y|.

The uniform metric: distinct points are at distance 1.

theorem Cslib.DataStructure.KServer.NatMetric.dist_pos_of_ne {α : Type} (M : NatMetric α) {x y : α} (h : x ≠ y) :
0 < M.dist x y

Server movement #

def Cslib.DataStructure.KServer.moveCost {α : Type} (M : NatMetric α) {k : ℕ} (s s' : Fin k → α) :

Total distance moved when every server i goes from s i to s' i.

@[simp]
theorem Cslib.DataStructure.KServer.moveCost_self {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) :
moveCost M s s = 0
theorem Cslib.DataStructure.KServer.moveCost_triangle {α : Type} (M : NatMetric α) {k : ℕ} (s t u : Fin k → α) :
moveCost M s u ≤ moveCost M s t + moveCost M t u
theorem Cslib.DataStructure.KServer.moveCost_comp_perm {α : Type} (M : NatMetric α) {k : ℕ} (s s' : Fin k → α) (π : Equiv.Perm (Fin k)) :
moveCost M (s ∘ ⇑π) (s' ∘ ⇑π) = moveCost M s s'

Relabeling both configurations by the same permutation does not change the movement.

theorem Cslib.DataStructure.KServer.moveCost_update {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) (a : Fin k) (x : α) :
moveCost M s (Function.update s a x) = M.dist (s a) x

Moving one server costs its distance.

theorem Cslib.DataStructure.KServer.moveCost_update_update {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) {a b : Fin k} (hab : a ≠ b) (x y : α) :
moveCost M s (Function.update (Function.update s a x) b y) = M.dist (s a) x + M.dist (s b) y

Moving two distinct servers costs the sum of their distances.

The problem #

@[reducible, inline]

The k-server problem on the metric M: configurations are labeled server positions, any initial configuration is admissible, serving r means reaching a configuration with a server at r, and a step costs the total server movement.

Minimum-cost matching between configurations #

def Cslib.DataStructure.KServer.matchCostAlong {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) :

Cost of matching server i of s to server σ i of t.

theorem Cslib.DataStructure.KServer.matchCostAlong_eq_moveCost {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) :
matchCostAlong M s t σ = moveCost M s (t ∘ ⇑σ)

Matching along σ is the movement to the relabeled configuration t ∘ σ.

def Cslib.DataStructure.KServer.matchCost {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) :

Minimum-cost perfect matching distance between two configurations, i.e. the transport distance between the multisets of server positions.

theorem Cslib.DataStructure.KServer.matchCost_le {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) :
theorem Cslib.DataStructure.KServer.exists_matchCost_eq {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) :
∃ (σ : Equiv.Perm (Fin k)), matchCost M s t = matchCostAlong M s t σ
theorem Cslib.DataStructure.KServer.matchCost_le_moveCost {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) :
matchCost M s t ≤ moveCost M s t
@[simp]
theorem Cslib.DataStructure.KServer.matchCost_self {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) :
matchCost M s s = 0
theorem Cslib.DataStructure.KServer.matchCost_le_add_moveCost {α : Type} (M : NatMetric α) {k : ℕ} (s t t' : Fin k → α) :
matchCost M s t' ≤ matchCost M s t + moveCost M t t'

Moving the second configuration changes the matching distance by at most the movement.

theorem Cslib.DataStructure.KServer.matchCost_comp_perm {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (π : Equiv.Perm (Fin k)) :
matchCost M (s ∘ ⇑π) t = matchCost M s t

Relabeling the first configuration does not change the matching distance.

def Cslib.DataStructure.KServer.pairSum {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) :

Summed distance over ordered pairs of servers; each unordered pair is counted twice.

theorem Cslib.DataStructure.KServer.pairSum_comp_perm {α : Type} (M : NatMetric α) {k : ℕ} (s : Fin k → α) (π : Equiv.Perm (Fin k)) :
pairSum M (s ∘ ⇑π) = pairSum M s
theorem Cslib.DataStructure.KServer.matchCostAlong_swap_le {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) {a b : Fin k} (hbtw : M.dist (t (σ a)) (s a) = M.dist (t (σ a)) (s b) + M.dist (s b) (s a)) :
matchCostAlong M s t (σ * Equiv.swap a b) ≤ matchCostAlong M s t σ

Uncrossing: if s b lies on a geodesic from t (σ a) to s a, swapping the partners of a and b does not increase the matching cost.

theorem Cslib.DataStructure.KServer.matchCostAlong_update_le {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) (i : Fin k) (y : α) :
matchCostAlong M (Function.update s i y) t σ ≤ matchCostAlong M s t σ + M.dist (s i) y

Moving one server changes a fixed matching's cost by at most the distance moved.

theorem Cslib.DataStructure.KServer.matchCostAlong_update_toward {α : Type} (M : NatMetric α) {k : ℕ} (s t : Fin k → α) (σ : Equiv.Perm (Fin k)) (i : Fin k) (y : α) (hy : M.dist (s i) (t (σ i)) = M.dist (s i) y + M.dist y (t (σ i))) :
matchCostAlong M (Function.update s i y) t σ + M.dist (s i) y = matchCostAlong M s t σ

Moving one server along a geodesic toward its partner lowers the cost by the distance moved.