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
- Model
- Word RAM
- Properties
- deterministicofflineiterative
- Evidence
- Proof sketchCode in 1 languages
Round-robin allocation divides indivisible goods among agents by letting them pick in turn: agent 1, agent 2, up to agent , 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 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 agents and indivisible goods. Agent values good at , and the value of a bundle is the sum of the values of its goods. The goal is an allocation of all goods that is EF1: for all agents with , some has . The agents pick in a fixed order, here .
The algorithm
ROUND-ROBIN(v) ▷ n agents, m goods, additive values v_i(g) ≥ 0- 1
for each agent i: L_i ← the goods sorted by v_i decreasing, ties by index; A_i ← ∅ - 2
R ← all goods; t ← 0 - 3
while R ≠ ∅ do - 4
i ← (t mod n) + 1 - 5
g ← the first good of L_i that is still in R - 6
A_i ← A_i ∪ {g}; R ← R \ {g} - 7
t ← t + 1 - 8
return 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 from where it stopped last time; a good that is not in 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 as follows.
| 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 for agent 1, for agent 2 and for agent 3.
| turn | agent | free goods before the pick | pick |
|---|---|---|---|
| 0 | 1 | ||
| 1 | 2 | ||
| 2 | 3 | ||
| 3 | 1 | ||
| 4 | 2 | ||
| 5 | 3 |
The output is , , , worth 11, 9 and 11 to their owners. Agent 2 values at 13 and envies agent 1, which picked before it; without 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 and . Cut the sequence of turns into phases that start at the turns of . In each phase, picks first, and picks at most once, later in the phase; the good of was free when picked, so values its own pick at least as much. If comes after in the order, every pick of lies in some phase, so . If comes before , only the first pick of lies before the first phase, so . Hence the output is EF1. The loop runs times, because each turn removes one good from . The full proof is in proofs/correctness.md.
Proof: Round-robin allocation is EF1 for additive valuationsfull
Setting. There are agents and a finite set of goods. Agent has an additive valuation with for each good . 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 as in the algorithm. Agent picks at the turns with .
Lemma 1 (termination and output). The loop of line L3 runs exactly turns, and the output is an allocation: the bundles are disjoint and their union is .
Proof. At the start of a turn . Every good not in belongs to exactly one bundle and every good of belongs to none: this holds after line L2, where and all bundles are empty, and line L6 moves one good from to one bundle. Line L5 finds a good, because lists all of and . So each turn removes exactly one good from , and the loop stops after turns with , when every good lies in exactly one bundle.
Lemma 2 (each pick is a best free good). The good chosen in line L5 at a turn of agent satisfies for every good in at that moment.
Proof. is sorted by in decreasing order, and is the first good of that lies in . Any appears at or after in , so .
Lemma 3 (phases). Fix two different agents and . Let be the turns of agent , and set . For , the phase is the set of turns with . Then each phase contains at most one turn of , and if picks the good at a turn in phase , the good that picks at has .
Proof. The turns of are apart, so for , and , since otherwise would be another turn of . So each phase has at most consecutive turns, and , whose turns are also apart, has at most one of them. If picks at a turn in phase , that turn is after , so was in at turn . Lemma 2 gives .
Lemma 4 (turns before the first phase). The turns contain at most one turn of , and none if .
Proof. Agent has its first turn at , if . The turns belong to agents , one each. So has at most one turn before , and none if . If , agent never picks, all turns go to distinct agents , and has at most one turn; it has none if .
Theorem (EF1). For all agents : if then ; if and , then , where is the first good picked by . Hence the output is EF1.
Proof. By Lemma 1 every pick of is at some turn, either before or in one of the phases. By Lemma 3, the picks of inside phases are distinct goods paired with distinct goods of (one per phase) with . Summing over these pairs and using for the goods of left unpaired,
By Lemma 4, the picks of outside the phases are none if , and at most the single good if ; if has no turn at all, there are no phases and . In the first case the right side is . In the second case it is , by additivity. For the EF1 condition, take if , and any good of if , using since values are nonnegative.
Complexity
Line L1 sorts lists of length in time. Over the whole run, the pointer of each agent in line L5 moves at most steps, so lines L3 to L7 take time in total. The time is and the extra space is for the lists.
Properties
- EF1, with no envy toward later agents. Agent 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 at and . Round-robin gives to agent 1 and to agent 2, worth 6 and 4. The allocation and 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 at and agent 2 at . Picking sincerely, agent 1 takes , agent 2 takes and agent 1 gets , for a total of 4. If agent 1 takes first, agent 2 takes and agent 1 still gets , 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 , gives a picking sequence rule; round-robin is the sequence 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 again at every turn in line L5 costs per turn and 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 in every turn makes the cost of line L5 grow with the number of goods already taken, up to 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 values a set of coloured goods by the colours it covers, with weights red 2, blue 2 and green 1, and goods are red, blue, green, blue and blue; agent is additive with values . Round-robin with first gives the goods and the goods , worth 2 to , while minus any one good is still worth at least 3 to .
- 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.
# 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag MZAAJ5 Edit this page History Report an error Markdown