TExcelTAD
Home › Online Algorithms & Competitive Analysis › Ski Rental Variants: Many Slopes and Predictions

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 0,1,…,m0, 1, \ldots, m. Option ii has a one-time price bib_i and a rental rate rir_i, with

0=b0<b1<⋯<bm,r0>r1>⋯>rm≥0.0 = b_0 < b_1 < \cdots < b_m, \qquad r_0 > r_1 > \cdots > r_m \ge 0 .

At any moment the user may switch to an option with a larger index. In the additive version, moving from option ii to option jj costs bj−bib_j - b_i (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 m=1m = 1, b1=Bb_1 = B, r0=1r_0 = 1, r1=0r_1 = 0. 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 tt, the offline optimum picks one option from the start:

OPT(t)=min⁡i(bi+ri t),\mathrm{OPT}(t) = \min_i \bigl(b_i + r_i\,t\bigr),

the lower envelope of m+1m + 1 lines, a concave, piecewise linear function with OPT(0)=0\mathrm{OPT}(0) = 0.

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: LEA(t)≤2 OPT(t)\mathrm{LEA}(t) \le 2\,\mathrm{OPT}(t) for every tt.

Proof

Let s(u)s(u) be the option on the envelope at time uu; it only increases with uu. LEA pays rent rs(u)r_{s(u)} at time uu, and, because upgrades are additive, its upgrade payments up to time tt add up to exactly bs(t)b_{s(t)}. Since OPT\mathrm{OPT} is concave with slope rs(u)r_{s(u)} at uu and OPT(0)=0\mathrm{OPT}(0) = 0, the rent part equals ∫0trs(u) du=OPT(t)\int_0^t r_{s(u)}\,du = \mathrm{OPT}(t). So

LEA(t)=OPT(t)+bs(t)≤OPT(t)+(bs(t)+rs(t) t)=2 OPT(t).\mathrm{LEA}(t) = \mathrm{OPT}(t) + b_{s(t)} \le \mathrm{OPT}(t) + \bigl(b_{s(t)} + r_{s(t)}\,t\bigr) = 2\,\mathrm{OPT}(t).

For m=1m = 1 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 0.40.4, a purchase at 12) and compares it with the two-option break-even rule that ignores the lease.

python · try it yourself
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 2.72.7 times OPT right after it buys at t=12t = 12, 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.

cpp · try it yourself
#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 ee−1\frac{e}{e-1}, and an ee-competitive randomized strategy for general instances.

Ski rental with a prediction

Now suppose a machine-learned model predicts the season length yy. 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, y=Dy = D;
  • robustness: its ratio in the worst case over all DD and yy.

Blindly trusting the prediction gives consistency 1 but unbounded robustness (predict "short", and the season never ends). Ignoring it gives consistency and robustness both 2−1/B2 - 1/B. Purohit, Svitkina and Kumar interpolate with a trust parameter λ∈(0,1]\lambda \in (0, 1]:

text
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 (1+λ)(1 + \lambda)-consistent and (1+1/λ)(1 + 1/\lambda)-robust. (In the discrete problem both bounds hold up to rounding terms of order 1/B1/B.)

With λ=1\lambda = 1 it is the break-even rule; as λ→0\lambda \to 0 it trusts the prediction more and more. The program measures both quantities for B=100B = 100 by brute force over seasons and predictions.

python · try it yourself
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 y≥By \ge B. 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 λ1−e−λ\frac{\lambda}{1 - e^{-\lambda}} and robustness 11−e−(λ−1/B)\frac{1}{1 - e^{-(\lambda - 1/B)}} (Purohit, Svitkina and Kumar, 2018), approaching ee−1\frac{e}{e-1} on both sides as λ→1\lambda \to 1.

Between the two extremes, the guarantee degrades smoothly with the prediction error η=∣y−D∣\eta = \lvert y - D \rvert: the deterministic strategy's cost is at most (1+λ) OPT+η1−λ(1 + \lambda)\,\mathrm{OPT} + \frac{\eta}{1 - \lambda}, 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 tt?

  1. Exactly OPT(t)\mathrm{OPT}(t)
  2. OPT(t)+bs(t)\mathrm{OPT}(t) + b_{s(t)}, the optimum plus the price of the current option
  3. 2 bm2\,b_m
  4. ∑ibi\sum_i b_i

A ski-rental algorithm with predictions has consistency 1.21.2. What does that guarantee?

  1. A ratio of 1.21.2 on every input
  2. A ratio of at most 1.21.2 whenever the prediction is correct
  3. A ratio of 1.21.2 on average
  4. That the prediction is correct 1.2 times as often

With trust parameter λ=0.25\lambda = 0.25, what are the consistency and robustness bounds of the Purohit-Svitkina-Kumar strategy?

  1. 1.251.25 and 55
  2. 1.251.25 and 1.251.25
  3. 55 and 1.251.25
  4. 22 and 22