Algorithm Search⌘K

Algorithmadvanced

Sequential posted pricing

Also called posted price mechanism, sequential posted price mechanism.

Offers the buyers one at a time a take-it-or-leave-it price. With prices from the ex ante relaxation it earns at least a 1 - 1/e fraction of the optimal revenue for one item.

Time
O(N log N) worst
Space
O(N) extra
Where
N = the total support size of the value distributions; n = the number of buyers
Properties
comparison basedrandomizediterative
Origin
Shuchi Chawla, Jason D. Hartline, David L. Malec, Balasubramanian Sivan, 2010

Sequential posted pricing sells one item to buyers with independent private values by offering them, one at a time, a take-it-or-leave-it price, and the first buyer who accepts gets the item at that price. The prices come from the ex ante relaxation, which bounds the optimal revenue, and are offered in decreasing order. The expected revenue is at least 1−(1−1/n)n≥1−1/e≈0.6321 - (1 - 1/n)^n \ge 1 - 1/e \approx 0.632 times the revenue of Myerson's optimal auction. The prophet inequality is a statement about stopping rules for a sequence of random rewards. This page is about the mechanism: how to choose prices from the value distributions, and why the result is truthful and earns a constant fraction of the optimal revenue.

In plain words

A seller has one item and a list of buyers. Instead of running an auction, the seller visits the buyers one by one and names a price to each. A buyer who likes the price buys and the sale ends. A buyer who does not like it walks away and the seller moves on. Each buyer sees one price and can only say yes or no, so no buyer has a reason to lie or to plan ahead. The seller picks the prices in advance from what it knows about the buyers. It asks how often it would like to sell to each buyer, with the chances adding up to at most one, and turns each chance into a price. Visiting the buyers from the highest price to the lowest loses at most about a third of the best possible revenue.

The problem

There are nn buyers and one item. Buyer ii has a private value viv_i drawn from a known distribution FiF_i, independently of the others, and quasilinear utility. The seller wants a simple truthful mechanism whose expected revenue is close to the optimal revenue OPT\mathrm{OPT} over all BIC and individually rational mechanisms.

For buyer ii the revenue curve maps a sale probability qq to the revenue q⋅Fi−1(1−q)q \cdot F_i^{-1}(1 - q) of the posted price that sells with probability qq. Let Rˉi\bar R_i be its concave hull, which is the best revenue of a random price with sale probability qq (ironing). The ex ante relaxation is

EAR=max⁡{∑iRˉi(qi):∑iqi≤1, qi≥0}.\mathrm{EAR} = \max \Bigl\{ \sum_i \bar R_i(q_i) : \sum_i q_i \le 1,\ q_i \ge 0 \Bigr\}.

Any mechanism sells to buyer ii with some ex ante probability QiQ_i, with ∑iQi≤1\sum_i Q_i \le 1, and earns at most Rˉi(Qi)\bar R_i(Q_i) from it, so OPT≤EAR\mathrm{OPT} \le \mathrm{EAR}.

The algorithm

The implementation takes discrete distributions and computes in exact fractions.

  1. SEQUENTIAL-POSTED-PRICING(F_1, ..., F_n, v_1, ..., v_n)
  2. 1for each buyer i: H_i ← vertices of the concave hull of the revenue curve of F_i, from (0, 0)
  3. 2S ← the hull segments of all buyers with positive slope, sorted by slope, largest first
  4. 3cap ← 1; q_i ← 0 for all i; for each segment (i, length ℓ) in S while cap > 0:
  5. 4t ← min(cap, ℓ); q_i ← q_i + t; cap ← cap - t
  6. 5for each buyer i: lottery_i ← the hull vertex at q_i, or a mix of the two vertices around q_i
  7. 6draw a price P_i from lottery_i for each buyer i
  8. 7for each buyer i in decreasing order of P_i:
  9. 8if v_i ≥ P_i: sell to i at price P_i and stop
  10. 9keep the item

Lines L1 to L5 depend only on the distributions. They solve the relaxation as a fractional knapsack: each hull segment is an item of size ℓ\ell and value density equal to its slope. In line L5, a vertex of Rˉi\bar R_i at (q,sq)(q, s q) means the price ss, and the vertex (0,0)(0, 0) means no offer. If qiq_i lies strictly between vertices with prices sa>sbs_a > s_b and quantiles qa<qbq_a < q_b, the lottery offers sas_a with probability (qb−qi)/(qb−qa)(q_b - q_i)/(q_b - q_a) and sbs_b otherwise. At most one buyer gets such a lottery. Lines L6 to L9 run the mechanism, and a buyer accepts exactly when its value is at least its price.

