Algorithm Search⌘K

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
Properties
deterministiciterative
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 Δ\Delta, and Δ\Delta 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 Δ\Delta 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 BB of buyers and a set GG of goods, with one unit of each good, and n=∣B∣+∣G∣n = |B| + |G|. Buyer ii has a budget ei>0e_i > 0 and utility uij≥0u_{ij} \ge 0 for all of good jj, linear in the amount. The edges are the mm pairs with uij>0u_{ij} > 0. Every buyer likes some good and every good is liked by some buyer. Find prices pp and money flows xij≥0x_{ij} \ge 0 (the money that buyer ii spends on good jj) such that every buyer spends exactly eie_i, only on goods of maximum bang per buck uij/pju_{ij} / p_j, and every good receives exactly pjp_j.

Write ci=ei−∑jxijc_i = e_i - \sum_j x_{ij} for the money that buyer ii has left and bj=∑ixij−pjb_j = \sum_i x_{ij} - p_j for the money that good jj receives above its price. An equality edge at pp is an edge with uij/pj=max⁡kuik/pku_{ij} / p_j = \max_k u_{ik} / p_k. Let p0p^0 be the starting prices. Following Orlin, (p,x)(p, x) is Δ\Delta-feasible when ci≥0c_i \ge 0 for every buyer, 0≤bj≤Δ0 \le b_j \le \Delta for every good with pj>pj0p_j > p^0_j, every xij>0x_{ij} > 0 is on an equality edge and is a multiple of Δ\Delta, and x,p≥0x, p \ge 0. It is Δ\Delta-optimal if also ci<Δc_i < \Delta for every buyer.

The algorithm

The residual network N(p,x)N(p, x) has an arc from buyer ii to good jj for each equality edge and an arc from good jj back to buyer ii when xij>0x_{ij} > 0. The pseudocode is the scaling algorithm, which the implementation follows.

  1. ORLIN-SCALING(utilities u, budgets e)
  2. 1Δ ← max_i e_i / n; p_j ← max_i u_ij e_i / (n Σ_k u_ik) for every good; x ← 0
  3. 2loop
  4. 3while some buyer r has c_r ≥ Δ do
  5. 4A ← the nodes that r reaches in N(p, x)
  6. 5if 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
  7. 6send Δ along a path of N(p, x) from r to a good j of A with b_j ≤ 0
  8. 7S ← the edges with x_ij ≥ 4nΔ
  9. 8p' ← the prices that S forces; if p' passes the exact max-flow check, return p' and the flow
  10. 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 rr 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 Δ\Delta on the forward arcs of the path and removes Δ\Delta on its backward arcs, so only the root rr and the last good jj change their totals. Line L9 makes the solution Δ/2\Delta/2-feasible for the next phase.

Line L8 is the stopping test. A set of edges SS 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 xij≥3nΔx_{ij} \ge 3n\Delta at the start of the Δ\Delta phase. In one phase, each xijx_{ij} changes by O(nΔ)O(n\Delta), and Δ\Delta 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 n−1n - 1 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 Δ′≤Δ/n2\Delta' \le \Delta / n^2 and new prices from which a new abundant edge appears within O(log⁡n)O(\log n) phases. This gives O(nlog⁡n)O(n \log n) phases with O(n)O(n) calls of PriceAndAugment each. The toy leaves MakeFertile out.

Example

Three buyers and three goods, u1=(1,4,3)u_1 = (1, 4, 3), u2=(4,2,1)u_2 = (4, 2, 1), u3=(1,1,2)u_3 = (1, 1, 2), budgets e=(1,1,3)e = (1, 1, 3), so n=6n = 6. Line L1 gives Δ=1/2\Delta = 1/2 and p0=(1/8,1/8,1/4)p^0 = (1/8, 1/8, 1/4). The money flows reach their final values in the second phase; after that only the prices move toward the equilibrium (5/4,5/4,5/2)(5/4, 5/4, 5/2), and line L8 waits until the edges with xij≥24Δx_{ij} \ge 24\Delta force the right prices.

