Algorithmresearch
Orlin's strongly polynomial Fisher market algorithm
Also called Orlin's algorithm for linear Fisher markets.
The first strongly polynomial algorithm for linear Fisher market equilibrium, by scaling and contraction of abundant edges.
- Time
- O(n^2 log n (m + n log n)) worst
- Space
- O(n + m) extra
- Where
- m = the number of pairs of a buyer and a good with positive utility; n = the number of buyers plus the number of goods
- Model
- Real RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- James B. Orlin, 2010
Orlin's algorithm computes the exact equilibrium of a Fisher market with linear utilities in strongly polynomial time: the number of arithmetic operations depends only on the number of buyers, goods and edges, not on the size of the utilities or budgets. It was the first algorithm with this property. It keeps the price raising of the DPSV algorithm, in which prices only go up and money flows only along edges of maximum bang per buck, and replaces the maximum flows with scaling: money moves in units of , and is halved from phase to phase. This scaling algorithm is weakly polynomial. To make it strongly polynomial, Orlin uses abundant edges, edges that carry so much money that they must carry money at the equilibrium, and a procedure that jumps down by a large factor when no new abundant edge is near. The implementation on this page is a toy of the scaling algorithm only.
In plain words
Buyers have money, goods have prices, and each buyer only wants the goods that give her the most pleasure per coin. Start with low prices and nobody owning anything. Hand out money in coins of a fixed size: a buyer with at least one coin left sends it to a good she likes best, maybe pushing another buyer's coin to a different good along the way. If every good she can reach is already paid for, raise the prices of those goods until some good has room again. When no buyer has a full coin left, halve the coin and repeat. Edges that carry many coins can be trusted to be in the final answer. Once those edges fix the prices, check them exactly and stop.
The problem
There is a set of buyers and a set of goods, with one unit of each good, and . Buyer has a budget and utility for all of good , linear in the amount. The edges are the pairs with . Every buyer likes some good and every good is liked by some buyer. Find prices and money flows (the money that buyer spends on good ) such that every buyer spends exactly , only on goods of maximum bang per buck , and every good receives exactly .
Write for the money that buyer has left and for the money that good receives above its price. An equality edge at is an edge with . Let be the starting prices. Following Orlin, is -feasible when for every buyer, for every good with , every is on an equality edge and is a multiple of , and . It is -optimal if also for every buyer.
The algorithm
The residual network has an arc from buyer to good for each equality edge and an arc from good back to buyer when . The pseudocode is the scaling algorithm, which the implementation follows.
ORLIN-SCALING(utilities u, budgets e)- 1
Δ ← max_i e_i / n; p_j ← max_i u_ij e_i / (n Σ_k u_ik) for every good; x ← 0 - 2
loop - 3
while some buyer r has c_r ≥ Δ do - 4
A ← the nodes that r reaches in N(p, x) - 5
if no good j in A has b_j ≤ 0 then multiply the prices of the goods in A by the least q > 1 at which some good of A gets b_j = 0 or a buyer of A gets a new equality edge; go to L4 - 6
send Δ along a path of N(p, x) from r to a good j of A with b_j ≤ 0 - 7
S ← the edges with x_ij ≥ 4nΔ - 8
p' ← the prices that S forces; if p' passes the exact max-flow check, return p' and the flow - 9
Δ ← Δ / 2; for every good with b_j > Δ, lower some positive x_ij by Δ
Lines L4 to L6 are PriceAndAugment. The price increase of line L5 is the one of the DPSV algorithm: the goods that can reach all get dearer by the same factor, so the equality edges among them stay, and the step stops when a good runs out of extra money or a new good becomes reachable. Line L6 adds on the forward arcs of the path and removes on its backward arcs, so only the root and the last good change their totals. Line L9 makes the solution -feasible for the next phase.
Line L8 is the stopping test. A set of edges forces prices when it touches every node: along the edges of each buyer the bang per buck is equal, which fixes the price ratios on each connected part, and the prices of each part add up to the budgets of its buyers. The implementation computes these prices in exact rationals and accepts them only if a maximum flow on the equality edges spends every budget, as on the Eisenberg-Gale program page. Orlin perturbs the utilities so that the equilibrium allocation is unique and its edges form a forest; the toy does not perturb, which is why it checks.
The strongly polynomial algorithm. An edge is abundant if at the start of the phase. In one phase, each changes by , and halves from phase to phase, so an abundant edge stays abundant in all later phases (Lemma 3.4 of the Dagstuhl version) and carries money at the equilibrium. With perturbed utilities, there are at most abundant edges. The scaling algorithm alone can need many phases between two new abundant edges. Orlin's procedure MakeFertile detects this case from the components of the abundant edges and their surplus, and jumps to a new and new prices from which a new abundant edge appears within phases. This gives phases with calls of PriceAndAugment each. The toy leaves MakeFertile out.
Example
Three buyers and three goods, , , , budgets , so . Line L1 gives and . The money flows reach their final values in the second phase; after that only the prices move toward the equilibrium , and line L8 waits until the edges with force the right prices.
| at the end of the phase | prices | buyer 3 spends on goods 1, 2, 3 | edges with | line L8 |
|---|---|---|---|---|
| none | no prices | |||
| none | no prices | |||
| none | no prices | |||
| no prices | ||||
| , rejected | ||||
| , rejected | ||||
| all five edges | , accepted |
In all phases buyer 1 spends on good 2 and buyer 2 spends on good 1. At , the three edges form three parts with one buyer each, which force the prices ; at these prices buyer 3 gets per unit of money from good 3 but from goods 1 and 2, so the check fails. At the edges and carry , all five edges form one part, and they force , which the check accepts. For the market , with budgets , the phases end with prices , and , and the last one returns .
Correctness
The proof for the toy is in proofs/correctness.md. Line L5 and line L6 keep -feasibility, and line L9 turns a -optimal solution into a -feasible one. Each call of PriceAndAugment ends, because every price step either ends it or makes a new good reachable, and each call lowers the money left with the buyers by , so each phase ends. Prices only rise and stay bounded, and the money flows change by at most per phase, so both converge, and the limit is an equilibrium; the delicate part is a good that keeps its starting price, which Lemma 3.3 of Orlin handles. Once is small, the edges with are exactly the edges that carry money in the limit, and they force the equilibrium prices, so line L8 returns. Whatever line L8 returns is correct, because it passes the exact check.
Proof: The toy scaling algorithm keeps Delta-feasibility, converges to the equilibrium and returns it exactlyfull
This proof is for the toy of the pseudocode: the scaling algorithm with the exact check of line L8. It does not prove the strongly polynomial bound of StrongScaling, which needs the perturbation and the MakeFertile step of Orlin's paper.
Fix buyers and goods , one unit of each good, , budgets and utilities , where every buyer likes some good and every good is liked by some buyer. Write , and . A good is raised once its price has gone above . Line L1 sets , which is positive because some buyer likes good . We say that is -feasible when
(F1) for every buyer; (F2) for every good, and for every raised good; (F3) every is on an equality edge at and is a multiple of ; (F4) and .
This is Orlin's definition, with the upper bound of (F2) stated for all goods. All arithmetic is exact.
Claim 1 (soundness of line L8). If line L8 returns , then is a Fisher market equilibrium.
Proof. The check accepts only positive prices with and a flow of value in the network source (capacity ) (only on edges of maximum bang per buck of at ) sink (capacity ). The source arcs and the sink arcs both have total capacity , so all of them are saturated. The returned is the flow on the arc . So buyer spends exactly , only on goods of maximum bang per buck, which makes her bundle optimal for linear utilities, and good receives exactly , so it is sold completely.
Claim 2 (one price step of line L5). Let be -feasible, let be the set that line L4 finds from a root , and suppose that every good of has . Then line L5 finds a factor , the new prices keep -feasibility, and the set of line L4 at the new prices contains and either has a good with or has a good that does not have.
Proof. The root has an equality edge, so has a good. For a good the candidate is greater than because . For a buyer and a good with , the edge is not an equality edge (otherwise would be in ), so , where is the maximum bang per buck of , and the candidate is greater than . So the minimum exists and .
If and , then is an equality edge by (F3), so . If and , then by the arcs from goods to buyers. So every edge with has both ends in or both ends outside .
Every buyer has all her equality goods in . After the step, the bang per buck of on goods of is divided by , and on a good it is by the choice of . So the new maximum of is , and all her old equality edges into stay equality edges. A buyer with some has , so her maximum is attained at a good whose price did not change; her maximum does not change, and her edges with money stay equality edges. So (F3) holds. Prices only rise, so (F4) holds, and does not change, so (F1) holds. For a good , the new by the choice of , and it is smaller than the old , so (F2) holds.
The equality edges inside and the money flows do not change, so every node of is still reachable. If was attained by a good of , that good now has . Otherwise was attained by a buyer and a good , and is now an equality edge, so is reachable.
By Claim 2, the loop of lines L4 and L5 stops after at most price steps, because the set of reachable goods grows at every step that does not stop it.
Claim 3 (the augmentation of line L6). Let be -feasible with , and let line L6 send along the path to a good with . Then stays -feasible, goes down by , and no other changes.
Proof. The path comes from a breadth-first search tree, so it is simple. It starts at , alternates between forward arcs (buyer to good, on equality edges) and backward arcs (good to buyer, with ), and ends at . A forward arc gets and stays an equality edge. A backward arc has , a multiple of , so , and it gets and stays nonnegative. Every flow stays a multiple of , so (F3) and (F4) hold. A good inside the path gets from the buyer before it and toward the buyer after it, and a buyer inside the path gets from the good before it and toward the good after it, so their totals do not change. The root spends more, so goes from at least to at least . The end good goes from to ; if it is raised, then (F2) gave , so before and after.
Claim 4 (line L9). If is -feasible with every , then after line L9 it is -feasible for , and every buyer has , where is the number of flows of buyer that line L9 lowered.
Proof. Multiples of are multiples of , and the prices do not change. A good with has , so some ; it is a positive multiple of , so after subtracting it is still a positive multiple of on the same equality edge. The good then has , since it had . The goods that were not repaired have , and the raised ones still have . Each good is repaired at most once, and each repair raises of one buyer by , so .
Claim 5 (each phase ends). Line L1 gives a -feasible start, every call of PriceAndAugment ends, and every phase ends with a -feasible with all . From the second phase on, a phase makes at most calls, and during a phase, line L9 at its start included, every changes by at most in total.
Proof. With and , (F1), (F3) and (F4) hold, no good is raised, and . By Claims 2 and 3, every call ends and keeps -feasibility, and each call lowers by , so line L3 stops after finitely many calls with all . By Claim 4, the next phase starts -feasible.
In a later phase with step , the money of buyer changes only in calls with root , each time by , so by Claim 4 the number of these calls is at most . The total is at most , because each good is repaired at most once. Each call changes each by at most (the path is simple), and line L9 changes each by at most .
Claim 6 (convergence). Let and be the values at the end of the phase , with step . Then and , and is a Fisher market equilibrium. So , the unique equilibrium prices.
Proof. Prices only rise. A raised good has , so , and a good that is not raised has . So the prices are bounded and . By Claim 5, for , and , so for all . So is a Cauchy sequence, , and
Buyers: , so every buyer spends . If , then for all large , so is an equality edge at , that is for all with . These inequalities pass to the limit, so is an equality edge at . Goods: , so for every good, and for a raised good also , so .
It remains to show that every good is raised at some time. Suppose good is never raised, so . Let be the buyer with . At , buyer has maximum bang per buck , and she spends only on goods with bang per buck , so she gets utility . But she gets the amount of each good , so her utility is at most . This is a contradiction. This argument plays the role of Lemma 3.3 of Orlin.
So every good is sold completely at , every buyer spends her budget on goods of maximum bang per buck, and is an equilibrium with the money flows . The equilibrium prices of a linear Fisher market are unique (Eisenberg and Gale), so .
Claim 7 (line L8 returns). The algorithm returns after finitely many phases.
Proof. Let and its smallest entry. Take so large that . By Claim 6, an edge outside has , and an edge in has . So line L7 finds .
Every buyer spends and every good receives in , so touches every node. Every edge of is an equality edge at , so . In one connected part of , basic_prices gives the first good the value , a buyer reached from a good with value the value , and a good reached from a buyer with value the value . By induction along the search, if a good has value then the next buyer has value and the next good has value , with the same in the whole part. So the values are consistent and the function does not return None. In , the buyers of a part spend all their money on goods of the same part, and those goods get money only from buyers of that part, so the prices of a part add up to the budgets of its buyers. The scaling of basic_prices therefore gives exactly . The prices are positive, add up to , and the flow given by has value , which is the largest possible, so the check accepts. Hence line L8 returns at the latest at phase , and by Claim 1 its answer is an equilibrium.
Orlin's paper perturbs the utilities so that the equilibrium allocation is unique and its support is a forest, and then shows that the prices of the support are the answer. The toy does not perturb, so the support that it guesses can give wrong prices at an early phase, as at in the example of the page; the exact check of line L8 rejects them, and Claim 7 shows that the right support appears.
Complexity
For integer data, Theorem 3.1 of the Dagstuhl version shows that each phase makes at most calls of PriceAndAugment and that each call takes time with prices stored implicitly and a Fibonacci heap of the times at which edges become equality edges. The number of phases of the scaling algorithm depends on the largest utility and budget, so it is weakly polynomial. The strongly polynomial algorithm StrongScaling has phases and runs in time, which the abstract states in the weaker form . Orlin also shows that an -approximate solution takes phases.
The toy stores prices explicitly and recomputes the residual network with breadth-first search, so one price step costs and one call of PriceAndAugment exact operations; the check of line L8 adds a maximum flow per phase. It has no strongly polynomial bound, because it leaves out MakeFertile.
Properties
- Prices only rise, as in the DPSV algorithm, and money moves in multiples of .
- Strongly polynomial. The number of operations of StrongScaling depends only on and . The numbers themselves are rational, and the bit lengths stay polynomial.
- Abundant edges are permanent. Once an edge carries at least at the start of a phase, it carries money in every later phase and at the equilibrium.
- The scaling algorithm alone is not strongly polynomial. Orlin's example has one buyer with budget and two goods with utilities and . The equilibrium spends on the second good, and the scaling algorithm needs more than phases before this edge carries enough money to be recognized.
Variants and improvements
- Weakly polynomial scaling. The algorithm of the pseudocode, without MakeFertile, is already faster than the DPSV bound.
- Approximate equilibria. Stopping the scaling algorithm after phases gives an -approximate solution in time.
- Small utilities. When the utilities are bounded by a polynomial in , Orlin gives a simpler strongly polynomial method (Section 3.7 and Theorem 3.3 of the Dagstuhl version). It sorts the buyers by budget, adds them in groups at the places where the budget drops by a large factor, and needs scaling phases in total.
- Other methods. The Eisenberg-Gale program can be solved by interior point or ellipsoid methods, and proportional response dynamics converges to the same equilibrium without a central planner.
When to use it
Use it as the reference algorithm when a guaranteed strongly polynomial bound for linear Fisher markets matters, or as a model of how abundant edges turn a scaling algorithm into a strongly polynomial one. In practice, for small markets the DPSV algorithm with exact arithmetic is simpler, and for large markets where an approximate answer is enough the scaling algorithm stopped early or a convex solver is easier to implement.
Pitfalls
- Raising the prices in line L5 beyond the first good whose extra money reaches leaves a raised good with , which breaks -feasibility: the good is then sold for less than its price.
- Sending more than in line L6, for example all the money that the root has left, breaks the rule that flows are multiples of and the bound of calls per phase.
- Halving in line L9 without lowering the flows into goods with leaves goods with too much money for the next phase.
- Returning the prices forced by the edges of line L7 without the check of line L8 fails without perturbation: in the example, the edges at force , which is not an equilibrium.
- Using floating point in line L5 makes the equality tests fail, so arcs of the residual network get lost. Use exact rationals.
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/orlin-fisher-market-algorithm/. The authors are listed in prov/XBSFVW.jsonl.
"""A toy of Orlin's Delta-scaling algorithm for linear Fisher markets.
This is the weakly polynomial scaling algorithm (ScalingAlgorithm with PriceAndAugment), written
for small inputs in exact Fractions. It is a toy: prices are stored explicitly, augmenting paths
come from breadth-first search instead of the Fibonacci heap of the paper, and the extra steps that
make the algorithm strongly polynomial (fertile components and MakeFertile) are left out. The
utilities are not perturbed, so the final step computes the prices of the candidate support and
accepts them only after an exact max-flow check.
Buyers are 0, ..., nb - 1 and goods are 0, ..., ng - 1, one unit each. U[i][j] >= 0 is the
utility of buyer i for all of good j and e[i] > 0 her budget. x[i][j] is money, not goods.
"""
from collections import deque
from fractions import Fraction
def _bang(U, p, i):
return max(Fraction(U[i][j]) / p[j] for j in range(len(p)) if U[i][j] > 0)
def _equality(U, p, i, j, alpha):
return U[i][j] > 0 and Fraction(U[i][j]) / p[j] == alpha[i]
def _max_flow(num_nodes, cap, s, t):
res, adj = {}, [[] for _ in range(num_nodes)]
for (a, b), c in cap.items():
adj[a].append(b)
adj[b].append(a)
res[(a, b)] = c
res.setdefault((b, a), Fraction(0))
value = Fraction(0)
while True:
prev, queue = {s: None}, deque([s])
while queue and t not in prev:
a = queue.popleft()
for b in adj[a]:
if b not in prev and res[(a, b)] > 0:
prev[b] = a
queue.append(b)
if t not in prev:
return value, {arc: c - res[arc] for arc, c in cap.items()}
path, b = [], t
while prev[b] is not None:
path.append((prev[b], b))
b = prev[b]
push = min(res[arc] for arc in path)
for a, b in path:
res[(a, b)] -= push
res[(b, a)] += push
value += push
def certify(U, e, p):
"""Return the money x[i][j] of an equilibrium at prices p, or None if p are not equilibrium
prices. The test is a maximum flow on the edges of maximum bang per buck."""
nb, ng = len(U), len(U[0])
if any(q is None or q <= 0 for q in p) or sum(p) != sum(e):
return None
alpha = [_bang(U, p, i) for i in range(nb)]
src, snk = 0, nb + ng + 1
cap = {(src, 1 + j): p[j] for j in range(ng)}
for i in range(nb):
cap[(1 + ng + i, snk)] = e[i]
for j in range(ng):
if _equality(U, p, i, j, alpha):
cap[(1 + j, 1 + ng + i)] = sum(e) + 1
value, flow = _max_flow(snk + 1, cap, src, snk)
if value != sum(e):
return None
return [[flow.get((1 + j, 1 + ng + i), Fraction(0)) for j in range(ng)] for i in range(nb)]
def basic_prices(U, e, support):
"""The prices fixed by a set of edges: equal bang per buck along the edges of each buyer, and
on each connected part the prices add up to the budgets. None if they are not well defined."""
nb, ng = len(U), len(U[0])
nbr = {}
for i, j in support:
nbr.setdefault(("b", i), []).append(("g", j))
nbr.setdefault(("g", j), []).append(("b", i))
if len(nbr) != nb + ng:
return None
rel, p = {}, [None] * ng
for j0 in range(ng):
if ("g", j0) in rel:
continue
rel[("g", j0)] = Fraction(1)
comp, stack = [("g", j0)], [("g", j0)]
while stack:
a = stack.pop()
for c in nbr[a]:
i, j = (a[1], c[1]) if a[0] == "b" else (c[1], a[1])
val = Fraction(U[i][j]) / rel[a]
if c not in rel:
rel[c] = val
comp.append(c)
stack.append(c)
elif rel[c] != val:
return None
money = sum(e[a[1]] for a in comp if a[0] == "b")
scale = money / sum(rel[a] for a in comp if a[0] == "g")
for a in comp:
if a[0] == "g":
p[a[1]] = rel[a] * scale
return p
def _price_and_augment(U, e, p, x, r, delta):
"""Raise the prices of the goods reachable from buyer r until some reachable good j has
b_j <= 0, then send delta along a residual path from r to j."""
nb, ng = len(U), len(U[0])
while True:
alpha = [_bang(U, p, i) for i in range(nb)]
prev = {("b", r): None} # @line L4
queue = deque([("b", r)])
while queue:
kind, a = queue.popleft()
nxt = []
if kind == "b":
nxt = [("g", j) for j in range(ng) if _equality(U, p, a, j, alpha)]
else:
nxt = [("b", i) for i in range(nb) if x[i][a] > 0]
for v in nxt:
if v not in prev:
prev[v] = (kind, a)
queue.append(v)
back = [j for (kind, j) in prev if kind == "g" and sum(x[i][j] for i in range(nb)) - p[j] <= 0]
if back:
break
act_goods = [j for (kind, j) in prev if kind == "g"]
act_buyers = [i for (kind, i) in prev if kind == "b"]
q = None # @line L5
for j in act_goods: # b_j reaches 0
cand = sum(x[i][j] for i in range(nb)) / p[j]
q = cand if q is None else min(q, cand)
for i in act_buyers: # a new equality edge to a good that is not reachable yet
for j in range(ng):
if ("g", j) not in prev and U[i][j] > 0:
q = min(q, alpha[i] * p[j] / U[i][j])
for j in act_goods:
p[j] *= q
j = min(back) # @line L6
node = ("g", j)
while prev[node] is not None:
before = prev[node]
if before[0] == "b":
x[before[1]][node[1]] += delta # forward arc: buyer spends more on the good
else:
x[node[1]][before[1]] -= delta # backward arc: buyer spends less on the good
node = before
def orlin_scaling(U, e, trace=None):
"""Return (p, x): exact equilibrium prices and money spent. If trace is a list, a tuple
(delta, p, x) is appended to it at the end of each scaling phase."""
nb, ng = len(U), len(U[0])
n = nb + ng
e = [Fraction(v) for v in e]
delta = max(e) / n # @line L1
p = [max(Fraction(U[i][j]) * e[i] / (n * sum(U[i])) for i in range(nb)) for j in range(ng)]
x = [[Fraction(0)] * ng for _ in range(nb)]
while True: # @line L2
while True: # @line L3
r = next((i for i in range(nb) if e[i] - sum(x[i]) >= delta), None)
if r is None:
break
_price_and_augment(U, e, p, x, r, delta)
if trace is not None:
trace.append((delta, list(p), [list(row) for row in x]))
support = [(i, j) for i in range(nb) for j in range(ng) if x[i][j] >= 4 * n * delta] # @line L7
cand = basic_prices(U, e, support) # @line L8
if cand is not None:
exact = certify(U, e, cand)
if exact is not None:
return cand, exact
delta /= 2 # @line L9
for j in range(ng):
if sum(x[i][j] for i in range(nb)) - p[j] > delta:
i = next(i for i in range(nb) if x[i][j] > 0)
x[i][j] -= delta
test_orlin_fisher_market_algorithm.py 159 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/orlin-fisher-market-algorithm/. The authors are listed in prov/XBSFVW.jsonl.
import random
import unittest
from fractions import Fraction
from itertools import combinations
from orlin_fisher_market_algorithm import orlin_scaling
def is_equilibrium(U, e, p, x):
"""Exact check with x in money: positive prices, budgets spent, goods sold, and money only on
goods of maximum bang per buck."""
nb, ng = len(U), len(U[0])
if any(q <= 0 for q in p):
return False
for i in range(nb):
best = max(Fraction(U[i][j]) / p[j] for j in range(ng))
if sum(x[i]) != e[i]:
return False
if any(x[i][j] < 0 or (x[i][j] > 0 and Fraction(U[i][j]) / p[j] != best) for j in range(ng)):
return False
return all(sum(x[i][j] for i in range(nb)) == p[j] for j in range(ng))
def brute_force_prices(U, e):
"""All equilibrium prices, from every forest of spending edges: along a buyer's edges the bang
per buck is equal, and on each tree the prices add up to the budgets."""
nb, ng = len(U), len(U[0])
edges = [(i, j) for i in range(nb) for j in range(ng) if U[i][j] > 0]
found = set()
for k in range(1, min(len(edges), nb + ng - 1) + 1):
for H in combinations(edges, k):
nodes = {("b", i) for i, _ in H} | {("g", j) for _, j in H}
if len(nodes) != nb + ng or k != nb + ng - components(H):
continue
p = tree_prices(U, e, H)
x = tree_flow(nb, ng, e, p, H)
if x is not None and is_equilibrium(U, e, p, x):
found.add(tuple(p))
return found
def components(H):
parent = {}
def find(a):
while parent.setdefault(a, a) != a:
a = parent[a]
return a
for i, j in H:
parent[find(("b", i))] = find(("g", j))
return len({find(a) for a in list(parent)})
def tree_prices(U, e, H):
ng = len(U[0])
rel = {}
p = [None] * ng
for j0 in range(ng):
if ("g", j0) in rel:
continue
rel[("g", j0)] = Fraction(1)
comp, changed = [("g", j0)], True
while changed:
changed = False
for i, j in H:
if ("g", j) in rel and ("b", i) not in rel:
rel[("b", i)] = Fraction(U[i][j]) / rel[("g", j)]
elif ("b", i) in rel and ("g", j) not in rel:
rel[("g", j)] = Fraction(U[i][j]) / rel[("b", i)]
else:
continue
comp += [("b", i), ("g", j)]
changed = True
comp = set(comp)
scale = sum(e[a[1]] for a in comp if a[0] == "b") / sum(rel[a] for a in comp if a[0] == "g")
for a in comp:
if a[0] == "g":
p[a[1]] = rel[a] * scale
return p
def tree_flow(nb, ng, e, p, H):
left = set(H)
need = {("b", i): Fraction(e[i]) for i in range(nb)}
need.update({("g", j): p[j] for j in range(ng)})
x = [[Fraction(0)] * ng for _ in range(nb)]
while left:
deg = {}
for i, j in left:
deg[("b", i)] = deg.get(("b", i), 0) + 1
deg[("g", j)] = deg.get(("g", j), 0) + 1
leaf = next(v for v, d in deg.items() if d == 1)
i, j = next(ed for ed in left if ("b", ed[0]) == leaf or ("g", ed[1]) == leaf)
if need[leaf] < 0:
return None
x[i][j] = need[leaf]
need[("b", i)] -= x[i][j]
need[("g", j)] -= x[i][j]
left.discard((i, j))
return x if all(v == 0 for v in need.values()) else None
def random_market(rng, nb, ng):
while True:
U = [[rng.choice([0, 1, 2, 3, 5, 8]) for _ in range(ng)] for _ in range(nb)]
if all(any(r) for r in U) and all(any(U[i][j] for i in range(nb)) for j in range(ng)):
return U, [rng.randint(1, 6) for _ in range(nb)]
class TestOrlinScaling(unittest.TestCase):
def test_check_value(self):
p, x = orlin_scaling([[2, 1], [1, 2]], [1, 1])
self.assertEqual(p, [1, 1])
self.assertEqual(x, [[1, 0], [0, 1]])
def test_example(self):
trace = []
p, x = orlin_scaling([[1, 4, 3], [4, 2, 1], [1, 1, 2]], [1, 1, 3], trace)
self.assertEqual(p, [Fraction(5, 4), Fraction(5, 4), Fraction(5, 2)])
self.assertTrue(is_equilibrium([[1, 4, 3], [4, 2, 1], [1, 1, 2]], [1, 1, 3], p, x))
self.assertEqual(trace[0][0], Fraction(1, 2))
for (a, _, _), (b, _, _) in zip(trace, trace[1:]):
self.assertEqual(b, a / 2)
for delta, q, y in trace:
# Delta-optimal at the end of each phase: every buyer has less than delta left, and
# the money on each edge is a multiple of delta.
for i in range(3):
self.assertLess(Fraction([1, 1, 3][i]) - sum(y[i]), delta)
self.assertTrue(all((v / delta).denominator == 1 for v in y[i]))
# prices never go down
for (_, q1, _), (_, q2, _) in zip(trace, trace[1:]):
self.assertTrue(all(a <= b for a, b in zip(q1, q2)))
def test_check_value_phases(self):
trace = []
orlin_scaling([[2, 1], [1, 2]], [1, 1], trace)
self.assertEqual([d for d, _, _ in trace], [Fraction(1, 4), Fraction(1, 8), Fraction(1, 16)])
def test_identical_buyers(self):
# The equilibrium allocation is not unique here; the prices are.
p, x = orlin_scaling([[1, 1], [1, 1]], [1, 3])
self.assertEqual(p, [2, 2])
self.assertTrue(is_equilibrium([[1, 1], [1, 1]], [1, 3], p, x))
def test_random_against_brute_force(self):
rng = random.Random(9)
for _ in range(40):
nb, ng = rng.randint(1, 3), rng.randint(1, 3)
U, e = random_market(rng, nb, ng)
p, x = orlin_scaling(U, e)
self.assertTrue(is_equilibrium(U, e, p, x))
self.assertEqual(brute_force_prices(U, e), {tuple(p)})
if __name__ == "__main__":
unittest.main()
History
Devanur, Papadimitriou, Saberi and Vazirani gave the first combinatorial polynomial time algorithm for linear Fisher markets and asked for a strongly polynomial one. Orlin presented his algorithm at the Dagstuhl seminar on equilibrium computation and at STOC 2010. He used the scaling idea of Edmonds and Karp and the abundant edges that he had introduced for a strongly polynomial minimum cost flow algorithm, the problem on the minimum cost flow page.
References
- James B. Orlin, Improved algorithms for computing Fisher's market clearing prices, STOC 2010, 291-300, the whole paper (the scaling algorithm with PriceAndAugment, abundant edges, and the strongly polynomial algorithm)
- James B. Orlin, Improved algorithms for computing Fisher's market clearing prices, Dagstuhl Seminar Proceedings 10171, Equilibrium Computation (2010), Section 3 (Delta-feasibility, PriceAndAugment, ScalingAlgorithm, Lemma 3.3, Lemma 3.4, Theorems 3.1 to 3.3), Section 4 (fertile components, MakeFertile and StrongScaling)
- Nikhil R. Devanur, Christos H. Papadimitriou, Amin Saberi and Vijay V. Vazirani, Market equilibrium via a primal-dual algorithm for a convex program, Journal of the ACM 55(5), Article 22 (2008), Sections 1.2 and 9 (a strongly polynomial algorithm is stated as an open question) and Sections 5 to 8 (the price raising that Orlin's algorithm reuses)
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 XBSFVW Edit this page History Report an error Markdown