Algorithmadvanced
Hylland-Zeckhauser mechanism
Also called HZ mechanism, pseudo-market for assignment.
Assigns probability shares of objects by a competitive equilibrium with equal budgets over cardinal utilities. Approximate equilibria are PPAD-complete; the exact case is open.
- Solves
- House allocation problem
- Time
- O(g^n n T) worst
- Space
- O(n^2) extra
- Where
- T = the time of one LP solve with at most n^2 variables; g = the number of grid values for one price; n = the number of agents and of objects
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Aanund Hylland, Richard Zeckhauser, 1979
The Hylland-Zeckhauser mechanism solves the house allocation problem with cardinal utilities. Each of agents gets one unit of fake money, and each of objects gets a price. Agents buy probability shares of objects: each agent buys one unit of shares in total, the best bundle it can afford, and among the best bundles the cheapest one. Prices are set so that every object is sold exactly once. This is a competitive equilibrium, and the result is a bistochastic matrix that a Birkhoff-von Neumann decomposition turns into a lottery over matchings. Hylland and Zeckhauser (1979) proved that an equilibrium exists and that its allocation is Pareto efficient, and with equal budgets it is also envy-free. No efficient algorithm is known. Finding an approximate equilibrium is PPAD-complete, and the complexity of the exact problem is open. The code on this page is a toy: it tries the prices on a grid.
In plain words
A school must give rooms to students, one each, and it wants to be fair. It gives each student 1 coin of play money. The rooms get prices, and a student can buy a mix of chances, for example half a chance of room A and half of room C. A popular room gets a high price, so a student who wants it a lot pays for a large chance of it, and a student who cares less takes a sure chance of a cheap room. When the prices are right, all chances of every room are sold. Then the school draws the real rooms by lottery from these chances.
The problem
There are agents and objects, one unit of each. Agent has utility for object , and its expected utility for a row of shares is . A price vector and an allocation , an by matrix with , form an HZ equilibrium when:
- every agent gets one unit, , and every object is sold once, ;
- is in the budget set and maximizes over it;
- among those maximizers, has the least cost .
Condition 3 is needed for efficiency: without it an agent could pay for shares that give it nothing more, and the money would be wasted. Some object must cost at most 1, or the budget sets are empty.
The prices can be normalized. If the smallest price is below 1, then gives the same budget sets, since turns into , and it orders the costs in the same way, so is also an equilibrium. If , then every share bought costs exactly 1, all prices are 1, every agent buys only top objects, and also works. So every equilibrium allocation has prices with smallest entry 0.
The algorithm
HZ-GRID-SEARCH(u, k, pmax)- 1
for each price vector p with entries in {0, 1/k, 2/k, ..., pmax} and smallest entry 0 do - 2
for each agent i do - 3
U_i ← max { u_i · y : y ≥ 0, Σ_j y_j = 1, p · y ≤ 1 } - 4
C_i ← min { p · y : y ≥ 0, Σ_j y_j = 1, p · y ≤ 1, u_i · y = U_i } - 5
find x ≥ 0 with Σ_j x_ij = 1, u_i · x_i = U_i and p · x_i = C_i for each i, and Σ_i x_ij = 1 for each j - 6
if x exists then return (p, x) - 7
return none
This is a toy, not an efficient algorithm. For a fixed price vector, the demand set of agent , the set of rows that satisfy conditions 2 and 3, is the face . Lines L3 and L4 find and with two small linear programs, and line L5 checks with one more linear program whether the demand sets can be chosen so that every object is sold once. The hard part of the problem is to find the prices, and the toy just tries every price on a grid, in lexicographic order.
Example
Same favourite. Two agents both have . With each agent can afford all of object 1, so both demand it and the market does not clear. With an agent can buy at most half of object 1, so each agent buys , which costs 1, and the market clears. The toy tries , and so on, and returns with the uniform matrix. Every agent gets a fair coin flip.
Three identical agents. All three have . They have the same demand set, which is convex, and the rows of an equilibrium allocation average to , so the uniform row is a best bundle. The equilibrium prices are . Check: the bundle costs and has utility . The budget set is a polygon whose corners have at most two nonzero entries. The corner that mixes objects 1 and 3 is , with utility ; the corner that mixes objects 2 and 3 is , also with utility ; object 3 alone has utility 0; and no mix of objects 1 and 2 alone is affordable. So , every best bundle costs 1, and is one of them. With the smallest price 0, these are the only equilibrium prices. The uniform row has no zero entry, so it is a best bundle only if the budget constraint is tight there and with . If , the third entry gives , so is proportional to , and a cost of 1 for the uniform row gives . If or instead, then and the third entry is impossible. The toy finds these prices but returns a vertex of the clearing LP, which is not the uniform matrix.
No conflict. With and , prices work: each agent buys its favourite for free, and the cheapest-bundle rule plays no role.
Correctness
The toy returns only when line L5 finds . Then is bistochastic, and each row is in the budget set, has utility , the largest possible by line L3, and has cost , the least among the bundles with utility by line L4. These are exactly conditions 1 to 3, so every answer is an equilibrium. Conversely, if some equilibrium has its normalized prices on the grid, the toy returns an equilibrium at those prices or at an earlier grid point. If no equilibrium has grid prices, it returns none, even though an equilibrium always exists. The proof file gives the details.
The properties of the equilibrium itself are theorems.
- Existence. Hylland and Zeckhauser (1979) proved that an equilibrium exists for all utilities.
- Pareto efficiency. The allocation is Pareto efficient among all random assignments (ex ante efficient), by a first welfare theorem argument that uses condition 3.
- Envy-freeness. Every bundle costs at most 1, so agent could afford it, and is a best affordable bundle. So , which is envy-freeness in expected utility.
Proof: The grid search returns only Hylland-Zeckhauser equilibria and stopsfull
This proof is about the toy on the page. It shows that every answer of the grid search is an equilibrium, that the search finds one whenever some equilibrium has its normalized prices on the grid, and that it stops. It does not prove that an equilibrium exists, which is the theorem of Hylland and Zeckhauser (1979), and it does not prove Pareto efficiency.
Fix agents and objects and utilities . Let . For prices the budget set is . A pair is an equilibrium when (1) every row is in and every column of sums to 1, (2) and , and (3) for every with .
Claim 1 (the demand values exist). If some price is at most 1, then is a nonempty compact polytope, and the values and exist. Every grid vector of line L1 has a price 0, so lines L3 and L4 are always feasible. Proof. If , the unit vector is in . is a closed subset of the compact set , defined by finitely many linear constraints. A linear function attains its maximum on a nonempty polytope, so exists, and the set of maximizers is a nonempty polytope, on which attains its minimum .
Claim 2 (the demand set is a face). Let . A row satisfies conditions 2 and 3 for agent exactly when . Proof. If satisfies 2 and 3, then , , and is a cheapest maximizer, so . Conversely, let . Then , because is the cost of a point of , so . Its utility is , the maximum, so condition 2 holds. Every maximizer in costs at least , so condition 3 holds.
Claim 3 (soundness). If the search returns , then is an equilibrium. Proof. Line L5 returns with , and for every , and for every . So every row is in , which gives conditions 2 and 3 by Claim 2, and the row and column sums give condition 1.
Claim 4 (normalization). If is an equilibrium, then there is an equilibrium with the same allocation and . Proof. Let . Every row is in , so . If , take . If , let , so and . For we have , because . This map is increasing in and sends 1 to 1, so , and it orders the costs of the bundles in in the same way. So conditions 2 and 3 hold for when they hold for , and condition 1 does not depend on the prices. If , then every row costs at least 1 and at most 1, so only for . Every column sums to 1, so every object has some , and all prices are 1. Then and every bundle costs 1. Take : again and every bundle costs 0, so conditions 2 and 3 hold for the same rows.
Claim 5 (grid completeness). If some equilibrium has and every in , then the search does not return none. Proof. The loop of line L1 reaches unless it returned earlier. At , every row satisfies conditions 2 and 3, so by Claim 2, and is a feasible point of the linear program of line L5. So line L6 returns.
By Claim 4, every equilibrium allocation has a price vector with smallest entry 0, so restricting line L1 to such vectors only loses equilibria whose normalized prices are off the grid. Such equilibria exist: an instance can have only irrational equilibrium prices (Vazirani and Yannakakis 2021). So an answer of none does not mean that no equilibrium exists.
Termination. The grid has vectors, so line L1 runs a finite number of times. Each pass solves linear programs, and the exact simplex method with Bland's rule never repeats a basis, so each one stops. So the search stops.
The checker. The function is_equilibrium computes and by Claim 1 (it first rejects negative prices and price vectors whose smallest entry is above 1, for which is empty), and accepts exactly when every row is in , every column sums to 1, and every row has utility and cost . By Claim 2 this is exactly conditions 1 to 3. All values are exact rationals, so the comparisons are exact.
Envy-freeness of every answer. For an equilibrium and agents , the row is in , so .
Complexity
The toy tries price vectors with , and for each it solves linear programs with at most variables, by an exact simplex method. With the time of one such solve, the total is . That is exponential in , and it is the reason the toy is only for .
No polynomial algorithm is known for the general problem, and none is expected.
- Vazirani and Yannakakis (2021) gave an instance whose only equilibria have irrational prices, so an exact answer cannot be written down in rational numbers. They showed that the exact problem is in FIXP and that finding an approximate equilibrium is in PPAD. For dichotomous and bi-valued utilities they gave polynomial time algorithms.
- Chen, Chen, Peng and Yannakakis (2022) showed that finding an approximate equilibrium is PPAD-hard, even with an inverse polynomial precision and with four distinct utility values. With the membership above, the approximate problem is PPAD-complete.
- The exact problem is open as of the 2022 paper: it is in FIXP, and FIXP-hardness is not known.
The model is the real RAM, since equilibrium prices can be irrational. The toy uses exact rational numbers and therefore only sees rational grid prices.
Properties
- Cardinal. It uses the strength of preferences, not only the order. An agent who cares much more about one object than about the others can buy a larger chance of it, which probabilistic serial and random serial dictatorship cannot express.
- Scale free. If an agent replaces by with , its utility for every unit bundle changes in the same way, so the equilibria do not change.
- Efficient and fair. Ex ante Pareto efficient and envy-free, as above.
- Not strategyproof. An agent can sometimes gain by reporting false utilities, since its report changes the prices.
- Money is fake. The budgets only give each agent equal weight in the market; no real money changes hands.
Variants and improvements
- Unequal budgets. Different budgets give priority to some agents. The envy-freeness argument then holds only among agents with equal budgets.
- More objects and capacities. Objects with several copies, and more objects than agents, fit by changing the column sums to the capacities.
- Fisher markets. In a linear Fisher market agents spend money on goods with no unit demand constraint. That market has a convex program and polynomial algorithms. The unit demand constraint of HZ breaks this structure, and the problem becomes much harder.
- CEEI. Competitive equilibrium from equal incomes is the same idea with real goods, and approximate CEEI is the version for indivisible goods used in course allocation.
When to use it
Use it when agents have cardinal preferences that matter, the market is small or has structure (for example two utility values), and fairness and ex ante efficiency are worth a heavy computation. For large markets, or when only rankings are known, probabilistic serial or random serial dictatorship are simple and fast. Use the toy on this page only to study small examples.
Pitfalls
- Forgetting the cheapest-bundle rule. Without condition 3 the allocation can waste money on worthless shares and lose Pareto efficiency.
- Trusting a grid. A price grid can miss all equilibria, since equilibrium prices can be irrational. A search that finds nothing proves nothing.
- Floating point. The demand sets are faces of polytopes, and a small error in or makes the face empty. Compare exactly, or with care.
- All prices positive. Normalize so that the smallest price is 0. Without it the same allocation appears at many price vectors, and a search wastes time.
- Asymmetric answers. The clearing LP of line L5 returns a vertex, which can be an asymmetric allocation even for identical agents. All such answers are equilibria, but they may look less fair than the symmetric one.
Implementations
The Python version is a toy and says so. It takes the utility matrix and the grid parameters and returns the first price vector on the grid with a clearing allocation, or None. It uses the shared exact LP helper in Fraction for the demand values and the clearing step, and it has an exact equilibrium checker. The tests check the examples above, the checker on wrong prices, the demand values against a search over the corners of the budget set, and on random instances with 2 agents that every answer is an equilibrium, ex ante Pareto efficient by a linear program over all bistochastic matrices, and envy-free. The 3 agent example is checked at its known prices, because the grid search on 3 objects is too slow for a unit test.
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
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Exact linear programming in Fraction, by the two-phase simplex method with Bland's rule.
lp_max(c, A_ub, b_ub, A_eq=None, b_eq=None) maximizes c x subject to A_ub x <= b_ub,
A_eq x = b_eq and x >= 0. lp_min does the same for minimization. Free variables must be
split by the caller (x = x+ - x-). Every input number is converted to Fraction, so the
result is exact: there is no tolerance anywhere.
Both functions return (status, x, value, dual). status is "optimal", "infeasible" or
"unbounded". When status is not "optimal", x, value and dual are None. dual has one entry
per constraint, the A_ub rows first and then the A_eq rows. It is the vector of shadow
prices: the value is sum_i b_i dual_i (strong duality). For lp_max, dual_i >= 0 on the
A_ub rows and A^T dual >= c. For lp_min, dual_i <= 0 on the A_ub rows and A^T dual <= c.
The entries for the A_eq rows have no sign condition.
Bland's rule (the smallest improving column enters, and among the rows with the smallest
ratio the one with the smallest basic variable leaves) makes the method finite on every
input, degenerate inputs included. There is no game algorithm in this module.
"""
from fractions import Fraction
def _frac(v):
return v if isinstance(v, Fraction) else Fraction(v)
def _pivot(T, obj, basis, r, j):
p = T[r][j]
row = [v / p for v in T[r]]
T[r] = row
for k in range(len(T)):
f = T[k][j]
if k != r and f != 0:
T[k] = [a - f * b for a, b in zip(T[k], row)]
f = obj[j]
if f != 0:
obj[:] = [a - f * b for a, b in zip(obj, row)]
basis[r] = j
def _simplex(T, obj, basis, ncols):
"""Maximize. obj[j] is the reduced cost of column j and obj[-1] is minus the value."""
while True:
enter = next((j for j in range(ncols) if obj[j] > 0), None)
if enter is None:
return "optimal"
best = None
for r, row in enumerate(T):
a = row[enter]
if a > 0:
key = (row[-1] / a, basis[r])
if best is None or key < best[0]:
best = (key, r)
if best is None:
return "unbounded"
_pivot(T, obj, basis, best[1], enter)
def _objective_row(cost, T, basis):
obj = list(cost) + [Fraction(0)]
for r, j in enumerate(basis):
f = obj[j]
if f != 0:
obj = [a - f * b for a, b in zip(obj, T[r])]
return obj
def _any_solution(M, rhs, nvars):
"""Return one solution y of M y = rhs (a consistent system), with the free variables 0."""
rows = [list(M[k]) + [rhs[k]] for k in range(len(M))]
pivots = []
r = 0
for col in range(nvars):
p = next((k for k in range(r, len(rows)) if rows[k][col] != 0), None)
if p is None:
continue
rows[r], rows[p] = rows[p], rows[r]
pv = rows[r][col]
rows[r] = [v / pv for v in rows[r]]
for k in range(len(rows)):
f = rows[k][col]
if k != r and f != 0:
rows[k] = [a - f * b for a, b in zip(rows[k], rows[r])]
pivots.append(col)
r += 1
if r == len(rows):
break
y = [Fraction(0)] * nvars
for k, col in enumerate(pivots):
y[col] = rows[k][-1]
return y
def _matrix(A, width, name):
A = [[_frac(v) for v in row] for row in (A or [])]
if any(len(row) != width for row in A):
raise ValueError(name + " must have one column per variable")
return A
def lp_max(c, A_ub, b_ub, A_eq=None, b_eq=None):
"""Maximize c x subject to A_ub x <= b_ub, A_eq x = b_eq and x >= 0, exactly."""
c = [_frac(v) for v in c]
n = len(c)
A_ub = _matrix(A_ub, n, "A_ub")
A_eq = _matrix(A_eq, n, "A_eq")
b_ub = [_frac(v) for v in (b_ub or [])]
b_eq = [_frac(v) for v in (b_eq or [])]
if len(b_ub) != len(A_ub) or len(b_eq) != len(A_eq):
raise ValueError("b_ub and b_eq must have one entry per row")
m1, m2 = len(A_ub), len(A_eq)
m = m1 + m2
width = n + m1
# Rows in the original orientation, with a slack column for each A_ub row.
orig = [A_ub[i] + [Fraction(int(k == i)) for k in range(m1)] for i in range(m1)]
orig += [A_eq[i] + [Fraction(0)] * m1 for i in range(m2)]
rhs = b_ub + b_eq
# A row gets an artificial variable if it is an equation or if its right side is negative.
need = [i >= m1 or rhs[i] < 0 for i in range(m)]
nart = sum(need)
T, basis = [], []
a = 0
for i in range(m):
sign = -1 if rhs[i] < 0 else 1
row = [sign * v for v in orig[i]] + [Fraction(0)] * nart + [sign * rhs[i]]
if need[i]:
row[width + a] = Fraction(1)
basis.append(width + a)
a += 1
else:
basis.append(n + i)
T.append(row)
if nart:
# Phase 1: maximize minus the sum of the artificial variables.
obj = _objective_row([Fraction(0)] * width + [Fraction(-1)] * nart, T, basis)
_simplex(T, obj, basis, width + nart)
if obj[-1] != 0:
return "infeasible", None, None, None
keep = []
for r in range(m):
if basis[r] >= width:
j = next((j for j in range(width) if T[r][j] != 0), None)
if j is None:
continue # the row is a combination of the other rows
_pivot(T, [Fraction(0)] * (width + nart + 1), basis, r, j)
keep.append(r)
T = [T[r][:width] + [T[r][-1]] for r in keep]
basis = [basis[r] for r in keep]
# Phase 2: the original objective, without the artificial columns.
cost = c + [Fraction(0)] * m1
obj = _objective_row(cost, T, basis)
if _simplex(T, obj, basis, width) == "unbounded":
return "unbounded", None, None, None
x = [Fraction(0)] * n
for r, j in enumerate(basis):
if j < n:
x[j] = T[r][-1]
value = sum((ci * xi for ci, xi in zip(c, x)), Fraction(0))
# The dual solves y^T A_B = c_B, where A_B holds the basic columns of the original rows.
M = [[orig[i][j] for i in range(m)] for j in basis]
dual = _any_solution(M, [cost[j] for j in basis], m)
return "optimal", x, value, dual
def lp_min(c, A_ub, b_ub, A_eq=None, b_eq=None):
"""Minimize c x subject to A_ub x <= b_ub, A_eq x = b_eq and x >= 0, exactly."""
status, x, value, dual = lp_max([-_frac(v) for v in c], A_ub, b_ub, A_eq, b_eq)
if status != "optimal":
return status, None, None, None
return status, x, -value, [-v for v in dual]
hylland_zeckhauser_mechanism.py 115 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hylland-zeckhauser-mechanism/. The authors are listed in prov/NMFNPQ.jsonl.
"""A toy Hylland-Zeckhauser solver: exact checks, and a search over a grid of prices.
This is a toy. It is not an efficient algorithm, and none is known: finding an approximate
HZ equilibrium is PPAD-complete. The search tries every price vector on a grid, so its
running time is exponential in the number of objects, and it can miss an equilibrium whose
prices are not on the grid (HZ equilibria can even be irrational). Use it on 2 or 3 objects.
The market has n agents and n objects, one unit of each. Agent i has utility u[i][j] for
object j and a budget of 1. An allocation x is an n by n matrix with x[i][j] the
probability share of object j given to agent i. All arithmetic is exact (Fraction).
"""
from fractions import Fraction
from itertools import product
from typing import Optional, Sequence
from agtlp import lp_max, lp_min
Matrix = list[list[Fraction]]
def demand_values(ui: Sequence[int], p: Sequence[Fraction]) -> tuple[Fraction, Fraction]:
"""Return (U, C): the best utility of a unit bundle with cost at most 1, and the least
cost of a bundle with that utility. Two LPs with m variables."""
m = len(p)
ones = [[1] * m]
st, x, U, _ = lp_max(list(ui), [list(p)], [1], ones, [1]) # @line L3
if st != "optimal":
raise ValueError("no unit bundle is affordable: some price must be at most 1")
st, x, C, _ = lp_min(list(p), [list(p)], [1], ones + [list(ui)], [1, U]) # @line L4
return U, C
def clearing_allocation(u: Sequence[Sequence[int]], p: Sequence[Fraction], vals) -> Optional[Matrix]:
"""Find x with x_i in the demand set of each agent and every object fully assigned, or None.
The demand set of agent i is {x_i >= 0 : sum_j x_ij = 1, u_i x_i = U_i, p x_i = C_i}."""
n = len(u)
nv = n * n
A_eq, b_eq = [], []
def row():
return [0] * nv
for i in range(n):
r = row()
for j in range(n):
r[i * n + j] = 1
A_eq.append(r)
b_eq.append(1)
r = row()
for j in range(n):
r[i * n + j] = u[i][j]
A_eq.append(r)
b_eq.append(vals[i][0])
r = row()
for j in range(n):
r[i * n + j] = p[j]
A_eq.append(r)
b_eq.append(vals[i][1])
for j in range(n):
r = row()
for i in range(n):
r[i * n + j] = 1
A_eq.append(r)
b_eq.append(1)
st, x, _, _ = lp_max([0] * nv, [], [], A_eq, b_eq)
if st != "optimal":
return None
return [[x[i * n + j] for j in range(n)] for i in range(n)]
def hz_grid_search(
u: Sequence[Sequence[int]], k: int = 5, pmax: int = 2
) -> Optional[tuple[list[Fraction], Matrix]]:
"""Try the price vectors with entries in {0, 1/k, ..., pmax} and smallest entry 0, in
lexicographic order, and return the first (p, x) that is an HZ equilibrium, or None.
(k * pmax + 1)^n price vectors, each costing 2n + 1 small LPs: exponential in n."""
n = len(u)
if any(len(row) != n for row in u):
raise ValueError("the toy needs n agents and n objects")
grid = [Fraction(t, k) for t in range(k * pmax + 1)]
for p in product(grid, repeat=n): # @line L1
if min(p) != 0:
continue
vals = []
for i in range(n): # @line L2
vals.append(demand_values(u[i], p))
x = clearing_allocation(u, p, vals) # @line L5
if x is not None: # @line L6
return list(p), x
return None # @line L7
def is_equilibrium(u: Sequence[Sequence[int]], p: Sequence[Fraction], x: Matrix) -> bool:
"""Exact check that (p, x) is an HZ equilibrium with budgets 1."""
n = len(u)
p = [Fraction(v) for v in p]
if any(v < 0 for v in p) or min(p) > 1:
return False
for j in range(n):
if sum(x[i][j] for i in range(n)) != 1:
return False
for i in range(n):
if any(v < 0 for v in x[i]) or sum(x[i]) != 1:
return False
U, C = demand_values(u[i], p)
util = sum(a * b for a, b in zip(u[i], x[i]))
cost = sum(a * b for a, b in zip(p, x[i]))
if util != U or cost != C:
return False
return True
test_hylland_zeckhauser_mechanism.py 121 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hylland-zeckhauser-mechanism/. The authors are listed in prov/NMFNPQ.jsonl.
import random
import unittest
from fractions import Fraction as F
from agtlp import lp_max
from hylland_zeckhauser_mechanism import clearing_allocation, demand_values, hz_grid_search, is_equilibrium
def utility(ui, xi):
return sum(a * b for a, b in zip(ui, xi))
def best_by_vertices(ui, p):
"""Best utility of a unit bundle with cost <= 1, by trying the vertices of the polytope."""
m = len(p)
best = None
for j in range(m):
if p[j] <= 1:
best = ui[j] if best is None else max(best, ui[j])
for k in range(m):
if p[j] < 1 < p[k]:
t = (p[k] - 1) / (p[k] - p[j])
v = t * ui[j] + (1 - t) * ui[k]
best = v if best is None else max(best, v)
return best
def ex_ante_pareto_optimal(u, x):
"""LP check: no fractional allocation gives every agent as much and the total more."""
n = len(u)
nv = n * n
A_eq, b_eq, A_ub, b_ub = [], [], [], []
for i in range(n):
A_eq.append([1 if v // n == i else 0 for v in range(nv)])
b_eq.append(1)
for j in range(n):
A_eq.append([1 if v % n == j else 0 for v in range(nv)])
b_eq.append(1)
for i in range(n):
A_ub.append([-u[i][v % n] if v // n == i else 0 for v in range(nv)])
b_ub.append(-utility(u[i], x[i]))
c = [u[v // n][v % n] for v in range(nv)]
st, _, value, _ = lp_max(c, A_ub, b_ub, A_eq, b_eq)
return st == "optimal" and value == sum(utility(u[i], x[i]) for i in range(n))
def uniform(n):
return [[F(1, n)] * n for _ in range(n)]
class TestHyllandZeckhauser(unittest.TestCase):
def test_identical_agents(self):
u = [[3, 2, 0]] * 3
p = [F(9, 5), F(6, 5), F(0)]
self.assertTrue(is_equilibrium(u, p, uniform(3)))
vals = [demand_values(u[i], p) for i in range(3)]
self.assertEqual(vals[0], (F(5, 3), F(1)))
x = clearing_allocation(u, p, vals)
self.assertIsNotNone(x)
self.assertTrue(is_equilibrium(u, p, x))
for q in ([F(2), F(1), F(0)], [F(8, 5), F(7, 5), F(0)], [F(9, 5), F(6, 5), F(1, 5)]):
self.assertFalse(is_equilibrium(u, q, uniform(3)))
vals = [demand_values(u[i], q) for i in range(3)]
self.assertIsNone(clearing_allocation(u, q, vals))
def test_same_favourite(self):
u = [[1, 0], [1, 0]]
self.assertEqual(hz_grid_search(u), ([F(2), F(0)], uniform(2)))
self.assertFalse(is_equilibrium(u, [F(1), F(0)], uniform(2)))
self.assertTrue(ex_ante_pareto_optimal(u, uniform(2)))
def test_different_favourites(self):
u = [[2, 1], [1, 2]]
p, x = hz_grid_search(u)
self.assertEqual(p, [F(0), F(0)])
self.assertEqual(x, [[1, 0], [0, 1]])
def test_edge_cases(self):
self.assertEqual(hz_grid_search([[5]]), ([F(0)], [[F(1)]]))
with self.assertRaises(ValueError):
hz_grid_search([[1, 2]])
with self.assertRaises(ValueError):
demand_values([1, 2], [F(2), F(3)])
self.assertFalse(is_equilibrium([[1, 0], [1, 0]], [F(2), F(2)], uniform(2)))
def test_demand_against_vertices(self):
rng = random.Random(6)
for _ in range(150):
m = rng.randint(1, 4)
ui = [rng.randint(0, 6) for _ in range(m)]
p = [F(rng.randint(0, 12), rng.randint(1, 4)) for _ in range(m)]
p[rng.randrange(m)] = F(rng.randint(0, 4), 4) # some price is at most 1
U, C = demand_values(ui, p)
self.assertEqual(U, best_by_vertices(ui, p))
self.assertLessEqual(C, 1)
def test_random_two_agents(self):
rng = random.Random(12)
found = 0
for _ in range(25):
u = [[rng.randint(0, 4) for _ in range(2)] for _ in range(2)]
res = hz_grid_search(u, k=4, pmax=2)
if res is None:
continue
found += 1
p, x = res
self.assertTrue(is_equilibrium(u, p, x))
self.assertTrue(ex_ante_pareto_optimal(u, x))
for i in range(2):
self.assertEqual(utility(u[i], x[i]), demand_values(u[i], p)[0])
self.assertEqual(utility(u[i], x[i]), best_by_vertices(u[i], p))
for k in range(2): # envy-free: every bundle costs at most the budget 1
self.assertGreaterEqual(utility(u[i], x[i]), utility(u[i], x[k]))
self.assertGreaterEqual(found, 20)
if __name__ == "__main__":
unittest.main()
History
Hylland and Zeckhauser (1979) proposed the pseudo-market for assigning individuals to positions, proved that an equilibrium exists and that its allocation is efficient. It was long seen as the ideal mechanism for one-sided matching with cardinal utilities, but too hard to compute. Vazirani and Yannakakis (2021) started its study in computer science, with irrational equilibria, FIXP and PPAD membership, and algorithms for special utilities. Chen, Chen, Peng and Yannakakis (2022) proved that the approximate problem is PPAD-hard.
References
- Aanund Hylland and Richard Zeckhauser, The efficient allocation of individuals to positions, Journal of Political Economy 87(2), 293 to 314 (1979), the pseudo-market with equal budgets, the existence of an equilibrium and its Pareto efficiency
- Vijay V. Vazirani and Mihalis Yannakakis, Computational complexity of the Hylland-Zeckhauser scheme for one-sided matching markets, 12th Innovations in Theoretical Computer Science Conference (ITCS 2021), an instance with only irrational equilibria, membership of the exact problem in FIXP and of the approximate problem in PPAD, and polynomial algorithms for dichotomous and bi-valued utilities
- Thomas Chen, Xi Chen, Binghui Peng and Mihalis Yannakakis, Computational hardness of the Hylland-Zeckhauser scheme, Proceedings of the 2022 ACM-SIAM Symposium on Discrete Algorithms (SODA 2022), PPAD-hardness of finding an approximate equilibrium, also for four-valued utilities
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 NMFNPQ Edit this page History Report an error Markdown