Δ\Delta at the end of the phase prices buyer 3 spends on goods 1, 2, 3 edges with xij≥24Δx_{ij} \ge 24\Delta line L8
1/21/2 (1,1,2)(1, 1, 2) 1/2,1/2,21/2, 1/2, 2 none no prices
1/41/4 (9/8,9/8,9/4)(9/8, 9/8, 9/4) 1/4,1/4,5/21/4, 1/4, 5/2 none no prices
1/81/8 (19/16,19/16,19/8)(19/16, 19/16, 19/8) 1/4,1/4,5/21/4, 1/4, 5/2 none no prices
1/161/16 (39/32,39/32,39/16)(39/32, 39/32, 39/16) 1/4,1/4,5/21/4, 1/4, 5/2 (3,3)(3, 3) no prices
1/321/32 (79/64,79/64,79/32)(79/64, 79/64, 79/32) 1/4,1/4,5/21/4, 1/4, 5/2 (1,2),(2,1),(3,3)(1, 2), (2, 1), (3, 3) (1,1,3)(1, 1, 3), rejected
1/641/64 (159/128,159/128,159/64)(159/128, 159/128, 159/64) 1/4,1/4,5/21/4, 1/4, 5/2 (1,2),(2,1),(3,3)(1, 2), (2, 1), (3, 3) (1,1,3)(1, 1, 3), rejected
1/1281/128 (319/256,319/256,319/128)(319/256, 319/256, 319/128) 1/4,1/4,5/21/4, 1/4, 5/2 all five edges (5/4,5/4,5/2)(5/4, 5/4, 5/2), accepted

In all phases buyer 1 spends 11 on good 2 and buyer 2 spends 11 on good 1. At Δ=1/32\Delta = 1/32, the three edges form three parts with one buyer each, which force the prices (1,1,3)(1, 1, 3); at these prices buyer 3 gets 2/32/3 per unit of money from good 3 but 11 from goods 1 and 2, so the check fails. At Δ=1/128\Delta = 1/128 the edges (3,1)(3, 1) and (3,2)(3, 2) carry 1/4≥24/1281/4 \ge 24/128, all five edges form one part, and they force p=(5/4,5/4,5/2)p = (5/4, 5/4, 5/2), which the check accepts. For the market u1=(2,1)u_1 = (2, 1), u2=(1,2)u_2 = (1, 2) with budgets (1,1)(1, 1), the phases Δ=1/4,1/8,1/16\Delta = 1/4, 1/8, 1/16 end with prices (3/4,3/4)(3/4, 3/4), (7/8,7/8)(7/8, 7/8) and (15/16,15/16)(15/16, 15/16), and the last one returns p=(1,1)p = (1, 1).

Correctness

The proof for the toy is in proofs/correctness.md. Line L5 and line L6 keep Δ\Delta-feasibility, and line L9 turns a Δ\Delta-optimal solution into a Δ/2\Delta/2-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 Δ\Delta, so each phase ends. Prices only rise and stay bounded, and the money flows change by at most (n+1)Δ(n + 1)\Delta 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 Δ\Delta is small, the edges with xij≥4nΔx_{ij} \ge 4n\Delta 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 BB and goods GG, one unit of each good, n=∣B∣+∣G∣≥2n = |B| + |G| \ge 2, budgets ei>0e_i > 0 and utilities uij≥0u_{ij} \ge 0, where every buyer likes some good and every good is liked by some buyer. Write uiG=∑kuiku_{iG} = \sum_k u_{ik}, ci=ei−∑jxijc_i = e_i - \sum_j x_{ij} and bj=∑ixij−pjb_j = \sum_i x_{ij} - p_j. A good is raised once its price has gone above pj0p^0_j. Line L1 sets pj0=max⁡iuijei/(nuiG)p^0_j = \max_i u_{ij} e_i / (n u_{iG}), which is positive because some buyer likes good jj. We say that (p,x)(p, x) is Δ\Delta-feasible when

