Algorithm Search⌘K

Algorithmintro

Last diminisher

Also called Banach-Knaster procedure.

A proportional cake cutting protocol for n agents. A piece passes from agent to agent, each may trim it to value 1/n, and the last agent to trim it takes it.

Time
Θ(n^2) worst · best
Space
Θ(n) extra
Where
n = the number of agents
Properties
deterministicofflineiterative

The last diminisher is a protocol that gives each of nn agents a connected piece of a cake worth at least 1/n1/n to that agent, so it finds a proportional division. In each round, one agent marks a piece worth 1/n1/n to it, and the piece passes to the other remaining agents in turn. An agent that values the piece at more than 1/n1/n trims it to 1/n1/n by its own measure. The last agent to trim the piece takes it and leaves, and the others continue with the rest of the cake. In the Robertson-Webb query model it uses at most n2−1n^2 - 1 queries.

In plain words

A group of friends shares a cake. The first friend cuts a slice from the left end that it thinks is a fair share. The slice then goes around the group. Each friend looks at the slice. If the slice looks too large, the friend makes it smaller, so that it looks exactly fair to that friend. If the slice looks fair or small, the friend lets it pass.

When every friend has seen the slice, the last friend who made it smaller takes it. If nobody made it smaller, the friend who cut it takes it. That friend leaves the group with a fair share. The others think the slice was not too large, so they think enough cake is left for them. They repeat the method on the rest, until one friend remains and takes what is left.

The problem

The cake is [0,1][0, 1]. Agent i∈{1,…,n}i \in \{1, \dots, n\} has a nonnegative, additive and nonatomic valuation ViV_i with Vi([0,1])=1V_i([0, 1]) = 1. The protocol must output disjoint intervals X1,…,XnX_1, \dots, X_n that cover [0,1][0, 1], with Vi(Xi)≥1/nV_i(X_i) \ge 1/n for every ii. It learns the valuations only by queries: Cuti(a,t)\mathrm{Cut}_i(a, t) returns a point x≥ax \ge a with Vi([a,x])=tV_i([a, x]) = t, and Evali(a,b)\mathrm{Eval}_i(a, b) returns Vi([a,b])V_i([a, b]).

The algorithm

The remaining cake is always [a,1][a, 1], and RR is the list of agents that do not have a piece yet, in a fixed order.

  1. LAST-DIMINISHER(n)
  2. 1a ← 0; R ← (1, 2, …, n)
  3. 2while |R| > 1 do
  4. 3h ← the first agent of R; x ← CUT_h(a, 1/n) ▷ h marks [a, x]
  5. 4for each agent j of R after h, in order do
  6. 5if EVAL_j(a, x) > 1/n then ▷ j thinks [a, x] is too large
  7. 6x ← CUT_j(a, 1/n); h ← j ▷ j trims it and becomes the holder
  8. 7give [a, x] to h; remove h from R; a ← x
  9. 8give [a, 1] to the last agent of R

Each trim moves xx to the left, because the agent that trims values [a,x][a, x] at more than 1/n1/n and its new mark has value exactly 1/n1/n. So the piece of a round is never larger than the first mark, and the holder always values [a,x][a, x] at exactly 1/n1/n.

Example

Split [0,1][0, 1] into four equal segments, and let the densities on them be (1,1,1,1)(1, 1, 1, 1) for agent 1, (2,1,1,0)(2, 1, 1, 0) for agent 2 and (3,1,0,0)(3, 1, 0, 0) for agent 3, Each segment has width 1/41/4 and each list sums to 4, so each agent values the whole cake at 1. For example, agent 2 values the first segment at 2/4=1/22/4 = 1/2. Here n=3n = 3 and 1/n=1/31/n = 1/3.