Example

A discrete instance. Two buyers have values in {2,3,5}\{2, 3, 5\} with probabilities 1/2,1/6,1/31/2, 1/6, 1/3. The revenue curve has the points (0,0)(0, 0), (1/3,5/3)(1/3, 5/3), (1/2,3/2)(1/2, 3/2) and (1,2)(1, 2), and its hull has the vertices (0,0)(0, 0), (1/3,5/3)(1/3, 5/3) and (1,2)(1, 2), with slopes 5 and 1/21/2. The greedy rule takes the slope-5 segment of buyer 1, then that of buyer 2, and then 1/31/3 of the slope-1/21/2 segment of buyer 1. So q1=2/3q_1 = 2/3, q2=1/3q_2 = 1/3 and EAR=5/3+5/3+1/6=7/2\mathrm{EAR} = 5/3 + 5/3 + 1/6 = 7/2. Buyer 2 gets the price 5. Buyer 1 sits halfway between the vertices of prices 5 and 2, so it gets 5 or 2 with probability 1/21/2 each.

  • Prices (5,5)(5, 5): buyer 1 is first by the tie rule, and the revenue is 5⋅1/3+(2/3)⋅5⋅1/3=25/95 \cdot 1/3 + (2/3) \cdot 5 \cdot 1/3 = 25/9.
  • Prices (2,5)(2, 5): buyer 2 is first, and the revenue is 5⋅1/3+(2/3)⋅2=35 \cdot 1/3 + (2/3) \cdot 2 = 3.

The expected revenue is 26/9≈2.8926/9 \approx 2.89. Myerson's optimal auction earns 33 here, and the guarantee is (1−1/4)⋅7/2=21/8(1 - 1/4) \cdot 7/2 = 21/8, so 21/8≤26/9≤3≤7/221/8 \le 26/9 \le 3 \le 7/2.

Uniform values. Two buyers have values uniform on [100,200][100, 200] (Chawla, Hartline, Malec and Sivan 2010, introduction). Here Rˉi(q)=q(200−100q)\bar R_i(q) = q(200 - 100q), and the relaxation sets q1=q2=1/2q_1 = q_2 = 1/2, the price 150 for both, and EAR=150\mathrm{EAR} = 150. Offering 150 to both in turn earns 150⋅(1−1/4)=112.5150 \cdot (1 - 1/4) = 112.5, exactly 3/4=1−(1−1/2)23/4 = 1 - (1 - 1/2)^2 of EAR. The optimal auction is the Vickrey auction here, with revenue E[min⁡(v1,v2)]=400/3≈133.3\mathbb{E}[\min(v_1, v_2)] = 400/3 \approx 133.3. Better prices exist: 150 to the first buyer and then 100 to the second earn 125125.

A tight case. Three buyers have values uniform on {1,2,3}\{1, 2, 3\}. The relaxation gives each buyer the price 3 with qi=1/3q_i = 1/3, and EAR=3\mathrm{EAR} = 3. The mechanism earns 3⋅(1−(2/3)3)=19/93 \cdot (1 - (2/3)^3) = 19/9, which is exactly 1−(1−1/3)31 - (1 - 1/3)^3 times EAR.

Correctness

The proof is in proofs/correctness.md.

  • Truthful and IR. Each buyer faces one price that does not depend on its own value, so accepting exactly when vi≥Piv_i \ge P_i is a dominant strategy, and no buyer pays more than its value.
  • The plan. The greedy rule solves the fractional knapsack over hull segments, so ∑iRˉi(qi)=EAR\sum_i \bar R_i(q_i) = \mathrm{EAR}. Each lottery sells to buyer ii with probability qiq_i and earns Rˉi(qi)\bar R_i(q_i) from it.
  • The guarantee. Write the revenue as ∫0∞Pr⁡[sale price≥t] dt\int_0^\infty \Pr[\text{sale price} \ge t]\, dt. Because prices go in decreasing order, the sale price is at least tt exactly when some buyer with Pi≥tP_i \ge t accepts, and these events are independent. With ai(t)=Pr⁡[Pi≥t,vi≥Pi]a_i(t) = \Pr[P_i \ge t, v_i \ge P_i] and ∑iai(t)≤∑iqi≤1\sum_i a_i(t) \le \sum_i q_i \le 1, the probability is 1−∏i(1−ai(t))≥(1−(1−1/n)n)∑iai(t)1 - \prod_i (1 - a_i(t)) \ge (1 - (1 - 1/n)^n) \sum_i a_i(t), and integrating gives the bound. With OPT≤EAR\mathrm{OPT} \le \mathrm{EAR} the mechanism earns at least (1−1/e) OPT(1 - 1/e)\, \mathrm{OPT}.
