Algorithm Search⌘K

Algorithmintro

Round-robin allocation

Also called round-robin picking sequence.

Agents take turns picking their favourite remaining good. With additive valuations the result is EF1.

Time
O(n m log m) worst
Space
O(n m) extra
Where
m = the number of goods; n = the number of agents
Properties
deterministicofflineiterative

Round-robin allocation divides indivisible goods among nn agents by letting them pick in turn: agent 1, agent 2, up to agent nn, then agent 1 again, and so on, and each agent takes its favourite good among those still free. For additive valuations the result is envy-free up to one good (EF1), and it is computed in O(nmlog⁡m)O(n m \log m) time. It is the draft used to pick players for sports teams. The result need not be Pareto optimal, and it need not be EF1 when valuations are not additive; envy-cycle elimination handles general monotone valuations.

In plain words

Children pick teams in the schoolyard this way. The first child takes the player they like best. The second child takes their own favourite among the players left, and so on. When everybody has had a turn, the first child picks again. This goes on until nobody is left.

Nobody gets a lot more than anybody else. If you pick after me, then in every round I pick before you, so my pick is at least as good for me as yours. If you pick before me, the only head start you have over me is your very first pick. So if I envy you, the envy goes away when I ignore that first pick.

The problem

There are nn agents and mm indivisible goods. Agent ii values good gg at vi(g)≥0v_i(g) \ge 0, and the value of a bundle is the sum of the values of its goods. The goal is an allocation A=(A1,…,An)A = (A_1, \dots, A_n) of all goods that is EF1: for all agents i,ji, j with Aj≠∅A_j \ne \emptyset, some g∈Ajg \in A_j has vi(Ai)≥vi(Aj∖{g})v_i(A_i) \ge v_i(A_j \setminus \{g\}). The agents pick in a fixed order, here 1,2,…,n1, 2, \dots, n.

The algorithm

  1. ROUND-ROBIN(v) ▷ n agents, m goods, additive values v_i(g) ≥ 0
  2. 1for each agent i: L_i ← the goods sorted by v_i decreasing, ties by index; A_i ← ∅
  3. 2R ← all goods; t ← 0
  4. 3while R ≠ ∅ do
  5. 4i ← (t mod n) + 1
  6. 5g ← the first good of L_i that is still in R
  7. 6A_i ← A_i ∪ {g}; R ← R \ {g}
  8. 7t ← t + 1
  9. 8return A

Line L1 fixes each agent's preference list once. Line L4 picks the agent whose turn it is. Line L5 walks along the list of agent ii from where it stopped last time; a good that is not in RR now will never come back, so each list is read once from left to right over the whole run. Lines L6 and L7 record the pick and move to the next turn. Another order of the agents is handled by renaming them.

Example

Three agents value six goods a,…,fa, \dots, f as follows.

aa bb cc dd ee ff
agent 1 8 7 4 3 2 1
agent 2 8 2 6 5 1 3
agent 3 6 7 5 1 4 2

The preference lists of line L1 are a,b,c,d,e,fa, b, c, d, e, f for agent 1, a,c,d,f,b,ea, c, d, f, b, e for agent 2 and b,a,c,e,f,db, a, c, e, f, d for agent 3.

turn tt agent free goods before the pick pick
0 1 a,b,c,d,e,fa, b, c, d, e, f aa
1 2 b,c,d,e,fb, c, d, e, f cc
2 3 b,d,e,fb, d, e, f bb
3 1 d,e,fd, e, f dd
4 2 e,fe, f ff
5 3 ee ee

The output is A1={a,d}A_1 = \{a, d\}, A2={c,f}A_2 = \{c, f\}, A3={b,e}A_3 = \{b, e\}, worth 11, 9 and 11 to their owners. Agent 2 values A1A_1 at 13 and envies agent 1, which picked before it; without aa the bundle is worth 5, so the envy is within EF1. Agent 1, which picks first, envies nobody. Each agent's maximin share is 8 here, so this output also meets every maximin share.

Correctness