round step query answer holder
1 L3 Cut1(0,1/3)\mathrm{Cut}_1(0, 1/3) x=1/3x = 1/3 1
1 L5 Eval2(0,1/3)\mathrm{Eval}_2(0, 1/3) 7/12>1/37/12 > 1/3
1 L6 Cut2(0,1/3)\mathrm{Cut}_2(0, 1/3) x=1/6x = 1/6 2
1 L5 Eval3(0,1/6)\mathrm{Eval}_3(0, 1/6) 1/2>1/31/2 > 1/3
1 L6 Cut3(0,1/3)\mathrm{Cut}_3(0, 1/3) x=1/9x = 1/9 3
2 L3 Cut1(1/9,1/3)\mathrm{Cut}_1(1/9, 1/3) x=4/9x = 4/9 1
2 L5 Eval2(1/9,4/9)\mathrm{Eval}_2(1/9, 4/9) 17/36>1/317/36 > 1/3
2 L6 Cut2(1/9,1/3)\mathrm{Cut}_2(1/9, 1/3) x=11/36x = 11/36 2

Agent 3 gets [0,1/9][0, 1/9], agent 2 gets [1/9,11/36][1/9, 11/36], and agent 1 gets [11/36,1][11/36, 1]. The values for their owners are 1/31/3, 1/31/3 and 25/3625/36. The run makes 8 queries, which is n2−1n^2 - 1: every agent trims in every round. The result is proportional but not envy-free: agent 3 values the piece of agent 2 at 17/3617/36, and agent 2 values the piece of agent 1 at 4/94/9.

Correctness

Invariant. At the start of each round, every agent ii in RR has Vi([a,1])≥∣R∣/nV_i([a, 1]) \ge |R|/n.

At the start, a=0a = 0 and ∣R∣=n|R| = n, so the invariant holds. In a round, the final holder hh values [a,x][a, x] at exactly 1/n1/n, because xx is its own cut. Every other agent jj in RR values [a,x][a, x] at most 1/n1/n. For an agent after the last trim, line L5 said so. For an agent before the last trim, it valued an earlier, larger piece at most 1/n1/n, or trimmed it to 1/n1/n, and the final piece is a subset of that piece. So Vj([x,1])=Vj([a,1])−Vj([a,x])≥∣R∣/n−1/nV_j([x, 1]) = V_j([a, 1]) - V_j([a, x]) \ge |R|/n - 1/n, which is the invariant for the next round with ∣R∣−1|R| - 1 agents.

Every agent that gets a piece in line L7 gets exactly 1/n1/n. The last agent gets [a,1][a, 1], worth at least 1/n1/n by the invariant with ∣R∣=1|R| = 1. So the division is proportional. The cut queries have answers because each agent in RR values [a,1][a, 1] at least 1/n1/n. The full proof is in proofs/correctness.md.

Proof: The last diminisher is proportional and uses at most n^2 - 1 queriesfull

Setting. The cake is [0,1][0, 1], and agent i∈{1,…,n}i \in \{1, \dots, n\} has a nonnegative, additive and nonatomic valuation ViV_i with Vi([0,1])=1V_i([0, 1]) = 1. For a∈[0,1]a \in [0, 1], the map t↦Vi([a,t])t \mapsto V_i([a, t]) is continuous and nondecreasing on [a,1][a, 1], since ViV_i is nonatomic. So Cuti(a,t)\mathrm{Cut}_i(a, t) has an answer whenever 0≤t≤Vi([a,1])0 \le t \le V_i([a, 1]), and any answer xx has Vi([a,x])=tV_i([a, x]) = t. Single points have value 0, so the end points shared by two pieces do not matter. We refer to the lines L1 to L8 of the page.

Lemma 1 (the piece shrinks). In one round, let x0x_0 be the mark of line L3 and x1,x2,…x_1, x_2, \dots the marks of the later executions of line L6, in order. Then x0≥x1≥x2≥…x_0 \ge x_1 \ge x_2 \ge \dots, and the holder hh at the end of the round has Vh([a,x])=1/nV_h([a, x]) = 1/n for the final mark xx.

Proof. Line L6 runs for agent jj only when line L5 found Vj([a,x])>1/nV_j([a, x]) > 1/n for the current mark xx. The new mark x′x' has Vj([a,x′])=1/n<Vj([a,x])V_j([a, x']) = 1/n < V_j([a, x]). Since t↦Vj([a,t])t \mapsto V_j([a, t]) is nondecreasing, x′<xx' < x. The holder is always the agent whose cut gave the current mark, so Vh([a,x])=1/nV_h([a, x]) = 1/n at the end. □\square