Proof: Correctness and the revenue guarantee of sequential posted pricingfull

There are nn bidders with independent values, and bidder ii has a discrete distribution FiF_i. For a price ss in the support of FiF_i write qi(s)=Pr⁡[vi≥s]q_i(s) = \Pr[v_i \ge s]. The revenue curve of bidder ii is the set of points (0,0)(0, 0) and (qi(s),s qi(s))(q_i(s), s\, q_i(s)), and Rˉi\bar R_i is the least concave function on [0,1][0, 1] above these points. The ex ante relaxation is

EAR=max⁡{∑iRˉi(qi):∑iqi≤1, 0≤qi≤1}.\mathrm{EAR} = \max \Bigl\{ \sum_i \bar R_i(q_i) : \sum_i q_i \le 1,\ 0 \le q_i \le 1 \Bigr\}.

Claim 1: lines L1 to L4 solve the ex ante relaxation

Line L1 computes the vertices of each Rˉi\bar R_i by the monotone chain method, as in ironing. The function Rˉi\bar R_i is piecewise linear with nonincreasing slopes, and Rˉi(0)=0\bar R_i(0) = 0. So Rˉi(qi)\bar R_i(q_i) is the largest total of ∑kmiktik\sum_k m_{ik} t_{ik} over amounts 0≤tik≤ℓik0 \le t_{ik} \le \ell_{ik} with ∑ktik=qi\sum_k t_{ik} = q_i, where segment kk of bidder ii has slope mikm_{ik} and length ℓik\ell_{ik}: filling the segments in order of decreasing slope is best, and this order is the order along the hull. Hence EAR is a fractional knapsack problem with capacity 1, items of size ℓik\ell_{ik} and value density mikm_{ik}. Segments with mik≤0m_{ik} \le 0 never help. The greedy rule of lines L2 to L4, which takes the segments in order of decreasing density and cuts the last one, is optimal for the fractional knapsack by the usual exchange argument. Because the slopes of one bidder decrease along its hull, the greedy rule takes the segments of each bidder in their hull order, so the amounts it takes for bidder ii form an initial part of its hull, of total length qiq_i, and their value is Rˉi(qi)\bar R_i(q_i). So line L4 ends with ∑iRˉi(qi)=EAR\sum_i \bar R_i(q_i) = \mathrm{EAR} and ∑iqi≤1\sum_i q_i \le 1.

Claim 2: line L5 gives each bidder a lottery that matches its share

If qiq_i is a vertex (q,R,s)(q, R, s) of Rˉi\bar R_i, the price ss sells with probability qi(s)=qq_i(s) = q and earns sq=Rˉi(qi)s q = \bar R_i(q_i). For the vertex (0,0)(0, 0) the bidder gets no offer, with sale probability and revenue 00. Otherwise qiq_i lies strictly between two consecutive vertices (qa,Ra,sa)(q_a, R_a, s_a) and (qb,Rb,sb)(q_b, R_b, s_b) with qa<qi<qbq_a < q_i < q_b. Line L5 offers sas_a with probability λ=(qb−qi)/(qb−qa)\lambda = (q_b - q_i)/(q_b - q_a) and sbs_b with probability 1−λ1 - \lambda. Then the sale probability is λqa+(1−λ)qb=qi\lambda q_a + (1 - \lambda) q_b = q_i, and the expected revenue is λRa+(1−λ)Rb=Rˉi(qi)\lambda R_a + (1 - \lambda) R_b = \bar R_i(q_i), since Rˉi\bar R_i is linear between the two vertices. In both cases, with PiP_i the random price of bidder ii,

Pr⁡[vi≥Pi]=qi,E[Pi⋅1{vi≥Pi}]=Rˉi(qi).(1)\Pr[v_i \ge P_i] = q_i, \qquad \mathbb{E}\bigl[P_i \cdot \mathbf{1}\{v_i \ge P_i\}\bigr] = \bar R_i(q_i). \tag{1}