Fix two agents ii and jj. Cut the sequence of turns into phases that start at the turns of ii. In each phase, ii picks first, and jj picks at most once, later in the phase; the good of jj was free when ii picked, so ii values its own pick at least as much. If jj comes after ii in the order, every pick of jj lies in some phase, so vi(Ai)≥vi(Aj)v_i(A_i) \ge v_i(A_j). If jj comes before ii, only the first pick g1g_1 of jj lies before the first phase, so vi(Ai)≥vi(Aj∖{g1})v_i(A_i) \ge v_i(A_j \setminus \{g_1\}). Hence the output is EF1. The loop runs mm times, because each turn removes one good from RR. The full proof is in proofs/correctness.md.

Proof: Round-robin allocation is EF1 for additive valuationsfull

Setting. There are n≥1n \ge 1 agents 1,…,n1, \dots, n and a finite set MM of mm goods. Agent ii has an additive valuation with vi(g)≥0v_i(g) \ge 0 for each good gg. We refer to the lines L1 to L8 of the page. A turn is one run of lines L4 to L7, and the turns are numbered t=0,1,…t = 0, 1, \dots as in the algorithm. Agent ii picks at the turns tt with t mod n=i−1t \bmod n = i - 1.

Lemma 1 (termination and output). The loop of line L3 runs exactly mm turns, and the output is an allocation: the bundles are disjoint and their union is MM.

Proof. At the start of a turn R≠∅R \ne \emptyset. Every good not in RR belongs to exactly one bundle and every good of RR belongs to none: this holds after line L2, where R=MR = M and all bundles are empty, and line L6 moves one good from RR to one bundle. Line L5 finds a good, because LiL_i lists all of MM and R≠∅R \ne \emptyset. So each turn removes exactly one good from RR, and the loop stops after mm turns with R=∅R = \emptyset, when every good lies in exactly one bundle. □\square

Lemma 2 (each pick is a best free good). The good gg chosen in line L5 at a turn of agent ii satisfies vi(g)≥vi(h)v_i(g) \ge v_i(h) for every good hh in RR at that moment.

Proof. LiL_i is sorted by viv_i in decreasing order, and gg is the first good of LiL_i that lies in RR. Any h∈Rh \in R appears at or after gg in LiL_i, so vi(h)≤vi(g)v_i(h) \le v_i(g). □\square

Lemma 3 (phases). Fix two different agents ii and jj. Let t1<t2<⋯<tkt_1 < t_2 < \dots < t_k be the turns of agent ii, and set tk+1=mt_{k+1} = m. For 1≤r≤k1 \le r \le k, the phase rr is the set of turns tt with tr≤t<tr+1t_r \le t < t_{r+1}. Then each phase contains at most one turn of jj, and if jj picks the good hh at a turn in phase rr, the good grg_r that ii picks at trt_r has vi(gr)≥vi(h)v_i(g_r) \ge v_i(h).

Proof. The turns of ii are nn apart, so tr+1=tr+nt_{r+1} = t_r + n for r<kr < k, and m−tk≤nm - t_k \le n, since otherwise tk+n<mt_k + n < m would be another turn of ii. So each phase has at most nn consecutive turns, and jj, whose turns are also nn apart, has at most one of them. If jj picks hh at a turn in phase rr, that turn is after trt_r, so hh was in RR at turn trt_r. Lemma 2 gives vi(gr)≥vi(h)v_i(g_r) \ge v_i(h). □\square

Lemma 4 (turns before the first phase). The turns t<t1t < t_1 contain at most one turn of jj, and none if j>ij > i.

Proof. Agent ii has its first turn at t1=i−1t_1 = i - 1, if m≥im \ge i. The turns 0,…,i−20, \dots, i - 2 belong to agents 1,…,i−11, \dots, i - 1, one each. So jj has at most one turn before t1t_1, and none if j>ij > i. If m<im < i, agent ii never picks, all mm turns go to distinct agents 1,…,m1, \dots, m, and jj has at most one turn; it has none if j>i>mj > i > m. □\square

Theorem (EF1). For all agents i≠ji \ne j: if j>ij > i then vi(Ai)≥vi(Aj)v_i(A_i) \ge v_i(A_j); if j<ij < i and Aj≠∅A_j \ne \emptyset, then vi(Ai)≥vi(Aj∖{h1})v_i(A_i) \ge v_i(A_j \setminus \{h_1\}), where h1h_1 is the first good picked by jj. Hence the output is EF1.

