Documentation

CslibFrontier.DataStructure.Online.SkiRental

Ski rental: the break-even strategy and the deterministic lower bound #

This file instantiates Cslib.DataStructure.Online.Problem for the deterministic ski-rental (rent-or-buy) problem. The rent-or-buy framing goes back to Karlin, Manasse, Rudolph, and Sleator, Competitive snoopy caching; the textbook treatment is in Borodin and El-Yaniv, Online Computation and Competitive Analysis.

Each request is one more day of skiing. Before every day the skier either rents for that day (cost 1) or buys (cost B, after which every further day is free). The online strategy does not know how many days remain. Offline schedules use the same states, transitions and costs, so the offline optimum on n days is min n B (exists_optimal_schedule, min_le_scheduleCost).

The break-even strategy rents for B - 1 days and buys on day B. On every request sequence and against every valid offline schedule its cost satisfies B * ALG ≤ (2B - 1) * OPT (breakEven_mul_cost_le), i.e. competitive ratio 2 - 1/B with no additive constant. Conversely every deterministic online strategy has an instance with OPT ≥ 1 and (2B - 1) * OPT ≤ B * ALG (exists_witness), so no deterministic strategy achieves any rational ratio p / q < 2 - 1/B without an additive constant (exists_ratio_violation_of_lt).

The break-even strategy is (1, B - 1)-competitive (breakEven_isCompetitive_one), so with an additive constant the factor-1 question is trivial; the meaningful ratio has no additive constant, and ratios for ski rental are stated with additive constant 0.

Main definitions #

Main results #

Randomized ski rental (ratio 1 / (1 - (1 - 1/B)^B) ≤ e/(e-1) and its matching lower bound) is in CslibFrontier.DataStructure.Online.SkiRental.Randomized.

References #

Ski-rental cost of moving from ownership state b to b' while serving one ski day, with purchase price B: free once owned, B on the day of purchase, and 1 for a rented day.

@[reducible, inline]

The ski-rental Online.Problem with purchase price B. The state records whether the skis have been bought; buying is irreversible; every run starts without skis.

Offline schedules #

theorem Cslib.DataStructure.Online.SkiRental.scheduleCost_true_eq_zero {B : ℕ} {reqs : List Unit} {states : List Bool} (hv : (problem B).ValidSchedule true reqs states) :
(problem B).scheduleCost true reqs states = 0

Once the skis are owned, every valid continuation keeps them and costs nothing.

theorem Cslib.DataStructure.Online.SkiRental.min_le_scheduleCost {B : ℕ} {reqs : List Unit} {states : List Bool} (hv : (problem B).ValidSchedule false reqs states) :
min reqs.length B ≤ (problem B).scheduleCost false reqs states

Offline lower bound. Every valid schedule from the initial state costs at least min n B on n ski days.

theorem Cslib.DataStructure.Online.SkiRental.validSchedule_replicate {B : ℕ} {b₀ b : Bool} (h : b₀ = true → b = true) (reqs : List Unit) :

The constant schedule replicate n b is valid from b₀ whenever b₀ = true → b = true.

Renting every day costs one per day.

Buying on the first day costs B on any nonempty request sequence.

Offline optimum. Renting every day (if n ≤ B) or buying on the first day (otherwise) is a valid schedule costing exactly min n B.

A schedule that rents for d days and then buys costs d + B.

A valid schedule that rents for d days and then buys costs d + B, whatever follows the purchase.

Rent-then-buy strategies #

@[reducible, inline]

The deterministic strategy that rents for the first t days and buys on day t + 1. Its memory records whether the skis are owned and how many days have been rented.

theorem Cslib.DataStructure.Online.SkiRental.rentThenBuy_costFrom_false {B t k : ℕ} (hk : k ≤ t) (reqs : List Unit) :
(rentThenBuy B t).costFrom (false, k) reqs = if k + reqs.length ≤ t then reqs.length else t - k + B

From the rented state after k ≤ t days, the remaining cost is the number of remaining days if the skier stops before day t + 1, and t - k + B otherwise.

Exact cost of rent-then-buy. On n ski days, rentThenBuy B t pays n if n ≤ t and t + B otherwise.

@[reducible, inline]

The break-even strategy: rent for B - 1 days and buy on day B.

theorem Cslib.DataStructure.Online.SkiRental.breakEven_mul_cost_le {B : ℕ} {reqs : List Unit} {states : List Bool} (hv : (problem B).ValidSchedule false reqs states) :
B * (breakEven B).cost false reqs ≤ (2 * B - 1) * (problem B).scheduleCost false reqs states

Break-even upper bound (for the rent-or-buy framing of [KMRS88] only): on every request sequence and against every valid offline schedule, the break-even strategy satisfies B * ALG ≤ (2B - 1) * OPT, i.e. it has competitive ratio 2 - 1/B with no additive constant.

The break-even strategy is (2, 0)-competitive.

With additive constant B - 1, the break-even strategy is even (1, B - 1)-competitive, which is why the ski-rental ratio 2 - 1/B is a statement without additive constant.

The break-even bound is attained: on B ski days the break-even strategy pays 2B - 1 while buying on the first day pays B.

Deterministic lower bound #

theorem Cslib.DataStructure.Online.SkiRental.exists_witness {B : ℕ} (hB : 1 ≤ B) (A : DetStrategy (problem B)) :
∃ (reqs : List (problem B).Req) (states : List (problem B).State), (problem B).ValidSchedule false reqs states ∧ 1 ≤ (problem B).scheduleCost false reqs states ∧ (2 * B - 1) * (problem B).scheduleCost false reqs states ≤ B * A.cost false reqs

Deterministic lower-bound witness. For every deterministic online ski-rental strategy (1 ≤ B) there are a request sequence and a valid offline schedule with offline cost at least 1 and (2B - 1) * OPT ≤ B * ALG. The adversary stops skiing on the day the strategy buys, or after 2B - 1 days if it never buys.

theorem Cslib.DataStructure.Online.SkiRental.exists_ratio_violation_of_lt {B : ℕ} (A : DetStrategy (problem B)) {p q : ℕ} (hpq : p * B < (2 * B - 1) * q) :
∃ (reqs : List (problem B).Req) (states : List (problem B).State), (problem B).ValidSchedule false reqs states ∧ p * (problem B).scheduleCost false reqs states < q * A.cost false reqs

Deterministic lower bound ([BElY98]): for every deterministic online ski-rental strategy and every rational ratio p / q < 2 - 1/B (i.e. p * B < (2B - 1) * q) there are a request sequence and a valid offline schedule with p * OPT < q * ALG.

For B ≥ 2, no deterministic online ski-rental strategy is (1, 0)-competitive.

On the first N ski days every deterministic strategy behaves like a rent-then-buy strategy: there is a threshold t with A.cost = (rentThenBuy B t).cost on every n ≤ N days. Take t to be the number of days the strategy rents before buying when it skis N days, or N if it never buys. This reduces lower bounds over arbitrary deterministic strategies, such as the randomized lower bound in CslibFrontier.DataStructure.Online.SkiRental.Randomized, to threshold strategies.