Algorithmcore
Bird's rule
Also called Bird allocation.
Charges each player the cost of the edge by which Prim's algorithm connects it to the source. The charges add up to the MST cost and lie in the core of the spanning tree game.
- Time
- O(n^2) worst
- Space
- O(n) extra
- Where
- n = the number of players
- Model
- Word RAM
- Properties
- deterministicexactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Charles G. Bird, 1976
Bird's rule divides the cost of a network among the users who must connect to a common source. It builds a minimum spanning tree from the source with Prim's algorithm and charges each player the cost of the edge by which the tree reaches it. The charges add up to the cost of the tree, and no group of players pays more than it would pay to build its own network. In the language of cooperative games, the allocation is in the core of the minimum cost spanning tree game. Bird gave the rule and the core result in 1976. This page is the rule as an algorithm, with a full proof; the game itself, its other solutions and its complexity results are on the model page.
In plain words
Several houses must be connected to a power plant. Any two points can be joined by a cable with a known price. The cheapest network that reaches every house is a minimum spanning tree. Build it outward from the plant, one house at a time, always adding the cheapest cable that reaches a new house. Each house pays for the cable that brought the network to it. The payments cover the whole network. No group of houses can complain that it could build its own network to the plant for less than it pays now. The rule is quick to compute and easy to explain, but a house can pay more after a new house joins, so it is not stable under growth.
The problem
The input is a symmetric cost for each pair of vertices of , where vertex 0 is the source and are the players. The game is a cost game: for a coalition , the cost is the cost of a minimum spanning tree of the complete graph on . A coalition may use only its own vertices and the source. The output is an allocation that splits the total cost, , where . The goal is a core allocation: for every coalition , so that no coalition pays more than its stand-alone cost.
The core of a general cost game can be empty, and testing whether a given vector is in the core of this game is coNP-complete (Faigle, Kern, Fekete and Hochstattler 1997). Bird's rule avoids the test: it outputs a vector that is always in the core, in time.
The algorithm
BIRD(c)- 1
for v ← 1 to n: d[v] ← c(0, v); p[v] ← 0 - 2
T ← {0} - 3
repeat n times: - 4
v ← the vertex outside T with the smallest d[v] (smallest index on ties) - 5
x_v ← d[v]; T ← T ∪ {v} - 6
for each w outside T: if c(v, w) < d[w]: d[w] ← c(v, w); p[w] ← v - 7
return x, p
The procedure is Prim's algorithm on the complete graph, started at the source. The array holds, for each vertex that is not yet in the tree, the cost of the cheapest edge from the tree to , and is the tree end of that edge. Line L1 starts with the edges from the source. Line L4 takes the vertex that is cheapest to reach, and line L5 charges it exactly that cost. Line L6 lowers when the new vertex is a cheaper way to reach . When the loop ends, the parent pointers describe the tree, and player pays , the cost of the edge that joins to its parent.
Example
The source is 0 and the players are 1, 2 and 3, with the costs
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 0 | 0 | 4 | 5 | 6 |
| 1 | 4 | 0 | 2 | 5 |
| 2 | 5 | 2 | 0 | 3 |
| 3 | 6 | 5 | 3 | 0 |
The trace shows and after each step.
| step | vertex added | charge | after line L6 | |
|---|---|---|---|---|
| L1 | none | none | 4, 5, 6 | 0, 0, 0 |
| 1 | 1 | done, 2, 5 | 0, 1, 1 | |
| 2 | 2 | done, done, 3 | 0, 1, 2 | |
| 3 | 3 | done, done, done | 0, 1, 2 |
The tree is the path with cost , and Bird's rule gives . The table checks every core inequality.
| coalition | ||
|---|---|---|
| {1} | 4 | 4 |
| {2} | 5 | 2 |
| {3} | 6 | 3 |
| {1, 2} | 6 | 6 |
| {1, 3} | 9 | 7 |
| {2, 3} | 8 | 5 |
| {1, 2, 3} | 9 | 9 |
Player 1 pays its full stand-alone cost, because the tree reaches it first by its own direct edge. Players 2 and 3 pay much less than alone, because they use the edges through player 1. The Shapley value of the same game is : it charges player 1 less and player 3 more, and here it is also in the core.
Correctness
The file proofs/correctness.md gives the full proof. The charges add up to because lines L1 to L6 are Prim's algorithm, so the tree of the parent edges is a minimum spanning tree and each of its edges is charged once.
For the core inequality, fix a coalition and a minimum spanning tree on . The proof matches each player with its own edge of that costs at least . An edge of can be matched with when the parent edge of is on the path from to in . Then by the cycle property of minimum spanning trees: otherwise minus the parent edge of plus would be a cheaper spanning tree. For any set , removing the parent edges of cuts into parts, and each part contains a vertex of . The tree must cross between these parts at least times, and each crossing edge can be matched with some player of . So Hall's condition holds, a perfect matching exists, and .
The proof uses only that is a minimum spanning tree. So the allocation read from any minimum spanning tree is in the core, also when ties make the tree not unique.
Proof: Bird's rule charges the cost of a minimum spanning tree and gives a core allocationfull
Setting. The vertex set is with . The cost is given for every pair of distinct vertices. For a coalition , the cost is the cost of a minimum spanning tree of the complete graph on , with . An allocation is in the core of the cost game if and for every , where .
The output. Lines L1 to L6 are Prim's algorithm from the source 0 on the complete graph on . Line L4 adds the vertex outside the tree with the smallest , and is the cheapest edge from the tree to , by the updates of line L6. So each player enters the tree by the edge , and line L5 sets . Let be the tree with the edges . Every vertex other than 0 has exactly one parent edge, and a parent enters the tree before its child, so is a spanning tree of rooted at 0. Prim's algorithm returns a minimum spanning tree (see Prim's algorithm), so is a minimum spanning tree and
The rest of the proof uses only the fact that is a minimum spanning tree of the complete graph on . So the result holds for every minimum spanning tree, also when ties make it not unique.
Lemma 1 (cycle property). Let be distinct, and let be an edge on the path from to in . Then .
Proof. If is an edge of , the path is this edge and the claim holds. Otherwise remove from . This splits into two components, one with and one with , because is on the only path between them. Adding the edge joins them again, so is a spanning tree. Its cost is , and it is at least because is a minimum spanning tree. So .
Lemma 2. Let be nonempty, and let be a minimum spanning tree on . Let . Call an edge of a witness for the player if is on the path from to in . Then at least edges of are witnesses for some player of .
Proof. Remove the edges , , from . A tree with edges removed has components. Each component contains a vertex of . The component of 0 contains 0. Any other component does not contain the root, so its vertex that is nearest to 0 in has its parent edge removed; therefore .
So the components split into nonempty classes. The tree connects all vertices of . If we contract each class to one point, the edges of still connect the points, so at least edges of join two different classes. Let be such an edge. Then and are in different components of without the edges , , so the path from to in contains a removed edge with . So is a witness for .
Theorem. For every , . Together with , the allocation is in the core.
Proof. For both sides are 0. Let be nonempty, and let be a minimum spanning tree on , so and has edges. Build the bipartite graph with the players of on one side and the edges of on the other side, and join to each edge of that is a witness for . By Lemma 2, every set has at least neighbours. By Hall's theorem, there is a matching that covers . As both sides have elements, the matching is a bijection from to the edges of .
The edge is a witness for , so is on the path from to in . By Lemma 1, . Sum over :
Cost. Line L1 takes time. The loop of line L3 runs times, and lines L4 and L6 scan vertices each, so the time is . The arrays , , and the tree flags take extra space.
Remark. The tests in impl/python/test_bird_rule.py check the sum against Kruskal's algorithm with a union-find, check that the parent edges form a spanning tree, and check for all coalitions of 600 random games with at most 6 players, with integer costs (many ties) and with fractional costs.
Complexity
The loop of line L3 runs times. Lines L4 and L6 each scan at most vertices, so the time is in the word RAM model with costs that fit in a word. The input is a complete cost matrix with entries, so no algorithm can do better in general. The extra space is for , , and the tree flags. On a sparse input graph with edges, where the missing edges have infinite cost, Prim's algorithm with a binary heap gives the same allocation in time.
Properties
- Efficient. The charges add up to exactly , the cost of the cheapest network.
- In the core. No coalition pays more than its stand-alone cost, as proved above. Since every subgame of a minimum cost spanning tree game is again such a game, Bird's rule also shows that every subgame has a nonempty core: the game is totally balanced.
- Not unique. With ties, different minimum spanning trees give different allocations. The code breaks ties by the smallest index.
- Not population monotonic. With , , , , and , the game on players 1 and 2 gives . When player 3 joins, the tree is , and the charges are . Player 2 pays 4 instead of 1, although the new player only adds options. So Bird's rule is not cross-monotonic, and it cannot be used in a Moulin mechanism.
Variants and improvements
- Shapley value. The Shapley value of the game is symmetric and additive, but it needs the costs of exponentially many coalitions, and it can be outside the core. With , , , , and , the Shapley value is , and the coalition pays .
- Folk rule. Bergantinos and Vidal-Puga (2007) studied a rule that is the Shapley value of the irreducible game, where each cost is replaced by the smallest possible largest edge cost on a path from to . It is in the core, it is cost monotonic, and it is population monotonic, which Bird's rule is not.
- Nucleolus. The nucleolus of the game is in the core and is unique, but computing it is NP-hard for this game (Faigle, Kern and Kuipers 1998).
- Steiner networks. If a coalition may also route through the vertices of other players, the game becomes a Steiner tree game. Cost sharing for Steiner trees needs other methods, such as Jain-Vazirani cost sharing, which recovers only part of the cost.
When to use it
Use Bird's rule when a fixed group of users shares the cost of a tree network to a source and the allocation must be in the core: no group of users should be able to leave and build its own network for less. It is a good default when the users and the costs are known and do not change, because it needs only one run of Prim's algorithm. Do not use it when users join and leave over time and each user must never pay more after a new user joins; use the folk rule or another population monotonic rule. Do not use it in a mechanism that asks users for their values, because without cross-monotonicity the Moulin mechanism built on it is not strategyproof.
Pitfalls
- Coalitions that use other players' vertices. The core result is for the game in which a coalition builds a tree on its own vertices and the source. If a coalition may route through outside vertices, its cost can be lower, and the core inequalities change.
- Asymmetric costs. The proof uses . With directed costs the right structure is a minimum arborescence, and the proof does not apply. The code rejects an asymmetric matrix.
- A tree that is not minimum. Charging the edges of any spanning tree adds up to that tree's cost, which can exceed . The proof needs a minimum spanning tree.
- Charging the wrong end of an edge. Each player pays the edge toward the source, its parent edge in the tree rooted at 0. If Prim's algorithm starts at a player, the order in which vertices enter changes, and the edge charged to a vertex may be an edge away from the source. Orient the tree from the source before charging.
- Using the rule in a mechanism. The Moulin mechanism needs cross-monotonic shares. With Bird's shares and the costs of the population monotonicity example, a player with value 2 that bids 4 when players 1 and 3 bid their values 8 and 0 is served at price 1 and gains, while the truthful bid leaves it unserved.
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/bird-rule/. The authors are listed in prov/7MY1TF.jsonl.
"""Bird's rule for minimum cost spanning tree games (Bird 1976).
The input is a symmetric cost matrix c on the vertices 0, 1, ..., n. Vertex 0 is the
source and vertices 1 to n are the players. The rule grows a tree from the source with
Prim's algorithm and charges each player the cost of the edge by which the tree reaches
it. The charges add up to the cost of a minimum spanning tree, and they are in the core
of the game c(S) = cost of a minimum spanning tree on S and the source.
Ties are broken by the smallest vertex index, so the output is deterministic. The time is
O(n^2) and the extra space is O(n).
"""
def _check(cost):
size = len(cost)
if size == 0:
raise ValueError("the cost matrix must contain the source")
for row in cost:
if len(row) != size:
raise ValueError("the cost matrix must be square")
for u in range(size):
for v in range(u + 1, size):
if cost[u][v] != cost[v][u]:
raise ValueError("the cost matrix must be symmetric")
return size - 1
def bird(cost):
"""Return (x, parent): x[v] is the charge of player v and parent[v] the vertex
that connects v in the Prim tree from the source 0. x[0] = 0 and parent[0] = None."""
n = _check(cost)
dist = [None] * (n + 1)
parent = [None] * (n + 1)
for v in range(1, n + 1): # @line L1
dist[v] = cost[0][v]
parent[v] = 0
in_tree = [False] * (n + 1) # @line L2
in_tree[0] = True
x = [0] * (n + 1)
for _ in range(n): # @line L3
v = None
for w in range(1, n + 1): # @line L4
if not in_tree[w] and (v is None or dist[w] < dist[v]):
v = w
x[v] = dist[v] # @line L5
in_tree[v] = True
for w in range(1, n + 1): # @line L6
if not in_tree[w] and cost[v][w] < dist[w]:
dist[w] = cost[v][w]
parent[w] = v
return x, parent # @line L7
def coalition_cost(cost, coalition):
"""c(S): the cost of a minimum spanning tree on S and the source, by Prim's algorithm."""
nodes = [0] + sorted(set(coalition))
best = {v: cost[0][v] for v in nodes[1:]}
total = 0
while best:
v = min(best, key=lambda w: (best[w], w))
total += best.pop(v)
for w in best:
if cost[v][w] < best[w]:
best[w] = cost[v][w]
return total
test_bird_rule.py 116 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bird-rule/. The authors are listed in prov/7MY1TF.jsonl.
"""Tests for bird_rule: the worked example, the core property against a Kruskal oracle,
the spanning tree, and the failure of population monotonicity."""
import itertools
import random
import unittest
from fractions import Fraction as F
from bird_rule import bird, coalition_cost
EXAMPLE = [
[0, 4, 5, 6],
[4, 0, 2, 5],
[5, 2, 0, 3],
[6, 5, 3, 0],
]
NOT_MONOTONE = [
[0, 8, 9, 7],
[8, 0, 1, 8],
[9, 1, 0, 4],
[7, 8, 4, 0],
]
def kruskal(cost, nodes):
"""An independent oracle: Kruskal's algorithm with a union-find on the given nodes."""
nodes = list(nodes)
root = {v: v for v in nodes}
def find(v):
while root[v] != v:
root[v] = root[root[v]]
v = root[v]
return v
total = 0
for w, u, v in sorted((cost[u][v], u, v) for u, v in itertools.combinations(nodes, 2)):
ru, rv = find(u), find(v)
if ru != rv:
root[ru] = rv
total += w
return total
def random_matrix(rng, n, frac=False):
c = [[0] * (n + 1) for _ in range(n + 1)]
for u in range(n + 1):
for v in range(u + 1, n + 1):
w = F(rng.randint(1, 30), rng.randint(1, 4)) if frac else rng.randint(1, 9)
c[u][v] = c[v][u] = w
return c
def bird_on(cost, players):
"""Bird's rule on the subgame of the given players (with the source 0)."""
nodes = [0] + list(players)
sub = [[cost[a][b] for b in nodes] for a in nodes]
x, _ = bird(sub)
return {p: x[k + 1] for k, p in enumerate(players)}
class TestBirdRule(unittest.TestCase):
def test_worked_example(self):
x, parent = bird(EXAMPLE)
self.assertEqual(x, [0, 4, 2, 3])
self.assertEqual(parent, [None, 0, 1, 2])
self.assertEqual(sum(x), 9)
costs = {S: coalition_cost(EXAMPLE, S) for r in range(1, 4) for S in itertools.combinations([1, 2, 3], r)}
self.assertEqual(costs, {(1,): 4, (2,): 5, (3,): 6, (1, 2): 6, (1, 3): 9, (2, 3): 8, (1, 2, 3): 9})
def test_edge_cases(self):
self.assertEqual(bird([[0]]), ([0], [None]))
self.assertEqual(bird([[0, 7], [7, 0]]), ([0, 7], [None, 0]))
x, parent = bird([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
self.assertEqual((x, parent), ([0, 1, 1], [None, 0, 0]))
with self.assertRaises(ValueError):
bird([[0, 1], [2, 0]])
with self.assertRaises(ValueError):
bird([[0, 1], [1]])
with self.assertRaises(ValueError):
bird([])
def test_core_and_tree_on_random_games(self):
rng = random.Random(7)
for trial in range(600):
n = rng.randint(1, 6)
c = random_matrix(rng, n, frac=trial % 3 == 0)
x, parent = bird(c)
players = range(1, n + 1)
self.assertEqual(sum(x), kruskal(c, range(n + 1)))
for v in players:
self.assertEqual(x[v], c[parent[v]][v])
seen, w = set(), v
while w != 0:
self.assertNotIn(w, seen)
seen.add(w)
w = parent[w]
for r in range(1, n + 1):
for S in itertools.combinations(players, r):
cs = kruskal(c, (0,) + S)
self.assertEqual(coalition_cost(c, S), cs)
self.assertLessEqual(sum(x[i] for i in S), cs)
def test_not_population_monotonic(self):
small = bird_on(NOT_MONOTONE, [1, 2])
full = bird_on(NOT_MONOTONE, [1, 2, 3])
self.assertEqual(small, {1: 8, 2: 1})
self.assertEqual(full, {1: 1, 2: 4, 3: 7})
self.assertGreater(full[2], small[2])
if __name__ == "__main__":
unittest.main()
History
Bird (1976) formulated cost allocation for a spanning tree as a cooperative game. He showed that the allocation that charges each player the edge connecting it in a minimum spanning tree is in the core, and he introduced the irreducible core, the core of the game in which every cost is lowered as far as possible without changing the cost of the minimum spanning tree. Later work studied the complexity of the core and the nucleolus of the game (Faigle and coauthors, 1997 and 1998) and rules with stronger monotonicity properties, such as the folk rule of Bergantinos and Vidal-Puga (2007).
References
- On cost allocation for a spanning tree, a game theoretic approach, the minimum cost spanning tree game, the allocation that charges each player the edge that connects it in a minimum spanning tree, the proof that it is in the core, and the irreducible core
- A fair rule in minimum cost spanning tree problems, the folk rule, its characterization by cost monotonicity, population monotonicity and equal share of extra costs, and its relation to Bird's rule and the irreducible game
- On the complexity of testing membership in the core of min-cost spanning tree games, deciding whether a given allocation is in the core is coNP-complete
- Computing the nucleolus of min-cost spanning tree games is NP-hard, the NP-hardness of the nucleolus of the game
- Noam Nisan, Tim Roughgarden, Eva Tardos and Vijay V. Vazirani (eds.), Algorithmic Game Theory, Cambridge University Press, 2007, Chapter 15 (Kamal Jain and Mohammad Mahdian, Cost Sharing), Section 15.2 on the core of cost-sharing games
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 7MY1TF Edit this page History Report an error Markdown