Claim 3: the mechanism is truthful and individually rational

Each bidder sees one take-it-or-leave-it price that does not depend on its own value. Accepting gives vi−Piv_i - P_i and declining gives 00, so accepting exactly when vi≥Piv_i \ge P_i is optimal for every value, and no bidder pays more than its value. If the prices were revealed only when offered, the same holds, since the offer to a bidder does not depend on its own behavior. Lines L7 to L9 sell to the first bidder in the order who accepts, so at most one bidder buys.

Claim 4: the revenue is at least (1−(1−1/n)n) EAR≥(1−1/e) EAR(1 - (1 - 1/n)^n)\,\mathrm{EAR} \ge (1 - 1/e)\,\mathrm{EAR}

Let ZZ be the sale price, with Z=0Z = 0 if no one buys. Then E[Z]=∫0∞Pr⁡[Z≥t] dt\mathbb{E}[Z] = \int_0^\infty \Pr[Z \ge t]\, dt. Fix t>0t > 0. Line L7 offers the prices in decreasing order, so all bidders with Pi≥tP_i \ge t get their offers before any bidder with Pi<tP_i < t. Hence Z≥tZ \ge t exactly when some bidder ii has Pi≥tP_i \ge t and vi≥Piv_i \ge P_i. These events are independent across bidders, since the prices are drawn independently and the values are independent. With ai(t)=Pr⁡[Pi≥t, vi≥Pi]a_i(t) = \Pr[P_i \ge t,\ v_i \ge P_i],

Pr⁡[Z≥t]=1−∏i(1−ai(t)).\Pr[Z \ge t] = 1 - \prod_i \bigl(1 - a_i(t)\bigr).

By (1), ai(t)≤qia_i(t) \le q_i, so A(t)=∑iai(t)≤1A(t) = \sum_i a_i(t) \le 1. By the inequality of arithmetic and geometric means, ∏i(1−ai)≤(1−A/n)n\prod_i (1 - a_i) \le (1 - A/n)^n. The function g(A)=1−(1−A/n)ng(A) = 1 - (1 - A/n)^n is concave with g(0)=0g(0) = 0, so g(A)≥A g(1)g(A) \ge A\, g(1) for 0≤A≤10 \le A \le 1. Therefore

E[Z]≥g(1)∫0∞∑iai(t) dt=g(1)∑iE[Pi⋅1{vi≥Pi}]=(1−(1−1n)n) EAR,\mathbb{E}[Z] \ge g(1) \int_0^\infty \sum_i a_i(t)\, dt = g(1) \sum_i \mathbb{E}\bigl[P_i \cdot \mathbf{1}\{v_i \ge P_i\}\bigr] = \Bigl(1 - \bigl(1 - \tfrac1n\bigr)^n\Bigr)\, \mathrm{EAR},

using (1) and Claim 1 in the last step. Finally (1−1/n)n≤e−1(1 - 1/n)^n \le e^{-1} for every n≥1n \ge 1.

Claim 5: no BIC and interim IR mechanism earns more than EAR

Take any single-item mechanism that is BIC and interim IR. Let QiQ_i be the ex ante probability that bidder ii gets the item. Since at most one bidder gets it at each profile, ∑iQi≤1\sum_i Q_i \le 1. Fix bidder ii and let xkx_k and pkp_k be its interim allocation and payment at its value sks_k, as in the proof for Myerson's optimal auction. That proof shows that xx is nondecreasing, that pk≤∑j≤ksj(xj−xj−1)p_k \le \sum_{j \le k} s_j (x_j - x_{j-1}) with x0=0x_0 = 0, and hence that

E[pi]≤∑jsj(xj−xj−1) qi(sj).\mathbb{E}[p_i] \le \sum_j s_j (x_j - x_{j-1})\, q_i(s_j).

The weights wj=xj−xj−1w_j = x_j - x_{j-1} are nonnegative and sum to xK≤1x_K \le 1. The right side is ∑jwj⋅sjqi(sj)\sum_j w_j \cdot s_j q_i(s_j), and the sale probability is Qi=∑kfkxk=∑jwj qi(sj)Q_i = \sum_k f_k x_k = \sum_j w_j\, q_i(s_j). So the pair (Qi,E[pi])(Q_i, \mathbb{E}[p_i]) lies on or below a combination, with total weight at most 1, of the points of the revenue curve, together with (0,0)(0, 0) for the remaining weight. Every such combination lies on or below Rˉi\bar R_i, so E[pi]≤Rˉi(Qi)\mathbb{E}[p_i] \le \bar R_i(Q_i). Summing over ii, the revenue is at most ∑iRˉi(Qi)≤EAR\sum_i \bar R_i(Q_i) \le \mathrm{EAR}.

