Ski Rental Variants: Many Slopes and Predictions
Real rent-or-buy decisions rarely have exactly two options, and they are rarely made with no information at all. This lesson looks at two extensions, briefly but with proofs where the proofs are short. Multislope ski rental offers several options, from pure renting to pure buying with leases in between; its additive version has a clean 2-competitive deterministic algorithm that follows the offline cost curve. Learning-augmented ski rental gives the skier a prediction of the season length that may be wrong; the goal is to be nearly optimal when the prediction is right and still competitive when it is not. Ratios here are strict, deterministic unless stated, against an oblivious adversary.
Multislope ski rental
There are options . Option has a one-time price and a rental rate , with
At any moment the user may switch to an option with a larger index. In the additive version, moving from option to option costs (an upgrade: a lease can be converted into a purchase by paying the difference); in the general version it may cost more. Classical ski rental is the case , , , . Power management with several sleep states is the motivating example: deeper sleep states save more power per second but cost more to enter and leave.
If the usage lasts time , the offline optimum picks one option from the start:
the lower envelope of lines, a concave, piecewise linear function with .
Following the envelope
The lower-envelope algorithm (LEA) is always in the option that would be optimal if the usage ended right now, upgrading at the moments where the envelope changes line.
Theorem. In the additive version, LEA is 2-competitive: for every .
Proof
Let be the option on the envelope at time ; it only increases with . LEA pays rent at time , and, because upgrades are additive, its upgrade payments up to time add up to exactly . Since is concave with slope at and , the rent part equals . So
For this is the continuous break-even rule. The program evaluates LEA on a three-option instance (rent at rate 1, a lease with price 4 and rate , a purchase at 12) and compares it with the two-option break-even rule that ignores the lease.
from fractions import Fraction as F
options = [(F(0), F(1)), (F(4), F(2, 5)), (F(12), F(0))] # (price b_i, rate r_i)
def opt(t):
return min(b + r * t for b, r in options)
def envelope_option(t):
return min(range(len(options)), key=lambda i: (options[i][0] + options[i][1] * t, -i))
def lea_cost(t):
"""Integrate the rent along the envelope exactly at breakpoints, then add b of the final option."""
breaks = sorted({(bj - bi) / (ri - rj) for i, (bi, ri) in enumerate(options)
for j, (bj, rj) in enumerate(options) if j > i} | {F(0)})
breaks = [x for x in breaks if x < t] + [t]
rent = sum(options[envelope_option((a + b) / 2)][1] * (b - a) for a, b in zip(breaks, breaks[1:]))
return rent + options[envelope_option(t)][0]
def two_option_cost(t, B=F(12)): # rent until B, then buy
return t if t <= B else 2 * B
grid = [F(i, 4) for i in range(1, 161)] # usage times 0.25 .. 40
print(" t OPT LEA LEA/OPT rent-or-buy/OPT")
for t in [F(2), F(20, 3), F(10), F(20), F(30)]:
print(f"{float(t):5.2f} {float(opt(t)):6.2f} {float(lea_cost(t)):6.2f} {float(lea_cost(t) / opt(t)):8.3f}"
f" {float(two_option_cost(t) / opt(t)):12.3f}")
print(f"worst over the grid: LEA {float(max(lea_cost(t) / opt(t) for t in grid)):.3f}, "
f"rent-or-buy {float(max(two_option_cost(t) / opt(t) for t in grid)):.3f}") t OPT LEA LEA/OPT rent-or-buy/OPT
2.00 2.00 2.00 1.000 1.000
6.67 6.67 10.67 1.600 1.000
10.00 8.00 12.00 1.500 1.250
20.00 12.00 24.00 2.000 2.000
30.00 12.00 24.00 2.000 2.000
worst over the grid: LEA 2.000, rent-or-buy 2.697
Ignoring the middle option costs a lot when the usage ends in the lease's range: the plain rent-or-buy rule pays about times OPT right after it buys at , while LEA never exceeds 2.
In C++
The same lower-envelope algorithm, simulated in small time steps for a four-state power-down instance (active at rate 1, then three sleep states with growing wake-up costs and smaller rates). The program reports the worst ratio over idle periods of 1 to 300 time units.
#include <algorithm>
#include <cstdio>
#include <vector>
struct Option { double price, rate; };
int main() {
std::vector<Option> opts = {{0, 1.0}, {5, 0.5}, {20, 0.1}, {60, 0.0}};
auto opt = [&](double t) {
double best = 1e18;
for (auto& o : opts) best = std::min(best, o.price + o.rate * t);
return best;
};
auto best_option = [&](double t) {
int best = 0;
for (int i = 1; i < (int)opts.size(); ++i)
if (opts[i].price + opts[i].rate * t <= opts[best].price + opts[best].rate * t) best = i;
return best;
};
const double dt = 0.01;
double worst = 0, worst_t = 0, cost = 0;
int state = 0;
for (int step = 1; step <= 30000; ++step) {
double t = step * dt;
cost += opts[state].rate * dt; // rent during (t - dt, t]
int s = best_option(t);
if (s > state) { cost += opts[s].price - opts[state].price; state = s; } // additive upgrade
if (step % 100 == 0) { // check whole time units
double ratio = cost / opt(t);
if (ratio > worst) { worst = ratio; worst_t = t; }
}
}
std::printf("worst LEA/OPT over t = 1..300: %.3f at t = %.0f\n", worst, worst_t);
}worst LEA/OPT over t = 1..300: 1.840 at t = 38
The worst case sits right after a switch to a deeper state, where LEA has just paid the upgrade, exactly as in the break-even rule.
For the general (non-additive) version, following the envelope can be worse than 2, and the analysis is harder. Deterministic algorithms with constant ratio exist for every instance (Bejerano, Cidon and Naor, 2000; Damaschke, 2003). For randomized algorithms, Lotker, Patt-Shamir and Rawitz (2012) found the best possible randomized strategy for every additive instance, with ratio at most , and an -competitive randomized strategy for general instances.
Ski rental with a prediction
Now suppose a machine-learned model predicts the season length . The prediction might be excellent or useless, and the algorithm does not know which. Two numbers describe an algorithm with predictions (Lykouris and Vassilvitskii, 2018; Purohit, Svitkina and Kumar, 2018):
- consistency: its ratio when the prediction is correct, ;
- robustness: its ratio in the worst case over all and .
Blindly trusting the prediction gives consistency 1 but unbounded robustness (predict "short", and the season never ends). Ignoring it gives consistency and robustness both . Purohit, Svitkina and Kumar interpolate with a trust parameter :
SKI-WITH-PREDICTION(B, y, lambda)
0 if y >= B // prediction says: buying is right
1 buy on the morning of day ceil(lambda * B)
2 else // prediction says: renting is right
3 buy on the morning of day ceil(B / lambda)Theorem (Purohit, Svitkina and Kumar, 2018). This strategy is -consistent and -robust. (In the discrete problem both bounds hold up to rounding terms of order .)
With it is the break-even rule; as it trusts the prediction more and more. The program measures both quantities for by brute force over seasons and predictions.
from math import ceil
def cost(j, B, D):
return D if D < j else (j - 1) + B
def buy_day(B, y, lam):
return ceil(lam * B) if y >= B else ceil(B / lam)
B = 100
seasons = range(1, 4 * B)
print(" lambda consistency 1 + lambda robustness 1 + 1/lambda")
for lam in [1.0, 0.8, 0.5, 0.3, 0.1]:
consistency = max(cost(buy_day(B, D, lam), B, D) / min(D, B) for D in seasons)
robustness = max(cost(buy_day(B, y, lam), B, D) / min(D, B) for D in seasons for y in [1, 4 * B])
print(f"{lam:7.1f} {consistency:11.3f} {1 + lam:10.3f} {robustness:10.3f} {1 + 1 / lam:12.3f}") lambda consistency 1 + lambda robustness 1 + 1/lambda
1.0 1.990 2.000 1.990 2.000
0.8 1.790 1.800 2.240 2.250
0.5 1.490 1.500 2.990 3.000
0.3 1.290 1.300 4.330 4.333
0.1 1.090 1.100 10.900 11.000
Two predictions suffice for the robustness check because the strategy only looks at whether . The measured values sit just below the bounds (the rounding terms). Consistency and robustness trade off: no deterministic algorithm can have both close to 1, and Wei and Zhang (2020) showed that this trade-off curve is the best possible for deterministic algorithms. A randomized version of the same idea achieves consistency and robustness (Purohit, Svitkina and Kumar, 2018), approaching on both sides as .
Between the two extremes, the guarantee degrades smoothly with the prediction error : the deterministic strategy's cost is at most , capped by the robustness bound. This "good when the predictions are good, never terrible" design pattern has since been applied to paging, scheduling, matching and many of the problems in this course.
Test yourself
In additive multislope ski rental, what does the lower-envelope algorithm pay up to time ?
- Exactly
- , the optimum plus the price of the current option
A ski-rental algorithm with predictions has consistency . What does that guarantee?
- A ratio of on every input
- A ratio of at most whenever the prediction is correct
- A ratio of on average
- That the prediction is correct 1.2 times as often
With trust parameter , what are the consistency and robustness bounds of the Purohit-Svitkina-Kumar strategy?
- and
- and
- and
- and