(F1) ci≥0c_i \ge 0 for every buyer; (F2) bj≤Δb_j \le \Delta for every good, and bj≥0b_j \ge 0 for every raised good; (F3) every xij>0x_{ij} > 0 is on an equality edge at pp and is a multiple of Δ\Delta; (F4) x≥0x \ge 0 and p≥p0p \ge p^0.

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 (p′,x)(p', x), then (p′,x)(p', x) is a Fisher market equilibrium.

Proof. The check accepts only positive prices with ∑jpj′=∑iei\sum_j p'_j = \sum_i e_i and a flow of value ∑iei\sum_i e_i in the network source →j\to j (capacity pj′p'_j) →i\to i (only on edges of maximum bang per buck of ii at p′p') →\to sink (capacity eie_i). The source arcs and the sink arcs both have total capacity ∑iei\sum_i e_i, so all of them are saturated. The returned xijx_{ij} is the flow on the arc j→ij \to i. So buyer ii spends exactly eie_i, only on goods of maximum bang per buck, which makes her bundle optimal for linear utilities, and good jj receives exactly pj′p'_j, so it is sold completely. □\square

Claim 2 (one price step of line L5). Let (p,x)(p, x) be Δ\Delta-feasible, let AA be the set that line L4 finds from a root rr, and suppose that every good of AA has bj>0b_j > 0. Then line L5 finds a factor q>1q > 1, the new prices keep Δ\Delta-feasibility, and the set of line L4 at the new prices contains AA and either has a good with bj≤0b_j \le 0 or has a good that AA does not have.

Proof. The root has an equality edge, so AA has a good. For a good j∈Aj \in A the candidate ∑ixij/pj\sum_i x_{ij} / p_j is greater than 11 because bj>0b_j > 0. For a buyer i∈Ai \in A and a good j∉Aj \notin A with uij>0u_{ij} > 0, the edge (i,j)(i, j) is not an equality edge (otherwise jj would be in AA), so uij/pj<αiu_{ij} / p_j < \alpha_i, where αi\alpha_i is the maximum bang per buck of ii, and the candidate αipj/uij\alpha_i p_j / u_{ij} is greater than 11. So the minimum qq exists and q>1q > 1.

If i∈Ai \in A and xij>0x_{ij} > 0, then (i,j)(i, j) is an equality edge by (F3), so j∈Aj \in A. If j∈Aj \in A and xij>0x_{ij} > 0, then i∈Ai \in A by the arcs from goods to buyers. So every edge with xij>0x_{ij} > 0 has both ends in AA or both ends outside AA.

Every buyer i∈Ai \in A has all her equality goods in AA. After the step, the bang per buck of ii on goods of AA is divided by qq, and on a good j∉Aj \notin A it is uij/pj≤αi/qu_{ij} / p_j \le \alpha_i / q by the choice of qq. So the new maximum of ii is αi/q\alpha_i / q, and all her old equality edges into AA stay equality edges. A buyer i∉Ai \notin A with some xij>0x_{ij} > 0 has j∉Aj \notin A, 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 xx does not change, so (F1) holds. For a good j∈Aj \in A, the new bj=∑ixij−qpj≥0b_j = \sum_i x_{ij} - q p_j \ge 0 by the choice of qq, and it is smaller than the old bj≤Δb_j \le \Delta, so (F2) holds.

The equality edges inside AA and the money flows do not change, so every node of AA is still reachable. If qq was attained by a good of AA, that good now has bj=0b_j = 0. Otherwise qq was attained by a buyer i∈Ai \in A and a good j∉Aj \notin A, and (i,j)(i, j) is now an equality edge, so jj is reachable. □\square

By Claim 2, the loop of lines L4 and L5 stops after at most ∣G∣|G| 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 (p,x)(p, x) be Δ\Delta-feasible with cr≥Δc_r \ge \Delta, and let line L6 send Δ\Delta along the path to a good jj with bj≤0b_j \le 0. Then (p,x)(p, x) stays Δ\Delta-feasible, crc_r goes down by Δ\Delta, and no other cic_i changes.

Proof. The path comes from a breadth-first search tree, so it is simple. It starts at rr, alternates between forward arcs (buyer to good, on equality edges) and backward arcs (good to buyer, with xij>0x_{ij} > 0), and ends at jj. A forward arc gets +Δ+\Delta and stays an equality edge. A backward arc has xij>0x_{ij} > 0, a multiple of Δ\Delta, so xij≥Δx_{ij} \ge \Delta, and it gets −Δ-\Delta and stays nonnegative. Every flow stays a multiple of Δ\Delta, so (F3) and (F4) hold. A good inside the path gets +Δ+\Delta from the buyer before it and −Δ-\Delta toward the buyer after it, and a buyer inside the path gets −Δ-\Delta from the good before it and +Δ+\Delta toward the good after it, so their totals do not change. The root spends Δ\Delta more, so crc_r goes from at least Δ\Delta to at least 00. The end good goes from bj≤0b_j \le 0 to bj≤Δb_j \le \Delta; if it is raised, then (F2) gave bj≥0b_j \ge 0, so bj=0b_j = 0 before and Δ\Delta after. □\square

Claim 4 (line L9). If (p,x)(p, x) is Δ\Delta-feasible with every ci<Δc_i < \Delta, then after line L9 it is Δ′\Delta'-feasible for Δ′=Δ/2\Delta' = \Delta / 2, and every buyer has ci<(2+ki)Δ′c_i < (2 + k_i) \Delta', where kik_i is the number of flows of buyer ii that line L9 lowered.

Proof. Multiples of Δ\Delta are multiples of Δ′\Delta', and the prices do not change. A good with bj>Δ′b_j > \Delta' has ∑ixij>pj>0\sum_i x_{ij} > p_j > 0, so some xij>0x_{ij} > 0; it is a positive multiple of 2Δ′2 \Delta', so after subtracting Δ′\Delta' it is still a positive multiple of Δ′\Delta' on the same equality edge. The good then has bj∈(0,Δ′]b_j \in (0, \Delta'], since it had bj≤Δ=2Δ′b_j \le \Delta = 2\Delta'. The goods that were not repaired have bj≤Δ′b_j \le \Delta', and the raised ones still have bj≥0b_j \ge 0. Each good is repaired at most once, and each repair raises cic_i of one buyer by Δ′\Delta', so ci<Δ+kiΔ′=(2+ki)Δ′c_i < \Delta + k_i \Delta' = (2 + k_i) \Delta'. □\square