Together, Claims 4 and 5 show that the mechanism earns at least 1−(1−1/n)n1 - (1 - 1/n)^n, and so at least 1−1/e1 - 1/e, of the optimal revenue.

Running time

Line L1 takes time linear in the support sizes, O(N)O(N) in total for sorted supports, and gives at most NN segments. Line L2 sorts them in O(Nlog⁡N)O(N \log N) and lines L3 and L4 scan them once. Line L5 finds each bidder's position on its hull in O(N)O(N) total. Running the mechanism sorts the nn prices in O(nlog⁡n)O(n \log n) and makes at most nn offers. Only one bidder can end inside a segment, so at most one lottery has two prices, and the exact expected revenue needs at most two orderings, each in O(nlog⁡n+N)O(n \log n + N).

Complexity

The hulls take O(N)O(N) time for sorted supports, sorting the at most NN segments takes O(Nlog⁡N)O(N \log N), and the greedy scan and the lotteries take O(N)O(N). A run of the mechanism sorts nn prices and makes at most nn offers, O(nlog⁡n)O(n \log n). The extra space is O(N)O(N) for the hulls. Since only one buyer can have a two-price lottery, the exact expected revenue needs only two orderings of the prices.

Properties

  • Dominant-strategy truthful and simple. Each buyer makes one yes or no decision and never needs to know the others' values or the prior.
  • Randomized only at one buyer. The plan is deterministic except for at most one buyer, and for continuous regular distributions no randomization is needed at all.
  • Factor depends on nn. The guarantee 1−(1−1/n)n1 - (1 - 1/n)^n is 11 for one buyer, 3/43/4 for two, 19/2719/27 for three, and decreases to 1−1/e1 - 1/e.
  • Not optimal. Myerson's auction earns more in general, as in both examples above.
  • The bound is against EAR. The analysis is tight against EAR (the tight case above), but EAR can be larger than OPT, so the true ratio to OPT can be better.

Variants and improvements

  • Matroid and multi-unit settings. For kk identical items (uniform matroid) and for partition matroids the factor is still e/(e−1)e/(e - 1), and for a general matroid a sequential posted pricing earns half of the optimum (Chawla, Hartline, Malec and Sivan 2010, Table 1).
  • Unit-demand buyers with several items. Chawla, Hartline, Malec and Sivan use sequential posted prices for multi-parameter unit-demand buyers, where the optimal mechanism is not known, and bound their revenue against a single-parameter relaxation.
  • Order not chosen by the seller. In an order-oblivious posted pricing an adversary picks the order of the offers. Prices chosen as in the prophet inequality still give a constant factor, 2 for kk identical items (Chawla, Hartline, Malec and Sivan 2010, Table 1).
  • The best order and prices. Better prices than those of the relaxation can be found by search or dynamic programming over a fixed order, as in the uniform example with 150 and 100.
  • Anonymous prices. One price for all buyers loses more revenue when the buyers differ, but it is the natural choice when the seller cannot treat buyers differently.

When to use it

Use it when an auction is hard to run, for example when the buyers arrive one at a time, or when the seller cannot collect bids from all buyers at once, and the value distributions are known. It also gives a simple benchmark and a building block for multi-parameter settings, where the optimal mechanism is complex. When all bids can be collected and the prior is trusted, Myerson's auction earns more. When the prior is unknown but the buyers are i.i.d., a Vickrey auction with an extra buyer (Bulow-Klemperer theorem) needs no prior at all.

Pitfalls

  • Offer order. The analysis needs the offers in decreasing order of price. In another order, a buyer with a low price can take the item before a buyer who would pay a high price.
  • Irregular distributions. With the raw revenue curve instead of its concave hull, the relaxation is no longer an upper bound on OPT. A sale probability between two hull vertices needs a random price to earn Rˉi(qi)\bar R_i(q_i).
  • Correlated values. The independence of the acceptance events is essential. With correlated values the bound can fail.
  • One offer per buyer. If a buyer who declines could come back later at a lower price, it would wait, and the analysis would fail. Each buyer must get exactly one offer.
  • Floating point. Hull tests and comparisons of slopes decide the plan. With discrete distributions they should be done in exact arithmetic.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

