Documentation

CslibFrontier.DataStructure.Online.SkiRental.Randomized

Randomized ski rental: the ratio 1 / (1 - (1 - 1/B)^B) ≤ e/(e-1), tight #

This file determines the best expected competitive ratio of randomized online strategies for the discrete ski-rental problem SkiRental.problem B (integer purchase price B ≥ 1, one request per ski day) against an oblivious adversary, in the model of CslibFrontier.DataStructure.Online.Randomized. The ratio is

randomizedRatio B = 1 / (1 - (1 - 1/B)^B) = B^B / (B^B - (B-1)^B) (randomizedRatio_eq),

for example 4/3 for B = 2 and 27/19 for B = 3. It is at most and tends to e/(e-1) ≈ 1.582 (randomizedRatio_le, tendsto_randomizedRatio; monotonicity in B is not proved), and it is below the deterministic 2 - 1/B of CslibFrontier.DataStructure.Online.SkiRental for every B ≥ 2 (randomizedRatio_lt_two_sub).

Upper bound. The strategy randomRentThenBuy B rents for t ∈ {0, …, B-1} days and buys on day t + 1, choosing t with probability proportional to buyWeight B t = (B-1)^(B-1-t) * B^t = B^(B-1) * (1 - 1/B)^(B-1-t) (buyWeight_eq), i.e. it buys on day i with probability proportional to (1 - 1/B)^(B-i). Its expected cost on n ski days is exactly randomizedRatio B * min n B (expectedCost_randomRentThenBuy), so it is randomizedRatio B-competitive with no additive constant (randomRentThenBuy_isCompetitive), hence e/(e-1)-competitive (randomRentThenBuy_isCompetitive_exp). This equalizing strategy is due to Karlin, Manasse, McGeoch, and Owicki, Competitive randomized algorithms for nonuniform problems; see also the textbook treatment of rent-or-buy in Borodin and El-Yaniv, Online Computation and Competitive Analysis.

Lower bound. Every randomized strategy has a request sequence with OPT ≥ 1 and randomizedRatio B * OPT ≤ E[ALG] (exists_randomized_witness), so no randomized strategy is (c, 0)-competitive for any c < randomizedRatio B (not_isCompetitive_of_lt). The proof is the easy direction of Yao's principle (RandStrategy.exists_le_mul_expectedCost) with the adversary distribution adversary B: ski k + 1 days with weight (B-1)^k * B^(B-2-k) for k < B - 1, and 2B - 1 days with weight (B-1)^(B-1). Against it every deterministic strategy, which on these lengths behaves like a rent-then-buy strategy (SkiRental.exists_rentThenBuy_cost_eq), has mean cost at least randomizedRatio B times the mean optimum (le_sum_advWeight_mul_cost, sum_advWeight_mul_min).

For any fixed B, ratios are stated with additive constant 0: the deterministic break-even strategy is already (1, B - 1)-competitive (breakEven_isCompetitive_one), so for fixed B an additive constant trivializes the ratio. Asymptotically as B → ∞, however, any fixed finite additive constant b is negligible: for every c < e/(e-1) and finite b, once B is sufficiently large, no randomized strategy is (c, b)-competitive (not_isCompetitive_eventually_of_lt).

Continuous-time randomized ski rental (with exact competitive ratio e/(e-1) for every purchase price B > 0) is in CslibFrontier.DataStructure.Online.SkiRental.Continuous.

Main definitions #

Main results #

References #

The ratio #

The optimal randomized competitive ratio for discrete ski rental with purchase price B: 1 / (1 - (1 - 1/B)^B).

theorem Cslib.DataStructure.Online.SkiRental.randomizedRatio_eq {B : ℕ} (hB : 1 ≤ B) :
randomizedRatio B = ↑B ^ B / (↑B ^ B - (↑B - 1) ^ B)

randomizedRatio B = B^B / (B^B - (B-1)^B); for instance 4/3 at B = 2.

randomizedRatio B as an extended real is the ratio of the natural numbers B^B and B^B - (B-1)^B.

randomizedRatio B ≤ e/(e-1), from (1 - 1/B)^B ≤ e⁻¹.