Claim 5 (each phase ends). Line L1 gives a Δ\Delta-feasible start, every call of PriceAndAugment ends, and every phase ends with a Δ\Delta-feasible (p,x)(p, x) with all ci<Δc_i < \Delta. From the second phase on, a phase makes at most nn calls, and during a phase, line L9 at its start included, every xijx_{ij} changes by at most (n+1)Δ(n + 1) \Delta in total.

Proof. With x=0x = 0 and p=p0p = p^0, (F1), (F3) and (F4) hold, no good is raised, and bj=−pj0<0b_j = -p^0_j < 0. By Claims 2 and 3, every call ends and keeps Δ\Delta-feasibility, and each call lowers ∑ici≥0\sum_i c_i \ge 0 by Δ\Delta, so line L3 stops after finitely many calls with all ci<Δc_i < \Delta. By Claim 4, the next phase starts Δ′\Delta'-feasible.

In a later phase with step Δ′\Delta', the money cic_i of buyer ii changes only in calls with root ii, each time by −Δ′-\Delta', so by Claim 4 the number of these calls is at most ⌊ci/Δ′⌋≤1+ki\lfloor c_i / \Delta' \rfloor \le 1 + k_i. The total is at most ∣B∣+∑iki≤∣B∣+∣G∣=n|B| + \sum_i k_i \le |B| + |G| = n, because each good is repaired at most once. Each call changes each xijx_{ij} by at most Δ′\Delta' (the path is simple), and line L9 changes each xijx_{ij} by at most Δ′\Delta'. □\square