sequential_posted_pricing.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sequential-posted-pricing/. The authors are listed in prov/MES401.jsonl.

"""Sequential posted pricing for one item, with prices from the ex ante relaxation.

A distribution is a list of (value, probability) pairs with distinct values and positive
probabilities that sum to 1, as ints or Fractions. Every computation is exact.

The plan solves the ex ante relaxation: maximize the sum of the concave hulls of the bidders'
revenue curves subject to a total sale probability of at most 1. Each bidder then gets a price
lottery whose sale probability and expected revenue match its share of the relaxation. The
mechanism draws all prices, offers them in decreasing order, and sells to the first bidder who
accepts. Its expected revenue is at least 1 - (1 - 1/n)^n >= 1 - 1/e times the relaxation, which
is at least the optimal revenue.
"""

from fractions import Fraction
from itertools import product
from typing import Sequence

Dist = Sequence[tuple]
NO_OFFER = None  # a price of "infinity": the bidder is not offered the item


def normalize(dist: Dist):
    """Return (values, probs) sorted by value, as Fractions, after checking the input."""
    pairs = sorted((Fraction(v), Fraction(p)) for v, p in dist)
    values = [v for v, _ in pairs]
    probs = [p for _, p in pairs]
    if not pairs or len(set(values)) != len(values):
        raise ValueError("the support must be nonempty with distinct values")
    if any(p <= 0 for p in probs) or sum(probs) != 1:
        raise ValueError("the probabilities must be positive and sum to 1")
    return values, probs


def hull_vertices(dist: Dist):
    """Return the vertices (q, revenue, price) of the concave hull of the revenue curve.

    The first vertex is (0, 0, NO_OFFER). A vertex with price s has q = Pr[v >= s].
    """
    values, probs = normalize(dist)
    pts = [(Fraction(0), Fraction(0), NO_OFFER)]
    q = Fraction(0)
    for s, f in zip(reversed(values), reversed(probs)):
        q += f
        pts.append((q, s * q, s))
    hull = []
    for p in pts:
        while len(hull) >= 2:
            (x1, y1, _), (x2, y2, _) = hull[-2], hull[-1]
            if (y2 - y1) * (p[0] - x1) <= (p[1] - y1) * (x2 - x1):
                hull.pop()
            else:
                break
        hull.append(p)
    return hull


def sale_probability(dist: Dist, price) -> Fraction:
    """Return Pr[v >= price], or 0 for NO_OFFER."""
    if price is NO_OFFER:
        return Fraction(0)
    return sum((Fraction(p) for v, p in dist if Fraction(v) >= price), Fraction(0))


def plan(dists: Sequence[Dist]):
    """Solve the ex ante relaxation and return (relaxation value, lotteries).

    lotteries[i] is a list of (price, probability) pairs; the price may be NO_OFFER.
    """
    hulls = [hull_vertices(d) for d in dists]  # @line L1
    segments = []
    for i, h in enumerate(hulls):
        for k in range(1, len(h)):
            dq, dr = h[k][0] - h[k - 1][0], h[k][1] - h[k - 1][1]
            if dr > 0:
                segments.append((dr / dq, i, k))
    segments.sort(key=lambda t: (-t[0], t[1], t[2]))  # @line L2
    cap = Fraction(1)
    q = [Fraction(0)] * len(dists)
    value = Fraction(0)
    for slope, i, k in segments:  # @line L3
        if cap == 0:
            break
        h = hulls[i]
        take = min(cap, h[k][0] - h[k - 1][0])  # @line L4
        q[i] += take
        value += slope * take
        cap -= take
    lotteries = []
    for i, h in enumerate(hulls):  # @line L5
        k = next(k for k in range(len(h)) if h[k][0] >= q[i])
        if h[k][0] == q[i]:
            lotteries.append([(h[k][2], Fraction(1))])
        else:
            # q[i] lies strictly inside the segment from vertex k - 1 to vertex k
            lam = (h[k][0] - q[i]) / (h[k][0] - h[k - 1][0])
            lotteries.append([(h[k - 1][2], lam), (h[k][2], 1 - lam)])
    return value, lotteries


def offer_order(prices):
    """Return the bidders in decreasing order of price (lower index first on ties), skipping NO_OFFER."""
    live = [i for i, p in enumerate(prices) if p is not NO_OFFER]
    return sorted(live, key=lambda i: (-prices[i], i))