Lemma 2 (the others think the piece is not too large). Let xx be the final mark of a round and hh the final holder. Every agent j≠hj \ne h of RR has Vj([a,x])≤1/nV_j([a, x]) \le 1/n.

Proof. Let j≠hj \ne h. If jj is the first agent of RR, it made the mark x0x_0 with Vj([a,x0])=1/nV_j([a, x_0]) = 1/n, and since h≠jh \ne j some later trim happened, so x≤x0x \le x_0 by Lemma 1. If jj comes later, it saw some mark yy in line L5. Either Vj([a,y])≤1/nV_j([a, y]) \le 1/n and it passed, or it trimmed to a mark y′y' with Vj([a,y′])=1/nV_j([a, y']) = 1/n and was holder for a while. All later marks are at most yy (in the first case) or at most y′y' (in the second case), by Lemma 1. So in all cases [a,x][a, x] lies inside an interval [a,z][a, z] with Vj([a,z])≤1/nV_j([a, z]) \le 1/n, and Vj([a,x])≤Vj([a,z])≤1/nV_j([a, x]) \le V_j([a, z]) \le 1/n. □\square

Lemma 3 (invariant). At the test of line L2, every agent i∈Ri \in R has Vi([a,1])≥∣R∣/nV_i([a, 1]) \ge |R|/n.

Proof. By induction on the rounds. The first time, a=0a = 0 and ∣R∣=n|R| = n, and Vi([0,1])=1V_i([0, 1]) = 1. Suppose the invariant holds at the start of a round. All cut queries of the round have answers: each one asks for 1/n≤∣R∣/n≤Vi([a,1])1/n \le |R|/n \le V_i([a, 1]). Let xx be the final mark and hh the holder. For every j∈R∖{h}j \in R \setminus \{h\}, additivity and Lemma 2 give

Vj([x,1])=Vj([a,1])−Vj([a,x])≥∣R∣n−1n=∣R∣−1n.V_j([x, 1]) = V_j([a, 1]) - V_j([a, x]) \ge \frac{|R|}{n} - \frac{1}{n} = \frac{|R| - 1}{n}.

Line L7 sets a←xa \leftarrow x and removes hh, so the invariant holds for the new RR of size ∣R∣−1|R| - 1. □\square

Theorem 1 (proportional). The output is a partition of [0,1][0, 1] into nn intervals, and Vi(Xi)≥1/nV_i(X_i) \ge 1/n for every agent ii.

Proof. Each round removes one agent from RR, so the loop of line L2 runs n−1n - 1 times. The pieces of line L7 are [a0,a1],[a1,a2],…,[an−2,an−1][a_0, a_1], [a_1, a_2], \dots, [a_{n-2}, a_{n-1}] with a0=0a_0 = 0, and line L8 gives [an−1,1][a_{n-1}, 1]. Lemma 1 and the answer of a cut query from aa give ak≤ak+1a_k \le a_{k+1}. So the pieces are intervals that cover [0,1][0, 1] and meet only at end points. Each agent in line L7 gets Vh([a,x])=1/nV_h([a, x]) = 1/n by Lemma 1. The last agent gets Vi([a,1])≥1/nV_i([a, 1]) \ge 1/n by Lemma 3 with ∣R∣=1|R| = 1. □\square

Theorem 2 (safe for an honest agent). Suppose agent ii answers by ViV_i, and every other agent jj answers by some nonnegative, additive and nonatomic valuation WjW_j with Wj([0,1])=1W_j([0, 1]) = 1 of its own choice, not necessarily its true one. Then Vi(Xi)≥1/nV_i(X_i) \ge 1/n.

Proof. Lemma 1 uses only that each agent answers both its queries by one valuation, so it holds for the valuations WjW_j and ViV_i. In Lemma 2 and Lemma 3, take j=ij = i and ii alone: their proofs use Lemma 1 and the answers of agent ii only. They show that, as long as agent ii is in RR, Vi([a,1])≥∣R∣/nV_i([a, 1]) \ge |R|/n. If agent ii gets a piece in line L7, the piece is its own cut, worth 1/n1/n. If it is the last agent, it gets [a,1][a, 1], worth at least 1/n1/n. □\square