Claim 6 (convergence). Let pkp^k and xkx^k be the values at the end of the phase kk, with step Δk\Delta_k. Then pk→pˉp^k \to \bar{p} and xk→xˉx^k \to \bar{x}, and (pˉ,xˉ)(\bar{p}, \bar{x}) is a Fisher market equilibrium. So pˉ=p∗\bar{p} = p^*, the unique equilibrium prices.

Proof. Prices only rise. A raised good has bj≥0b_j \ge 0, so pj≤∑ixij≤∑ieip_j \le \sum_i x_{ij} \le \sum_i e_i, and a good that is not raised has pj=pj0p_j = p^0_j. So the prices are bounded and pk→pˉ≥p0>0p^k \to \bar{p} \ge p^0 > 0. By Claim 5, ∣xijl−xijl−1∣≤(n+1)Δl|x^{l}_{ij} - x^{l-1}_{ij}| \le (n + 1) \Delta_l for l≥2l \ge 2, and Δl=Δk/2l−k\Delta_l = \Delta_k / 2^{l - k}, so ∣xijl−xijk∣≤(n+1)Δk|x^l_{ij} - x^k_{ij}| \le (n + 1) \Delta_k for all l>k≥1l > k \ge 1. So xkx^k is a Cauchy sequence, xk→xˉx^k \to \bar{x}, and

∣xijk−xˉij∣≤(n+1)Δkfor k≥1.|x^k_{ij} - \bar{x}_{ij}| \le (n + 1) \Delta_k \quad \text{for } k \ge 1 .

Buyers: 0≤ci<Δk→00 \le c_i < \Delta_k \to 0, so every buyer spends ∑jxˉij=ei\sum_j \bar{x}_{ij} = e_i. If xˉij>0\bar{x}_{ij} > 0, then xijk>0x^k_{ij} > 0 for all large kk, so (i,j)(i, j) is an equality edge at pkp^k, that is uij/pjk≥uil/plku_{ij} / p^k_j \ge u_{il} / p^k_l for all ll with uil>0u_{il} > 0. These inequalities pass to the limit, so (i,j)(i, j) is an equality edge at pˉ\bar{p}. Goods: bj≤Δk→0b_j \le \Delta_k \to 0, so ∑ixˉij≤pˉj\sum_i \bar{x}_{ij} \le \bar{p}_j for every good, and for a raised good also bj≥0b_j \ge 0, so ∑ixˉij=pˉj\sum_i \bar{x}_{ij} = \bar{p}_j.

It remains to show that every good is raised at some time. Suppose good jj is never raised, so pˉj=pj0\bar{p}_j = p^0_j. Let ii be the buyer with pj0=uijei/(nuiG)p^0_j = u_{ij} e_i / (n u_{iG}). At pˉ\bar{p}, buyer ii has maximum bang per buck αi≥uij/pj0=nuiG/ei\alpha_i \ge u_{ij} / p^0_j = n u_{iG} / e_i, and she spends eie_i only on goods with bang per buck αi\alpha_i, so she gets utility αiei≥nuiG\alpha_i e_i \ge n u_{iG}. But she gets the amount xˉik/pˉk≤1\bar{x}_{ik} / \bar{p}_k \le 1 of each good kk, so her utility is at most ∑kuik=uiG<nuiG\sum_k u_{ik} = u_{iG} < n u_{iG}. This is a contradiction. This argument plays the role of Lemma 3.3 of Orlin.

So every good is sold completely at pˉ\bar{p}, every buyer spends her budget on goods of maximum bang per buck, and (pˉ,xˉ)(\bar{p}, \bar{x}) is an equilibrium with the money flows xˉ\bar{x}. The equilibrium prices of a linear Fisher market are unique (Eisenberg and Gale), so pˉ=p∗\bar{p} = p^*. □\square

Claim 7 (line L8 returns). The algorithm returns after finitely many phases.