Proof. By Lemma 1 every pick of jj is at some turn, either before t1t_1 or in one of the phases. By Lemma 3, the picks of jj inside phases are distinct goods hh paired with distinct goods grg_r of AiA_i (one per phase) with vi(gr)≥vi(h)v_i(g_r) \ge v_i(h). Summing over these pairs and using vi≥0v_i \ge 0 for the goods of AiA_i left unpaired,

vi(Ai)≥∑h picked by j in a phasevi(h).v_i(A_i) \ge \sum_{h \text{ picked by } j \text{ in a phase}} v_i(h).

By Lemma 4, the picks of jj outside the phases are none if j>ij > i, and at most the single good h1h_1 if j<ij < i; if ii has no turn at all, there are no phases and Aj⊆{h1}A_j \subseteq \{h_1\}. In the first case the right side is vi(Aj)v_i(A_j). In the second case it is vi(Aj∖{h1})v_i(A_j \setminus \{h_1\}), by additivity. For the EF1 condition, take g=h1g = h_1 if j<ij < i, and any good of AjA_j if j>ij > i, using vi(Aj∖{g})≤vi(Aj)v_i(A_j \setminus \{g\}) \le v_i(A_j) since values are nonnegative. ■\blacksquare

Complexity

Line L1 sorts nn lists of length mm in O(nmlog⁡m)O(n m \log m) time. Over the whole run, the pointer of each agent in line L5 moves at most mm steps, so lines L3 to L7 take O(nm)O(n m) time in total. The time is O(nmlog⁡m)O(n m \log m) and the extra space is O(nm)O(n m) for the lists.

Properties

  • EF1, with no envy toward later agents. Agent ii does not envy any agent that picks after it, and its envy toward an earlier agent disappears after removing that agent's first pick.
  • Balanced bundle sizes. The sizes differ by at most one.
  • Not Pareto optimal. Two agents value goods g0,…,g3g_0, \dots, g_3 at (4,3,2,1)(4, 3, 2, 1) and (6,3,2,1)(6, 3, 2, 1). Round-robin gives {g0,g2}\{g_0, g_2\} to agent 1 and {g1,g3}\{g_1, g_3\} to agent 2, worth 6 and 4. The allocation {g1,g2,g3}\{g_1, g_2, g_3\} and {g0}\{g_0\} is worth 6 and 6, which is better for agent 2 and no worse for agent 1. Equal bundle sizes block such trades of one good for several.
  • Not strategyproof. Agent 1 values a,b,ca, b, c at 3,2,13, 2, 1 and agent 2 at 1,3,21, 3, 2. Picking sincerely, agent 1 takes aa, agent 2 takes bb and agent 1 gets cc, for a total of 4. If agent 1 takes bb first, agent 2 takes cc and agent 1 still gets aa, for a total of 5. So round-robin is not dominant-strategy incentive compatible.
  • Deterministic, not online. The output depends only on the order and the values, with ties broken by index.

Variants and improvements

  • Picking sequences. Any fixed sequence of agents, such as 1,2,2,11, 2, 2, 1, gives a picking sequence rule; round-robin is the sequence 1,2,…,n1, 2, \dots, n repeated. With at most one good per agent, it is serial dictatorship.
  • Chores. With costs in place of values and each agent taking its least costly chore, the same argument gives EF1 for chores, where the envy disappears after removing one chore from the agent's own bundle.
  • Non-additive valuations. For general monotone valuations, use envy-cycle elimination, which gives EF1.
  • Approximate maximin share. Round-robin also appears as a last step of approximate MMS algorithms, which first remove large goods by fixed rules.

When to use it

Use round-robin when valuations are additive and EF1 is enough, especially when the agents can pick in person, as in a draft, so that only the agents' own choices are needed. When efficiency matters too, use an EF1 and Pareto optimal method such as the Barman-Krishnamurthy-Vaish algorithm or maximum Nash welfare.