Theorem 3 (query count). The protocol makes exactly n(n−1)/2n(n-1)/2 eval queries, between n−1n - 1 and n(n+1)/2−1n(n+1)/2 - 1 cut queries, and at most n2−1n^2 - 1 queries in total.

Proof. The round with ∣R∣=r|R| = r makes one eval query for each of the r−1r - 1 agents after the first (line L5), one cut query in line L3, and at most r−1r - 1 cut queries in line L6. The rounds have r=n,n−1,…,2r = n, n - 1, \dots, 2. So the evals number ∑r=2n(r−1)=n(n−1)/2\sum_{r=2}^{n} (r - 1) = n(n-1)/2, and the cuts number at least n−1n - 1 and at most ∑r=2nr=n(n+1)/2−1\sum_{r=2}^{n} r = n(n+1)/2 - 1. The total is at most n(n−1)/2+n(n+1)/2−1=n2−1n(n-1)/2 + n(n+1)/2 - 1 = n^2 - 1. Line L8 makes no query. ■\blacksquare

Complexity

A round with r=∣R∣r = |R| agents makes r−1r - 1 eval queries (one per agent after the first) and between 1 and rr cut queries. Rounds run for r=n,n−1,…,2r = n, n - 1, \dots, 2. So the protocol makes exactly ∑r=2n(r−1)=n(n−1)/2\sum_{r=2}^{n} (r - 1) = n(n - 1)/2 eval queries, between n−1n - 1 and ∑r=2nr=n(n+1)/2−1\sum_{r=2}^{n} r = n(n + 1)/2 - 1 cut queries, and at most n2−1n^2 - 1 queries in total. Even with no trims it makes n(n−1)/2+n−1n(n - 1)/2 + n - 1 queries, so its cost is Θ(n2)\Theta(n^2) in every case.

The bound n2−1n^2 - 1 is reached: if agent ii puts more weight to the left than every agent before it in the order (for example, density 2i(n−j)2^{i(n - j)} on segment jj of nn equal segments), every agent trims in every round. Extra space is O(n)O(n) for the list RR.

Properties

  • Connected pieces. Each agent gets one interval, and the cake is cut at n−1n - 1 points in the end.
  • Safe for an honest agent. The guarantee of 1/n1/n for agent ii uses only the answers of agent ii. Whatever the other agents answer, an agent that cuts and trims by its true valuation gets at least 1/n1/n.
  • Envy only toward later pieces. An agent jj that gets a piece in round kk was waiting in every round before kk, so it values each earlier piece at most 1/n1/n, and it gets exactly 1/n1/n itself. So no agent envies a piece that was given out before its own. It may envy a later piece, as the example shows.
  • Not equitable and not Pareto optimal in general. In the example the last agent gets 25/3625/36 and the others 1/31/3.
  • Uses eval and cut queries. Unlike the Dubins-Spanier moving knife, it asks waiting agents to evaluate the current piece, and only some of them cut.

Variants and improvements

  • Dubins-Spanier moving knife. A knife moves from aa to the right, and the first agent to call stop takes the piece. With cut queries, every remaining agent marks its 1/n1/n point and the least mark wins. It gives the same kind of allocation with exactly n(n+1)/2−1n(n + 1)/2 - 1 cut queries and no evals.
  • Even-Paz. The Even-Paz algorithm splits the agents into two halves at a median mark and recurses. It uses O(nlog⁡n)O(n \log n) queries, which is optimal by the Edmonds-Pruhs lower bound.
  • Other classic proportional methods. Brams and Taylor describe the lone divider and the lone chooser methods next to the last diminisher. They give the same guarantee of 1/n1/n by other steps.
  • Two agents. For n=2n = 2 the protocol is a form of divide and choose: agent 1 marks its half [0,x][0, x], and agent 2 either lets agent 1 take it or trims it to its own half point and takes the trimmed piece.

When to use it

