Randomized Ski Rental: Deriving the Optimal Distribution
The deterministic lower bound of the previous lesson works because the adversary knows the buying day and ends the season on it. A skier who buys on a random day, drawn from a distribution the adversary knows but whose outcome it does not, cannot be ambushed that way. Part I stated the optimal distribution and its ratio (Ski Rental: Rent or Buy?). This lesson derives both, in discrete and continuous time, and then proves with Yao's principle that no randomized strategy does better. The result is due to Karlin, Manasse, McGeoch and Owicki (1990); all bounds here are strict ratios against an oblivious adversary.
The equalizing idea
A randomized strategy buys on day with . Buying after day never helps (buying on day instead costs less on every long season and the same on short ones), so assume lives on . For a season of days the expected cost is
and for it no longer changes, while . The adversary picks the with the worst ratio . A natural guess for the best is the one that makes the adversary indifferent: for every . If any had a smaller ratio, weight could be shifted to lower the others.
Deriving the discrete distribution
Subtract consecutive equations. Going from to days, the outcome changes from "rented days" to "rented days and bought", adding , and every outcome pays one more day of rent:
So : each day is times as likely as the previous one, . The last equation (, where ) gives , and normalization gives . Hence
The program builds from the recurrence with exact fractions, checks that every season length gives the same ratio, and samples the strategy with a seeded generator to confirm the expectation empirically.
import random
from fractions import Fraction
def optimal_distribution(B):
r = Fraction(B - 1, B)
w = [r ** (B - i) for i in range(1, B + 1)] # p_i proportional to (1 - 1/B)^(B - i)
s = sum(w)
return [x / s for x in w]
def expected_cost(p, B, D):
return sum(pi * ((i - 1 + B) if D >= i else D) for i, pi in enumerate(p, start=1))
B = 10
p = optimal_distribution(B)
ratios = {D: expected_cost(p, B, D) / min(D, B) for D in range(1, 2 * B)}
print("p_1..p_B:", " ".join(f"{float(x):.4f}" for x in p))
print("distinct ratios over D = 1..19:", sorted({str(r) for r in ratios.values()}))
print(f"c_B = {float(ratios[1]):.6f}, formula {1 / (1 - (1 - 1 / B) ** B):.6f}")
rng = random.Random(7)
days = list(range(1, B + 1))
weights = [float(x) for x in p]
for D in [3, 10, 25]:
runs = [rng.choices(days, weights)[0] for _ in range(20000)]
avg = sum((j - 1 + B) if D >= j else D for j in runs) / len(runs)
print(f"season {D:2}: sampled E[cost]/OPT = {avg / min(D, B):.4f}")p_1..p_B: 0.0595 0.0661 0.0734 0.0816 0.0907 0.1007 0.1119 0.1244 0.1382 0.1535
distinct ratios over D = 1..19: ['10000000000/6513215599']
c_B = 1.535340, formula 1.535340
season 3: sampled E[cost]/OPT = 1.5363
season 10: sampled E[cost]/OPT = 1.5367
season 25: sampled E[cost]/OPT = 1.5338
The distinct-ratios line contains a single fraction: the adversary is indeed indifferent. Sampling agrees with the exact value up to the usual noise of 20000 runs.
The continuous version
In continuous time, rent accrues at rate 1 and the skier buys at a random time with density on . The same equalization, for all , reads
Differentiating once in gives , and once more gives . So , normalization gives , and putting into the first derivative gives . The skier buys at time
by inverting the distribution function .
In C++
Sampling the continuous strategy by inverse transform with a seeded std::mt19937_64, and measuring the expected ratio for several season lengths. The uniform is built from the top 53 bits of one 64-bit draw, so the sequence is the same on every standard library.
#include <cmath>
#include <cstdio>
#include <random>
int main() {
const double B = 10.0, e = std::exp(1.0);
std::mt19937_64 rng(42);
auto uniform = [&]() { return (rng() >> 11) * (1.0 / 9007199254740992.0); }; // [0, 1)
const int runs = 200000;
std::printf("e/(e - 1) = %.4f\n", e / (e - 1));
for (double D : {1.0, 4.0, 10.0, 30.0}) {
double total = 0;
for (int i = 0; i < runs; ++i) {
double T = B * std::log(1 + uniform() * (e - 1)); // buying time
total += (D <= T) ? D : T + B; // rented until D, or until T then bought
}
double opt = std::fmin(D, B);
std::printf("season %4.1f: E[cost] = %7.4f, OPT = %4.1f, ratio %.4f\n", D, total / runs, opt, total / runs / opt);
}
}e/(e - 1) = 1.5820
season 1.0: E[cost] = 1.5811, OPT = 1.0, ratio 1.5811
season 4.0: E[cost] = 6.3161, OPT = 4.0, ratio 1.5790
season 10.0: E[cost] = 15.8231, OPT = 10.0, ratio 1.5823
season 30.0: E[cost] = 15.8227, OPT = 10.0, ratio 1.5823
Every season length gives a ratio near ; short seasons as well as long ones.
Optimality: Yao's principle
Theorem (Karlin, Manasse, McGeoch and Owicki, 1990). No randomized ski-rental strategy has strict ratio below against an oblivious adversary in the discrete problem, and below in the continuous problem.
By Yao's principle, it suffices to find a distribution over seasons on which every deterministic strategy pays at least times the expected optimum. Equalize again, now on the adversary's side. The adversary uses seasons and one long season (any length at least ), with probabilities . Strategies are worse than on this support, so only matter. Moving the buying day from to saves on the season and costs one more day of rent on every longer season, so the deterministic strategies all cost the same exactly when
from fractions import Fraction
B = 10
# solve backwards: Pr[D > B-1] = q_L; q_j = Pr[D > j] / (B - 1)
q = {"L": Fraction(1)}
tail = Fraction(1) # Pr[D > j], unnormalized
for j in range(B - 1, 0, -1):
q[j] = tail / (B - 1)
tail += q[j]
total = sum(q.values())
q = {d: x / total for d, x in q.items()}
def det_cost(j, D): # D = "L" is a season longer than every j <= B
if D == "L" or D >= j:
return (j - 1) + B
return D
e_opt = sum(x * (B if d == "L" else d) for d, x in q.items())
costs = [sum(x * det_cost(j, d) for d, x in q.items()) for j in range(1, B + 1)]
print("E[ALG_j] for j = 1..B all equal:", len(set(costs)) == 1)
print(f"E[ALG]/E[OPT] = {float(costs[0] / e_opt):.6f}")
print(f"c_B = {1 / (1 - (1 - 1 / B) ** B):.6f}")
print(f"Pr[long season] = {float(q['L']):.4f}, Pr[D = 1] = {float(q[1]):.4f}")E[ALG_j] for j = 1..B all equal: True
E[ALG]/E[OPT] = 1.535340
c_B = 1.535340
Pr[long season] = 0.3874, Pr[D = 1] = 0.1000
The adversary's distribution makes every deterministic strategy pay exactly , so by Yao's principle no randomized strategy beats , and the distribution derived above is optimal. In continuous time the adversary's distribution becomes a density on plus an atom at a long season, and the bound is exactly .
Watching it in the lab
The lab's strategy 3 is the randomized discrete strategy. Its chart shows the expected cost over OPT for every season length: flat at up to , then falling, because long seasons only add to OPT's side. Compare with strategy 0 (break-even), whose curve peaks at .
Test yourself
In the optimal discrete strategy, how do and compare?
What density does the optimal continuous strategy use for its buying time on ?
- Uniform
- Proportional to
- Proportional to
- A point mass at
Why does the randomized strategy not contradict the deterministic lower bound ?
- It does contradict it
- That bound is for deterministic strategies, whose buying day the adversary knows; the oblivious adversary only knows the distribution
- Randomized strategies are measured with additive constants
- The randomized strategy rents forever
How is the optimality of proved?
- By an adaptive adversary
- By Yao's principle with a season distribution on which every deterministic strategy pays times the expected optimum
- By the minimax theorem applied to running times
- It is an open problem