Pitfalls

  • Sorting in the loop. Sorting the free goods of RR again at every turn in line L5 costs O(mlog⁡m)O(m \log m) per turn and O(m2log⁡m)O(m^2 \log m) in total. The lists of line L1 are sorted once.
  • Restarting the pointer in line L5. Starting each agent's search at the head of LiL_i in every turn makes the cost of line L5 grow with the number of goods already taken, up to O(m2)O(m^2) in total. The pointer only needs to move forward.
  • Using it for non-additive valuations. Line L1 ranks single goods, and the EF1 proof compares single goods, which is valid only for additive valuations. With a coverage valuation, an agent can lose EF1: agent BB values a set of coloured goods by the colours it covers, with weights red 2, blue 2 and green 1, and goods 0,…,40, \dots, 4 are red, blue, green, blue and blue; agent AA is additive with values 5,1,4,2,35, 1, 4, 2, 3. Round-robin with AA first gives AA the goods 0,2,40, 2, 4 and BB the goods 1,31, 3, worth 2 to BB, while {0,2,4}\{0, 2, 4\} minus any one good is still worth at least 3 to BB.
  • Forgetting ties. Line L1 must break ties by a fixed rule, here the good index, so that the output is reproducible; the EF1 proof holds for any tie rule.

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.

round_robin_allocation.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/round-robin-allocation/. The authors are listed in prov/MZAAJ5.jsonl.

from typing import Optional, Sequence


def round_robin(values: Sequence[Sequence], order: Optional[Sequence[int]] = None) -> list[list[int]]:
    """Round-robin allocation of m indivisible goods to n agents.

    values[i][g] is the nonnegative additive value of agent i for good g,
    with goods 0..m-1. order is the picking order, a permutation of the
    agents (default 0, 1, ..., n-1). The agents pick in this order, again
    and again, and each pick takes the most valuable free good of the agent;
    ties go to the smallest good index. Returns the bundles, each a list of
    goods in the order of the picks.

    Cost: O(n m log m) time for the n sorts, then O(n m) for the picks,
    because each pointer of an agent only moves forward. Extra space O(n m).
    """
    n = len(values)
    if n == 0:
        raise ValueError("at least one agent is needed")
    m = len(values[0])
    if any(len(row) != m for row in values):
        raise ValueError("every agent needs a value for every good")
    if any(x < 0 for row in values for x in row):
        raise ValueError("values must be nonnegative")
    order = list(range(n)) if order is None else list(order)
    if sorted(order) != list(range(n)):
        raise ValueError("order must be a permutation of the agents")
    prefs = [sorted(range(m), key=lambda g, i=i: (-values[i][g], g)) for i in range(n)]  # @line L1
    bundles: list[list[int]] = [[] for _ in range(n)]
    free = [True] * m  # @line L2
    pointer = [0] * n
    t = 0
    left = m
    while left > 0:  # @line L3
        i = order[t % n]  # @line L4
        while not free[prefs[i][pointer[i]]]:  # @line L5
            pointer[i] += 1
        g = prefs[i][pointer[i]]
        bundles[i].append(g)  # @line L6
        free[g] = False
        left -= 1
        t += 1  # @line L7
    return bundles  # @line L8
test_round_robin_allocation.py 143 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/round-robin-allocation/. The authors are listed in prov/MZAAJ5.jsonl.

import itertools
import random

import pytest

from round_robin_allocation import round_robin


def value(row, bundle) -> int:
    return sum(row[g] for g in bundle)


def is_ef1(values, bundles) -> bool:
    """EF1 by its definition: try every good of the envied bundle."""
    n = len(values)
    for i in range(n):
        mine = value(values[i], bundles[i])
        for j in range(n):
            if i == j or not bundles[j]:
                continue
            other = value(values[i], bundles[j])
            if not any(mine >= other - values[i][g] for g in bundles[j]):
                return False
    return True


def envies(values, bundles, i, j) -> bool:
    return value(values[i], bundles[j]) > value(values[i], bundles[i])


def pareto_improvement(values, bundles):
    """Brute force over all n^m allocations; returns a dominating one or None."""
    n, m = len(values), len(values[0])
    u = [value(values[i], bundles[i]) for i in range(n)]
    for owner in itertools.product(range(n), repeat=m):
        w = [0] * n
        for g, i in enumerate(owner):
            w[i] += values[i][g]
        if all(w[i] >= u[i] for i in range(n)) and any(w[i] > u[i] for i in range(n)):
            return owner
    return None


def test_worked_example():
    values = [[8, 7, 4, 3, 2, 1], [8, 2, 6, 5, 1, 3], [6, 7, 5, 1, 4, 2]]
    bundles = round_robin(values)
    assert bundles == [[0, 3], [2, 5], [1, 4]]
    assert [value(values[i], bundles[i]) for i in range(3)] == [11, 9, 11]
    assert envies(values, bundles, 1, 0)
    assert value(values[1], [3]) <= 9  # removing good 0 ends the envy
    assert is_ef1(values, bundles)