Use the last diminisher when you want a simple proportional protocol with connected pieces that people can run by hand, one piece at a time. It is easy to explain and each agent can check its own guarantee. For many agents, the Even-Paz algorithm needs far fewer queries. If envy matters, use an envy-free procedure such as Selfridge-Conway for three agents.

Pitfalls

  • Giving the piece to the first trimmer. The piece goes to the last agent that trims it, after all agents of RR have seen it. If it goes to an agent before the others have seen it, a later agent may value it at more than 1/n1/n, and then that agent can be left with less than its share of the rest.
  • Trimming from the wrong end. The trim must keep the left end aa and move the right end xx. If it moves aa, the remaining cake is no longer one interval.
  • Ties. With the strict test of line L5, an agent that values the piece at exactly 1/n1/n lets it pass. A test with ≥\ge also keeps the guarantees, but it adds cut queries and changes who gets the piece.
  • Not envy-free. A proportional result can still leave agents with envy. Do not report it as envy-free for n≥3n \ge 3.

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.

agtcake.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Piecewise-constant cake valuations and a Robertson-Webb query oracle.

The cake is the interval [0, 1]. A valuation is a list of k nonnegative
Fraction densities d[0], ..., d[k - 1]. Density d[j] holds on the segment
[j/k, (j + 1)/k], so that segment has value d[j] / k. A valuation is
normalized when the value of the whole cake is 1, that is, sum(d) = k.