For B ≥ 2 randomization helps: randomizedRatio B < 2 - 1/B, the optimal deterministic ratio (SkiRental.breakEven_mul_cost_le, SkiRental.exists_ratio_violation_of_lt).

Arithmetic of the two distributions #

Writing B = m + 1, these identities are the finite geometric sums behind the equalizing strategy and the equalizing adversary.

The equalizing randomized strategy #

Unnormalized probability that the equalizing strategy rents for t < B days and buys on day t + 1: (B-1)^(B-1-t) * B^t.

theorem Cslib.DataStructure.Online.SkiRental.buyWeight_eq {B t : ℕ} (hB : 1 ≤ B) (ht : t < B) :
↑(buyWeight B t) = ↑B ^ (B - 1) * (1 - 1 / ↑B) ^ (B - 1 - t)

buyWeight B t is proportional to (1 - 1/B)^(B-1-t), i.e. buying on day i = t + 1 has weight proportional to (1 - 1/B)^(B-i).

The weights sum to B^B - (B-1)^B.

The equalizing distribution of the number of rented days t < B.

@[simp]
theorem Cslib.DataStructure.Online.SkiRental.rentDays_apply (B : ℕ) [NeZero B] (t : Fin B) :
(rentDays B) t = ↑(buyWeight B ↑t) / ↑(B ^ B - (B - 1) ^ B)

The equalizing randomized ski-rental strategy of [KMMcGO94]: draw the number of rented days t from rentDays B, then rent for t days and buy on day t + 1.

Exact expected cost of the equalizing strategy. On n ski days randomRentThenBuy B pays randomizedRatio B * min n B in expectation, i.e. exactly randomizedRatio B times the offline optimum.

Upper bound [KMMcGO94]: against every valid offline schedule, the expected cost of randomRentThenBuy B is at most randomizedRatio B times the schedule's cost.

randomRentThenBuy B is randomizedRatio B-competitive against an oblivious adversary, with no additive constant.

randomRentThenBuy B is e/(e-1)-competitive against an oblivious adversary, for every purchase price B ≥ 1.

The matching lower bound #

Number of ski days chosen by the adversary: k + 1 for some k with k < B - 1, and 2B - 1 for none.

Unnormalized adversary weights: (B-1)^k * B^(B-2-k) for k + 1 days, and (B-1)^(B-1) for 2B - 1 days.

theorem Cslib.DataStructure.Online.SkiRental.sum_advWeight (B : ℕ) [NeZero B] :
∑ o : Option (Fin (B - 1)), advWeight B o = B ^ (B - 1)

The adversary weights sum to B^(B-1).

theorem Cslib.DataStructure.Online.SkiRental.sum_advWeight_mul_min (B : ℕ) [NeZero B] :
∑ o : Option (Fin (B - 1)), advWeight B o * min (advDays B o) B = B ^ B - (B - 1) ^ B

Weighted offline optimum under the adversary: ∑ advWeight * min days B = B^B - (B-1)^B.

Every deterministic strategy pays at least B^B against the weighted adversary, i.e. at least randomizedRatio B times the weighted optimum B^B - (B-1)^B.

The oblivious adversary distribution on ski-day counts, with probabilities advWeight B o / B^(B-1).

@[simp]
theorem Cslib.DataStructure.Online.SkiRental.adversary_apply (B : ℕ) [NeZero B] (o : Option (Fin (B - 1))) :
(adversary B) o = ↑(advWeight B o) / ↑(B ^ (B - 1))

Lower bound. Every randomized ski-rental strategy μ has, against an oblivious adversary, a request sequence and a valid offline schedule with OPT ≥ 1 and randomizedRatio B * OPT ≤ E_μ[ALG]. At B = 0 the ratio is 0 and one rented day is a witness.

No randomized ski-rental strategy is (c, 0)-competitive against an oblivious adversary for any c < randomizedRatio B; with randomRentThenBuy_isCompetitive, randomizedRatio B is the optimal randomized ratio.

Asymptotic randomized lower bound with additive constant ([KMMcGO94]; [BElY98]): for every competitive ratio c < e/(e-1) and every finite additive constant b, once the purchase price B is sufficiently large, no randomized ski-rental strategy is (c, b)-competitive against an oblivious adversary.