def run(prices, values):
    """Offer the posted prices in decreasing order. Return (buyer, price), or (None, 0)."""
    for i in offer_order(prices):  # @line L7
        if Fraction(values[i]) >= prices[i]:  # @line L8
            return i, prices[i]
    return None, Fraction(0)  # @line L9


def draw_prices(lotteries, rng):
    """Draw one price per bidder from its lottery with a random.Random instance."""
    prices = []
    for lot in lotteries:  # @line L6
        u = Fraction(rng.random())
        acc = Fraction(0)
        chosen = lot[-1][0]
        for price, prob in lot:
            acc += prob
            if u < acc:
                chosen = price
                break
        prices.append(chosen)
    return prices


def expected_revenue(dists: Sequence[Dist], lotteries) -> Fraction:
    """Return the exact expected revenue of the sequential posted pricing with these lotteries."""
    total = Fraction(0)
    for combo in product(*lotteries):
        weight = Fraction(1)
        for _, prob in combo:
            weight *= prob
        prices = [price for price, _ in combo]
        unsold = Fraction(1)
        for i in offer_order(prices):
            a = sale_probability(dists[i], prices[i])
            total += weight * unsold * a * prices[i]
            unsold *= 1 - a
    return total


def sequential_posted_pricing(dists: Sequence[Dist], values, rng):
    """Plan, draw the prices and run the mechanism once. Return (buyer, price)."""
    _, lotteries = plan(dists)
    return run(draw_prices(lotteries, rng), values)
test_sequential_posted_pricing.py 130 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sequential-posted-pricing/. The authors are listed in prov/MES401.jsonl.

import random
import unittest
from fractions import Fraction as F
from itertools import product

from sequential_posted_pricing import (
    NO_OFFER,
    draw_prices,
    expected_revenue,
    hull_vertices,
    plan,
    run,
    sale_probability,
    sequential_posted_pricing,
)

IRREGULAR = [(2, F(1, 2)), (3, F(1, 6)), (5, F(1, 3))]
UNIFORM3 = [(1, F(1, 3)), (2, F(1, 3)), (3, F(1, 3))]


def random_dist(rng, k, denom=6):
    values = sorted(rng.sample(range(1, 10), k))
    cuts = sorted(rng.sample(range(1, denom), k - 1))
    parts = [b - a for a, b in zip([0] + cuts, cuts + [denom])]
    return [(v, F(p, denom)) for v, p in zip(values, parts)]


def ironed(dist):
    """Ironed virtual value of each support value: the hull slope over its quantile interval."""
    h = hull_vertices(dist)
    out = {}
    for v, _ in dist:
        q = sale_probability(dist, F(v))
        j = next(j for j in range(1, len(h)) if h[j - 1][0] < q <= h[j][0])
        out[F(v)] = (h[j][1] - h[j - 1][1]) / (h[j][0] - h[j - 1][0])
    return out


def optimal_revenue(dists):
    """Myerson's optimal revenue E[max(0, max_i ironed phi_i(v_i))], by enumeration."""
    bars = [ironed(d) for d in dists]
    total = F(0)
    for combo in product(*dists):
        p = F(1)
        for _, f in combo:
            p *= f
        total += p * max([F(0)] + [bars[i][F(v)] for i, (v, _) in enumerate(combo)])
    return total