All numbers are Fraction, so every value and every cut point is exact.
This module holds no cake cutting protocol.
"""

from fractions import Fraction
from random import Random
from typing import Optional, Sequence

Valuation = list[Fraction]
Interval = tuple[Fraction, Fraction]

ZERO = Fraction(0)
ONE = Fraction(1)


def normalize(dens: Sequence) -> Valuation:
    """Scale nonnegative densities so that the whole cake has value 1."""
    d = [Fraction(x) for x in dens]
    if not d:
        raise ValueError("a valuation needs at least one segment")
    if any(x < 0 for x in d):
        raise ValueError("densities must be nonnegative")
    total = sum(d)
    if total == 0:
        raise ValueError("densities must not all be zero")
    k = len(d)
    return [x * k / total for x in d]


def _check_point(x: Fraction) -> None:
    if x < 0 or x > 1:
        raise ValueError("a point of the cake must be in [0, 1]")


def value(v: Valuation, a, b) -> Fraction:
    """Return the value of the interval [a, b] under v. Needs 0 <= a <= b <= 1."""
    a, b = Fraction(a), Fraction(b)
    _check_point(a)
    _check_point(b)
    if a > b:
        raise ValueError("value(v, a, b) needs a <= b")
    k = len(v)
    total = ZERO
    j = min(int(a * k), k - 1)
    while j < k:
        lo = Fraction(j, k)
        if lo >= b:
            break
        hi = Fraction(j + 1, k)
        left = a if a > lo else lo
        right = b if b < hi else hi
        if right > left:
            total += v[j] * (right - left)
        j += 1
    return total


def cut(v: Valuation, a, t) -> Optional[Fraction]:
    """Return the least x >= a with value(v, a, x) = t, or None if there is none."""
    a, t = Fraction(a), Fraction(t)
    _check_point(a)
    if t < 0:
        raise ValueError("cut(v, a, t) needs t >= 0")
    if t == 0:
        return a
    k = len(v)
    pos = a
    rest = t
    j = min(int(a * k), k - 1)
    while j < k:
        hi = Fraction(j + 1, k)
        d = v[j]
        if d > 0 and hi > pos:
            here = d * (hi - pos)
            if rest <= here:
                return pos + rest / d
            rest -= here
        if hi > pos:
            pos = hi
        j += 1
    return None


def piece_value(v: Valuation, piece: Sequence[Interval]) -> Fraction:
    """Return the value of a piece, given as a list of intervals (a, b)."""
    return sum((value(v, a, b) for a, b in piece), ZERO)


def random_valuation(rng: Random, k: int, hi: int) -> Valuation:
    """Return a normalized valuation with k segments and integer densities in 0..hi."""
    if k < 1 or hi < 1:
        raise ValueError("random_valuation needs k >= 1 and hi >= 1")
    while True:
        dens = [rng.randint(0, hi) for _ in range(k)]
        if any(dens):
            return normalize(dens)


class Oracle:
    """Answer Robertson-Webb queries for a list of valuations and count them.

    eval_query(i, a, b) returns V_i([a, b]). cut_query(i, a, t) returns the
    least x with V_i([a, x]) = t, or None. The lists evals and cuts hold the
    number of queries of each kind for each agent.
    """

    def __init__(self, valuations: Sequence[Valuation]) -> None:
        self.valuations = [list(v) for v in valuations]
        n = len(self.valuations)
        self.evals = [0] * n
        self.cuts = [0] * n

    @property
    def n(self) -> int:
        return len(self.valuations)

    def eval_query(self, i: int, a, b) -> Fraction:
        self.evals[i] += 1
        return value(self.valuations[i], a, b)

    def cut_query(self, i: int, a, t) -> Optional[Fraction]:
        self.cuts[i] += 1
        return cut(self.valuations[i], a, t)

    def total_evals(self) -> int:
        return sum(self.evals)

    def total_cuts(self) -> int:
        return sum(self.cuts)

    def total(self) -> int:
        return self.total_evals() + self.total_cuts()
last_diminisher.py 34 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/last-diminisher/. The authors are listed in prov/VJGVJA.jsonl.

from fractions import Fraction

from agtcake import Oracle

Piece = list[tuple[Fraction, Fraction]]


def last_diminisher(oracle: Oracle) -> dict[int, Piece]:
    """Banach-Knaster last diminisher for the n agents of the oracle.

    Each agent i gets one interval, worth at least 1/n to it. In each round
    the first remaining agent cuts a piece worth 1/n to it, and each later
    agent trims the piece when it is worth more than 1/n to that agent.
    """
    n = oracle.n
    share = Fraction(1, n)
    alloc: dict[int, Piece] = {}
    a = Fraction(0)  # @line L1
    rest = list(range(n))
    while len(rest) > 1:  # @line L2
        holder = rest[0]  # @line L3
        x = oracle.cut_query(holder, a, share)
        for j in rest[1:]:  # @line L4
            if oracle.eval_query(j, a, x) > share:  # @line L5
                x = oracle.cut_query(j, a, share)  # @line L6
                holder = j
        alloc[holder] = [(a, x)]  # @line L7
        rest.remove(holder)
        a = x
    alloc[rest[0]] = [(a, Fraction(1))]  # @line L8
    return alloc
test_last_diminisher.py 103 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/last-diminisher/. The authors are listed in prov/VJGVJA.jsonl.

import random
from fractions import Fraction

from agtcake import Oracle, normalize, piece_value, random_valuation, value
from last_diminisher import last_diminisher

F = Fraction


def check_partition(alloc, n) -> list:
    """The pieces are single intervals that tile [0, 1] from left to right."""
    assert sorted(alloc) == list(range(n))
    ivs = sorted(alloc[i][0] for i in range(n))
    assert all(len(alloc[i]) == 1 for i in range(n))
    assert ivs[0][0] == 0 and ivs[-1][1] == 1
    for (a1, b1), (a2, b2) in zip(ivs, ivs[1:]):
        assert a1 <= b1 == a2 <= b2
    return ivs


def check_rounds(vals, alloc) -> None:
    """Replay the rounds with the true valuations.

    In each round, the receiver values its piece at exactly 1/n, and every
    agent that is still waiting values that piece at most 1/n.
    """
    n = len(vals)
    share = F(1, n)
    owner = {alloc[i][0]: i for i in range(n)}
    waiting = set(range(n))
    for iv in sorted(owner)[:-1]:
        i = owner[iv]
        assert piece_value(vals[i], [iv]) == share
        for j in waiting - {i}:
            assert piece_value(vals[j], [iv]) <= share
        waiting.remove(i)


def test_example() -> None:
    vals = [normalize([1, 1, 1, 1]), normalize([2, 1, 1, 0]), normalize([3, 1, 0, 0])]
    o = Oracle(vals)
    alloc = last_diminisher(o)
    assert alloc == {2: [(0, F(1, 9))], 1: [(F(1, 9), F(11, 36))], 0: [(F(11, 36), 1)]}
    assert [piece_value(vals[i], alloc[i]) for i in range(3)] == [F(25, 36), F(1, 3), F(1, 3)]
    # agent 3 envies agent 2: proportional, not envy-free
    assert piece_value(vals[2], alloc[1]) == F(17, 36)
    assert o.evals == [0, 2, 1] and o.cuts == [2, 2, 1]
    assert o.total() == 3 * 3 - 1  # every agent trims in every round


def test_identical_valuations() -> None:
    rng = random.Random(3)
    for n in range(1, 6):
        v = random_valuation(rng, 6, 5)
        o = Oracle([v] * n)
        alloc = last_diminisher(o)
        check_partition(alloc, n)
        for i in range(n):
            assert piece_value(v, alloc[i]) == F(1, n)
        assert o.total_cuts() == n - 1  # nobody trims
        assert o.total_evals() == n * (n - 1) // 2


def test_random_valuations() -> None:
    rng = random.Random(2024)
    for _ in range(150):
        n = rng.randint(1, 5)
        vals = [random_valuation(rng, rng.randint(1, 8), 6) for _ in range(n)]
        o = Oracle(vals)
        alloc = last_diminisher(o)
        check_partition(alloc, n)
        check_rounds(vals, alloc)
        for i in range(n):
            assert piece_value(vals[i], alloc[i]) >= F(1, n)
        assert o.total_evals() == n * (n - 1) // 2
        assert n - 1 <= o.total_cuts() <= n * (n + 1) // 2 - 1
        assert o.total() <= n * n - 1 if n > 1 else o.total() == 0


def test_worst_case_reaches_bound() -> None:
    # agent i puts more weight to the left than every agent before it
    for n in range(2, 6):
        vals = [normalize([2 ** (i * (n - j)) for j in range(n)]) for i in range(n)]
        o = Oracle(vals)
        alloc = last_diminisher(o)
        check_partition(alloc, n)
        for i in range(n):
            assert piece_value(vals[i], alloc[i]) >= F(1, n)
        assert o.total() == n * n - 1


def test_two_agents_is_cut_and_trim() -> None:
    rng = random.Random(5)
    for _ in range(50):
        vals = [random_valuation(rng, 5, 4) for _ in range(2)]
        alloc = last_diminisher(Oracle(vals))
        left = min(alloc, key=lambda i: alloc[i][0][0])
        x = alloc[left][0][1]
        assert value(vals[left], 0, x) == F(1, 2)
        assert value(vals[1 - left], 0, x) <= F(1, 2)

History

Steinhaus (1948) described the problem of fair division for nn people and gave this method, which he credited to his colleagues Stefan Banach and Bronislaw Knaster. It is the first protocol for proportional division for every nn. Brams and Taylor (1996) treat it as a classic method for n>2n > 2, and the counts of queries in the Robertson-Webb model were studied later, with the O(nlog⁡n)O(n \log n) method of Even and Paz (1984) and the matching lower bound of Edmonds and Pruhs (2006).

References

  1. Hugo Steinhaus, The problem of fair division, Econometrica 16(1) (1948), 101-104, the method for n people that Steinhaus credits to Banach and Knaster
  2. Steven J. Brams and Alan D. Taylor, Fair Division, From Cake-Cutting to Dispute Resolution, Cambridge University Press, 1996, Chapter 2, Proportionality for n > 2, the divisible case (from p. 30)
  3. Jack Robertson and William Webb, Cake-Cutting Algorithms, Be Fair If You Can, A K Peters, 1998, Chapter 1, Fairly Dividing a Cake
  4. Felix Brandt, Vincent Conitzer, Ulle Endriss, Jerome Lang and Ariel D. Procaccia (eds.), Handbook of Computational Social Choice, Cambridge University Press, 2016, Chapter 13, Ariel D. Procaccia, Cake Cutting Algorithms, Section 13.3, classic algorithms (from p. 313)

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.best
  • 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
  • History with a source
  • a scene preset for the example