def test_every_good_is_given_once():
    rng = random.Random(7)
    for _ in range(200):
        n, m = rng.randint(1, 5), rng.randint(0, 9)
        values = [[rng.randint(0, 9) for _ in range(m)] for _ in range(n)]
        bundles = round_robin(values)
        assert sorted(g for b in bundles for g in b) == list(range(m))
        sizes = [len(b) for b in bundles]
        assert max(sizes, default=0) - min(sizes, default=0) <= 1


def test_ef1_random_against_definition():
    rng = random.Random(2024)
    for _ in range(800):
        n, m = rng.randint(2, 4), rng.randint(1, 7)
        values = [[rng.randint(0, 10) for _ in range(m)] for _ in range(n)]
        order = list(range(n))
        rng.shuffle(order)
        bundles = round_robin(values, order)
        assert is_ef1(values, bundles)
        # the first agent to pick envies no one
        first = order[0]
        assert not any(envies(values, bundles, first, j) for j in range(n))


def test_ef1_identical_and_tied_values():
    for n in range(1, 5):
        for m in range(0, 8):
            values = [[1] * m for _ in range(n)]
            assert is_ef1(values, round_robin(values))
            values = [[m - g for g in range(m)] for _ in range(n)]
            assert is_ef1(values, round_robin(values))


def test_not_pareto_optimal():
    values = [[4, 3, 2, 1], [6, 3, 2, 1]]
    bundles = round_robin(values)
    assert bundles == [[0, 2], [1, 3]]
    assert [value(values[i], bundles[i]) for i in range(2)] == [6, 4]
    better = pareto_improvement(values, bundles)
    assert better is not None
    # A takes goods 1, 2, 3 and B takes good 0: (6, 6) dominates (6, 4)
    assert pareto_improvement(values, [[1, 2, 3], [0]]) is None


def greedy_round_robin(vals, m):
    """Round-robin for general valuations: each pick has the largest marginal value."""
    n = len(vals)
    bundles = [frozenset() for _ in range(n)]
    free = set(range(m))
    t = 0
    while free:
        i = t % n
        g = max(sorted(free), key=lambda g: (vals[i](bundles[i] | {g}) - vals[i](bundles[i]), -g))
        bundles[i] = bundles[i] | {g}
        free.remove(g)
        t += 1
    return bundles


def test_fails_for_a_submodular_valuation():
    # Agent B counts colours: red 2, blue 2, green 1. Goods 0..4 are red, blue, green, blue, blue.
    colour = ["red", "blue", "green", "blue", "blue"]
    weight = {"red": 2, "blue": 2, "green": 1}
    a = [5, 1, 4, 2, 3]

    def va(s):
        return sum(a[g] for g in s)

    def vb(s):
        return sum(weight[c] for c in {colour[g] for g in s})

    bundles = greedy_round_robin([va, vb], 5)
    assert bundles == [frozenset({0, 2, 4}), frozenset({1, 3})]
    assert vb(bundles[1]) == 2
    assert all(vb(bundles[0] - {g}) > 2 for g in bundles[0])


def test_bad_input():
    with pytest.raises(ValueError):
        round_robin([])
    with pytest.raises(ValueError):
        round_robin([[1, 2], [3]])
    with pytest.raises(ValueError):
        round_robin([[1, -1]])
    with pytest.raises(ValueError):
        round_robin([[1], [2]], order=[0, 0])

History

Round-robin picking is the draft mechanism of sports leagues. Caragiannis et al. (2019, Section 3) gave the phase argument that it is EF1 for additive valuations and noted that it is not Pareto optimal.

References

  1. Ioannis Caragiannis, David Kurokawa, Herve Moulin, Ariel D. Procaccia, Nisarg Shah and Junxing Wang, The unreasonable fairness of maximum Nash welfare, ACM Transactions on Economics and Computation 7(3) (2019), article 12 (conference version EC 2016), Section 3, the draft mechanism (the EF1 argument by phases and the remark that the result need not be Pareto optimal)

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
  • History with a source
  • at least three sources
  • a scene preset for the example