class TestPlan(unittest.TestCase):
    def test_hull(self):
        self.assertEqual(hull_vertices(IRREGULAR), [(0, 0, NO_OFFER), (F(1, 3), F(5, 3), 5), (1, 2, 2)])

    def test_worked_example(self):
        value, lotteries = plan([IRREGULAR, IRREGULAR])
        self.assertEqual(value, F(7, 2))
        self.assertEqual(lotteries, [[(5, F(1, 2)), (2, F(1, 2))], [(5, 1)]])
        self.assertEqual(expected_revenue([IRREGULAR, IRREGULAR], lotteries), F(26, 9))
        self.assertEqual(optimal_revenue([IRREGULAR, IRREGULAR]), 3)

    def test_bound_is_tight_for_equal_prices(self):
        dists = [UNIFORM3] * 3
        value, lotteries = plan(dists)
        self.assertEqual(value, 3)
        self.assertEqual(lotteries, [[(3, 1)]] * 3)
        self.assertEqual(expected_revenue(dists, lotteries), F(19, 9))
        self.assertEqual(F(19, 9) / value, 1 - F(2, 3) ** 3)

    def test_lotteries_match_the_relaxation(self):
        rng = random.Random(1)
        for _ in range(60):
            dists = [random_dist(rng, rng.randint(1, 4)) for _ in range(rng.randint(1, 4))]
            value, lotteries = plan(dists)
            q_total, rev_total = F(0), F(0)
            for d, lot in zip(dists, lotteries):
                self.assertEqual(sum(p for _, p in lot), 1)
                for price, p in lot:
                    a = sale_probability(d, price)
                    q_total += p * a
                    rev_total += p * a * (price if price is not NO_OFFER else 0)
            self.assertLessEqual(q_total, 1)
            self.assertEqual(rev_total, value)

    def test_revenue_bounds(self):
        rng = random.Random(2)
        for _ in range(60):
            n = rng.randint(1, 4)
            dists = [random_dist(rng, rng.randint(1, 3)) for _ in range(n)]
            value, lotteries = plan(dists)
            spm = expected_revenue(dists, lotteries)
            opt = optimal_revenue(dists)
            self.assertGreaterEqual(value, opt)
            self.assertGreaterEqual(opt, spm)
            self.assertGreaterEqual(spm, (1 - (1 - F(1, n)) ** n) * value)


class TestRun(unittest.TestCase):
    def test_decreasing_order(self):
        self.assertEqual(run([F(3), F(5), NO_OFFER], [4, 4, 9]), (0, 3))
        self.assertEqual(run([F(3), F(5), NO_OFFER], [4, 6, 9]), (1, 5))
        self.assertEqual(run([F(3), F(3)], [3, 3]), (0, 3))
        self.assertEqual(run([F(3), F(5)], [2, 4]), (None, 0))

    def test_monte_carlo_matches_exact(self):
        rng = random.Random(3)
        dists = [IRREGULAR, IRREGULAR, UNIFORM3]
        value, lotteries = plan(dists)
        exact = float(expected_revenue(dists, lotteries))
        trials, total = 20000, 0.0
        supports = [([v for v, _ in d], [float(p) for _, p in d]) for d in dists]
        for _ in range(trials):
            values = [rng.choices(s, w)[0] for s, w in supports]
            total += float(run(draw_prices(lotteries, rng), values)[1])
        self.assertAlmostEqual(total / trials, exact, delta=0.06)

    def test_one_shot_and_bad_input(self):
        buyer, price = sequential_posted_pricing([IRREGULAR], [5], random.Random(4))
        self.assertEqual((buyer, price), (0, 2))
        with self.assertRaises(ValueError):
            plan([[(1, F(1, 2))]])
        with self.assertRaises(ValueError):
            plan([[(1, F(1, 2)), (1, F(1, 2))]])


if __name__ == "__main__":
    unittest.main()

History

Posted prices are the oldest selling method, and their revenue for one buyer is the starting point of Myerson's theory. Prophet inequalities, whose single-item form goes back to Krengel, Sucheston and Samuel-Cahn, are statements about stopping rules. Chawla, Hartline, Malec and Sivan (2010) used them to bound the revenue of posted prices. They bounded the optimal revenue by the ex ante relaxation, showed that sequential posted prices approximate it within e/(e−1)e/(e - 1) for one item and for uniform and partition matroids and within 2 for general matroids, and used these single-parameter results to design approximately optimal mechanisms for multi-parameter unit-demand buyers. Posted prices have since become a standard tool for simple and approximately optimal mechanism design.

References

  1. Shuchi Chawla, Jason D. Hartline, David L. Malec and Balasubramanian Sivan, Multi-parameter mechanism design and sequential posted pricing, Proceedings of the 42nd ACM Symposium on Theory of Computing (STOC 2010), 311-320, Lemma 2 (the ex ante upper bound on the optimal revenue), Section 4.2 and Table 1 (the factor e/(e - 1) for uniform and partition matroids, and 2 for general matroids), and the example of two buyers with values uniform on [100, 200] in the introduction
  2. Tim Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016, Lecture 6, Simple near-optimal auctions, Sections 6.2 and 6.3 (the prophet inequality and simple single-item auctions built on it)
  3. Jason D. Hartline, Mechanism Design and Approximation, book draft, version with Chapters 1 to 7 revised in September 2021, https://jasonhartline.com/MDnA/, Chapter 4, Bayesian approximation (the prophet inequality, posted pricings and the ex ante relaxation)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example