Proof. Let S∗={(i,j):xˉij>0}S^* = \{(i, j) : \bar{x}_{ij} > 0\} and β\beta its smallest entry. Take kk so large that (5n+1)Δk≤β(5n + 1) \Delta_k \le \beta. By Claim 6, an edge outside S∗S^* has xijk≤(n+1)Δk<4nΔkx^k_{ij} \le (n + 1) \Delta_k < 4n \Delta_k, and an edge in S∗S^* has xijk≥β−(n+1)Δk≥4nΔkx^k_{ij} \ge \beta - (n + 1) \Delta_k \ge 4n \Delta_k. So line L7 finds S=S∗S = S^*.

Every buyer spends ei>0e_i > 0 and every good receives pj∗>0p^*_j > 0 in xˉ\bar{x}, so S∗S^* touches every node. Every edge of S∗S^* is an equality edge at p∗p^*, so uij/pj∗=αiu_{ij} / p^*_j = \alpha_i. In one connected part of S∗S^*, basic_prices gives the first good the value 11, a buyer reached from a good with value tt the value uij/tu_{ij} / t, and a good reached from a buyer with value ss the value uij/su_{ij} / s. By induction along the search, if a good has value λpj∗\lambda p^*_j then the next buyer has value αi/λ\alpha_i / \lambda and the next good has value λpj′∗\lambda p^*_{j'}, with the same λ\lambda in the whole part. So the values are consistent and the function does not return None. In xˉ\bar{x}, 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 pj∗p^*_j of a part add up to the budgets of its buyers. The scaling of basic_prices therefore gives exactly p∗p^*. The prices p∗p^* are positive, add up to ∑iei\sum_i e_i, and the flow given by xˉ\bar{x} has value ∑iei\sum_i e_i, which is the largest possible, so the check accepts. Hence line L8 returns at the latest at phase kk, and by Claim 1 its answer is an equilibrium. ■\blacksquare

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 Δ=1/32\Delta = 1/32 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 nn calls of PriceAndAugment and that each call takes O(m+nlog⁡n)O(m + n \log n) 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 O(nlog⁡n)O(n \log n) phases and runs in O(n2log⁡n (m+nlog⁡n))O(n^2 \log n \, (m + n \log n)) time, which the abstract states in the weaker form O(n4log⁡n)O(n^4 \log n). Orlin also shows that an ε\varepsilon-approximate solution takes O(log⁡(n/ε))O(\log(n / \varepsilon)) phases.

The toy stores prices explicitly and recomputes the residual network with breadth-first search, so one price step costs O(nm)O(nm) and one call of PriceAndAugment O(n2m)O(n^2 m) 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 Δ\Delta.
  • Strongly polynomial. The number of operations of StrongScaling depends only on nn and mm. The numbers themselves are rational, and the bit lengths stay polynomial.
  • Abundant edges are permanent. Once an edge carries at least 3nΔ3n\Delta 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 11 and two goods with utilities 2K2^K and 11. The equilibrium spends 1/(2K+1)1/(2^K + 1) on the second good, and the scaling algorithm needs more than KK 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 O(log⁡(n/ε))O(\log(n / \varepsilon)) phases gives an ε\varepsilon-approximate solution in O(n(m+nlog⁡n)log⁡(n/ε))O(n (m + n \log n) \log(n / \varepsilon)) time.
  • Small utilities. When the utilities are bounded by a polynomial in nn, 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 O(n2log⁡Umax⁡)O(n^2 \log U_{\max}) 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 bjb_j reaches 00 leaves a raised good with bj<0b_j < 0, which breaks Δ\Delta-feasibility: the good is then sold for less than its price.
  • Sending more than Δ\Delta in line L6, for example all the money that the root has left, breaks the rule that flows are multiples of Δ\Delta and the bound of nn calls per phase.
  • Halving Δ\Delta in line L9 without lowering the flows into goods with bj>Δb_j > \Delta 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 Δ=1/32\Delta = 1/32 force (1,1,3)(1, 1, 3), 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.

orlin_fisher_market_algorithm.pyI0RawGitHub
# 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

  1. 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)
  2. 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)
  3. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example