Algorithm Search⌘K

Algorithmadvanced

Multicommodity flow global routing

Also called Albrecht global routing.

Global routing as fractional multicommodity flow, solved approximately by multiplicative length updates over shortest paths, then rounded to one route per net.

Time
O(T k E log V) worst
Space
O(E + T k V) extra
Where
E = the number of grid edges; T = the number of rounds; V = the number of gcells; k = the number of nets
Properties
randomizednot exactiterative
Origin
Christoph Albrecht, 2001

Multicommodity flow global routing solves the LP relaxation of global routing, in which each net may split over several routes, and then rounds it to one route per net. The relaxation is a fractional multicommodity flow that minimizes the congestion λ\lambda, the largest ratio of usage to capacity. This page solves it with multiplicative weights: each edge has a weight, each net takes a shortest route under lengths proportional to the weights, and the weights of the edges that the routes use grow by a factor. The average of the rounds is within a factor 1+ε1 + \varepsilon of the fractional optimum, up to an additive term that falls as 1/T1/T in the number of rounds TT, and each round also gives a proved lower bound. Randomized rounding then picks one route per net, and rip-up and reroute removes the overflow that remains.

In plain words

Suppose every net could split into many thin wires that take different roads. Then the best plan is easy to compute well, and it tells you how crowded the chip must be at least.

The method finds such a plan by playing many rounds. Each road has a price. In each round, every net takes its cheapest road. Then each road that was used gets a little more expensive, more so when many nets used it. Over many rounds, the nets spread over the roads, and the share of rounds in which a net took a road becomes the fraction of that net on it.

At the end, each net must take one real road. It draws one at random, with the chance of each road equal to its share. A few roads may then be too full, and a repair step moves some nets away.

The problem

Let G=(V,E)G = (V, E) be the routing graph with capacities ce>0c_e > 0, and let there be kk nets. Net ii has a set Ri\mathcal{R}_i of routes: all paths between its two pins, or a given list of candidate trees. The fractional problem is

λ∗=min⁡λsubject to∑P∈RixiP=1 (each net i),x≥0,∑i∑P∈Ri, P∋exiP≤λce (each edge e).\lambda^* = \min \lambda \quad \text{subject to} \quad \sum_{P \in \mathcal{R}_i} x_{iP} = 1 \ (\text{each net } i), \qquad x \ge 0, \qquad \sum_i \sum_{P \in \mathcal{R}_i,\ P \ni e} x_{iP} \le \lambda c_e \ (\text{each edge } e).

It is a linear program with one variable per route, which can be exponentially many, so the method only touches routes through an oracle that returns a shortest route of a net for given edge lengths. For two-pin nets the oracle is Dijkstra's algorithm. The integral problem, with each xiP∈{0,1}x_{iP} \in \{0, 1\}, is the minimum congestion form of global routing, and λ∗≤λint\lambda^* \le \lambda_{\mathrm{int}}.

The algorithm

The width is ρ=k/min⁡ece\rho = k / \min_e c_e. No edge carries more than kk nets, so loade/(ρce)≤1\mathrm{load}_e / (\rho c_e) \le 1 in every round. The step size ε∈(0,1]\varepsilon \in (0, 1] is a parameter.

  1. MCF-GLOBAL-ROUTE(G, c, nets, ε, T)
  2. 1w_e ← 1 for every edge e; ρ ← k / min_e c_e; LB ← 0
  3. 2for t ← 1 to T do
  4. 3ℓ_e ← w_e / (W c_e) for every e, where W = Σ_e w_e
  5. 4for each net i: P_i ← a shortest route of net i under ℓ (the oracle)
  6. 5count(i, P_i) ← count(i, P_i) + 1 for each i; load_e ← |{ i : e ∈ P_i }|
  7. 6LB ← max(LB, Σ_e ℓ_e · load_e)
  8. 7w_e ← w_e · (1 + ε · load_e / (ρ c_e)) for every e
  9. 8x_iP ← count(i, P) / T; λ_frac ← max_e (Σ_i Σ_{P ∋ e} x_iP) / c_e
  10. 9for each net i, independently: pick one route P with probability x_iP
  11. 10return x, λ_frac, LB and the picked routes

Lines L2 to L7 are the fractional solver. The lengths of line L3 satisfy ∑eℓece=1\sum_e \ell_e c_e = 1, so the value of line L6 is a lower bound on λ∗\lambda^* by weak duality. Line L8 averages the routes of the TT rounds. Line L9 is the rounding of Raghavan and Thompson.

Albrecht's router uses the method of Garg and Könemann with Fleischer's extensions, which routes the nets in phases with a step size and a stopping rule of its own. This page uses the averaged multiplicative weights form above, which has the same kind of guarantee and a short proof, and it is not Albrecht's exact procedure.

Example

Two crossing nets. Take the 2×22 \times 2 grid of gcells (x,y)(x, y) with capacity 1 on its 4 edges: bottom (0,0)(1,0)(0,0)(1,0), top (0,1)(1,1)(0,1)(1,1), left (0,0)(0,1)(0,0)(0,1) and right (1,0)(1,1)(1,0)(1,1). Net A joins (0,0)(0,0) and (1,1)(1,1), net B joins (1,0)(1,0) and (0,1)(0,1). Then k=2k = 2, ρ=2\rho = 2, and take ε=1/4\varepsilon = 1/4. A route of A meets each route of B in one edge, so λint=2\lambda_{\mathrm{int}} = 2.

round weights (bottom, top, left, right) route of A route of B loads ∑eℓeloade\sum_e \ell_e \mathrm{load}_e
1 1, 1, 1, 1 bottom, right bottom, left 2, 0, 1, 1 1
2 5/4, 1, 9/8, 9/8 top, left top, right 0, 2, 1, 1 17/18
3 5/4, 5/4, 81/64, 81/64 bottom, right bottom, left 2, 0, 1, 1 1
4 25/16, 5/4, 729/512, 729/512 top, left top, right 0, 2, 1, 1 1369/1449

In round 1 all lengths are 1/41/4, both routes of each net cost 1/21/2, and the ties go to the routes through the bottom edge. Its load is 2, so its weight becomes 1⋅(1+14⋅22)=5/41 \cdot (1 + \frac14 \cdot \frac22) = 5/4, and the left and right weights become 1+14⋅12=9/81 + \frac14 \cdot \frac12 = 9/8. In round 2 the routes through the top cost (1+9/8)/W(1 + 9/8)/W against (5/4+9/8)/W(5/4 + 9/8)/W through the bottom, so both nets switch. The rounds alternate. For every even TT the average gives each route weight 1/21/2, every edge has average load 1, and λfrac=1\lambda_{\mathrm{frac}} = 1. Round 1 gives LB=1\mathrm{LB} = 1, so λfrac=LB=λ∗=1\lambda_{\mathrm{frac}} = \mathrm{LB} = \lambda^* = 1: the lower bound proves that this fractional solution is optimal. The rounding picks one route per net, and every pick has congestion 2, the integral optimum. The gap between λ∗=1\lambda^* = 1 and λint=2\lambda_{\mathrm{int}} = 2 is the integrality gap of this instance.

Three nets on a 3×33 \times 3 grid. Take capacity 1 on all 12 edges and the nets (0,0)(0,0) to (2,2)(2,2), (2,0)(2,0) to (0,2)(0,2) and (1,0)(1,0) to (1,2)(1,2), with the Dijkstra oracle and ε=1/4\varepsilon = 1/4. All three nets must cross the 3 vertical edges between row 0 and row 1, so λ∗≥1\lambda^* \ge 1.

rounds TT λfrac\lambda_{\mathrm{frac}} LB
10 1 0.8547
40 1 0.9179
160 1 0.9965

So λ∗=1\lambda^* = 1 here, and the lower bound of line L6 approaches it as the weights settle. An exhaustive search over the 12, 12 and 9 simple paths of the three nets gives λint=2\lambda_{\mathrm{int}} = 2, and each rounding in these runs had congestion 2.

Correctness

The proof shows the following, for any route sets Ri\mathcal{R}_i for which the oracle returns a shortest route.

  • Feasible average. For each net, the weights xiPx_{iP} are nonnegative and add up to 1.
  • Lower bound. Each value ∑eℓeloade\sum_e \ell_e \mathrm{load}_e of line L6 is at most λ∗\lambda^*, so LB≤λ∗≤λfrac\mathrm{LB} \le \lambda^* \le \lambda_{\mathrm{frac}}.
  • Upper bound. λfrac≤εln⁡(1+ε)λ∗+ρln⁡∣E∣Tln⁡(1+ε)≤(1+ε)λ∗+ρln⁡∣E∣Tln⁡(1+ε)\lambda_{\mathrm{frac}} \le \frac{\varepsilon}{\ln(1 + \varepsilon)} \lambda^* + \frac{\rho \ln |E|}{T \ln(1 + \varepsilon)} \le (1 + \varepsilon) \lambda^* + \frac{\rho \ln |E|}{T \ln(1 + \varepsilon)}.
  • Rounds needed. For 0<ε≤10 < \varepsilon \le 1 and T≥2ρln⁡∣E∣/(ε2λ∗)T \ge 2 \rho \ln |E| / (\varepsilon^2 \lambda^*), λfrac≤(1+2ε)λ∗\lambda_{\mathrm{frac}} \le (1 + 2\varepsilon) \lambda^*.
  • Rounding. The expected load of each edge after rounding is its average load, at most λfracce\lambda_{\mathrm{frac}} c_e.
Proof: The averaged multiplicative weights solver gives a feasible fractional routing within a factor 1 + ε of optimal plus an additive term in 1/T, and a valid lower boundfull

Setting. G=(V,E)G = (V, E) has ∣E∣=M|E| = M edges with capacities ce>0c_e > 0. There are k≥1k \ge 1 nets, and net ii has a finite nonempty set Ri\mathcal{R}_i of routes, each a set of edges. For a choice of weights xx, the load of ee is loade(x)=∑i∑P∈Ri,P∋exiP\mathrm{load}_e(x) = \sum_i \sum_{P \in \mathcal{R}_i, P \ni e} x_{iP}. The fractional optimum is

λ∗=min⁡{λ:∑P∈RixiP=1 for all i, x≥0, loade(x)≤λce for all e}.\lambda^* = \min \{ \lambda : \textstyle\sum_{P \in \mathcal{R}_i} x_{iP} = 1 \text{ for all } i,\ x \ge 0,\ \mathrm{load}_e(x) \le \lambda c_e \text{ for all } e \}.

The feasible set is a nonempty polyhedron (take any one route per net and λ\lambda large), λ≥0\lambda \ge 0 on it, and the objective is linear, so the minimum is attained, by the existence of optimal vertices of linear programs. Fix an optimal x∗x^*.

The oracle returns, for nonnegative edge lengths ℓ\ell, a route P∈RiP \in \mathcal{R}_i with the least length ℓ(P)=∑e∈Pℓe\ell(P) = \sum_{e \in P} \ell_e. For the Dijkstra oracle, Ri\mathcal{R}_i is the set of simple paths between the two pins, and a shortest walk under positive lengths is a simple path, so Dijkstra's algorithm is such an oracle.

In round tt write wtw^t for the weights at line L3, Wt=∑ewetW^t = \sum_e w^t_e, ℓet=wet/(Wtce)\ell^t_e = w^t_e / (W^t c_e), PitP^t_i for the route of net ii, loadet=∣{i:e∈Pit}∣\mathrm{load}^t_e = |\{ i : e \in P^t_i \}|, and LBt=∑eℓetloadet\mathrm{LB}_t = \sum_e \ell^t_e \mathrm{load}^t_e. Let uet=loadet/(ρce)u^t_e = \mathrm{load}^t_e / (\rho c_e) with ρ=k/min⁡ece\rho = k / \min_e c_e.

Lemma 1 (feasible average). For each net ii, the weights xiP=count(i,P)/Tx_{iP} = \mathrm{count}(i, P) / T of line L8 are nonnegative, they are positive only on routes of Ri\mathcal{R}_i, and they add up to 1. Moreover loade(x)=1T∑t=1Tloadet\mathrm{load}_e(x) = \frac{1}{T} \sum_{t=1}^{T} \mathrm{load}^t_e.

Proof. Each of the TT rounds adds 1 to exactly one counter of net ii, at a route returned by the oracle, so the counters of net ii add up to TT. For the load, loade(x)=1T∑i∑P∋ecount(i,P)\mathrm{load}_e(x) = \frac1T \sum_i \sum_{P \ni e} \mathrm{count}(i, P), and ∑P∋ecount(i,P)\sum_{P \ni e} \mathrm{count}(i, P) is the number of rounds in which the route of net ii contains ee. Summing over ii and exchanging the sums gives 1T∑tloadet\frac1T \sum_t \mathrm{load}^t_e. □\square

Lemma 2 (lower bound). For every round tt, LBt≤λ∗\mathrm{LB}_t \le \lambda^*. Hence LB=max⁡tLBt≤λ∗≤λfrac\mathrm{LB} = \max_t \mathrm{LB}_t \le \lambda^* \le \lambda_{\mathrm{frac}}.

Proof. The lengths satisfy ∑eℓetce=∑ewet/Wt=1\sum_e \ell^t_e c_e = \sum_e w^t_e / W^t = 1. Since ℓetloadet\ell^t_e \mathrm{load}^t_e sums the length of each edge once for each route on it, LBt=∑iℓt(Pit)=∑imin⁡P∈Riℓt(P)\mathrm{LB}_t = \sum_i \ell^t(P^t_i) = \sum_i \min_{P \in \mathcal{R}_i} \ell^t(P). A minimum is at most any weighted average with weights that add up to 1, so

LBt≤∑i∑P∈RixiP∗ ℓt(P)=∑eℓet loade(x∗)≤∑eℓet λ∗ce=λ∗.\mathrm{LB}_t \le \sum_i \sum_{P \in \mathcal{R}_i} x^*_{iP}\, \ell^t(P) = \sum_e \ell^t_e\, \mathrm{load}_e(x^*) \le \sum_e \ell^t_e\, \lambda^* c_e = \lambda^*.

The middle equality exchanges the sums over routes and edges. The last inequality uses ℓet≥0\ell^t_e \ge 0 and the constraint loade(x∗)≤λ∗ce\mathrm{load}_e(x^*) \le \lambda^* c_e. By Lemma 1, xx is feasible with λ=λfrac\lambda = \lambda_{\mathrm{frac}}, so λ∗≤λfrac\lambda^* \le \lambda_{\mathrm{frac}}. □\square

This is weak duality for the dual λ∗=max⁡ℓ≥0, ∑eℓece=1∑imin⁡Pℓ(P)\lambda^* = \max_{\ell \ge 0,\ \sum_e \ell_e c_e = 1} \sum_i \min_P \ell(P) of the problem; only the direction "at most" is needed here.

Lemma 3 (width). 0≤uet≤10 \le u^t_e \le 1 for all tt and ee.

Proof. 0≤loadet≤k0 \le \mathrm{load}^t_e \le k, since each net puts at most one route on ee, and ρce≥ρmin⁡ece=k\rho c_e \ge \rho \min_e c_e = k. □\square

Lemma 4. For ε>0\varepsilon > 0 and u∈[0,1]u \in [0, 1], (1+ε)u≤1+εu(1 + \varepsilon)^u \le 1 + \varepsilon u.

Proof. The function f(u)=(1+ε)uf(u) = (1 + \varepsilon)^u is convex, with f(0)=1f(0) = 1 and f(1)=1+εf(1) = 1 + \varepsilon. A convex function lies below its chord on [0,1][0, 1], so f(u)≤(1−u)⋅1+u(1+ε)=1+εuf(u) \le (1 - u) \cdot 1 + u (1 + \varepsilon) = 1 + \varepsilon u. □\square

Theorem (upper bound). For 0<ε≤10 < \varepsilon \le 1 and T≥1T \ge 1,

λfrac ≤ εln⁡(1+ε) λ∗+ρln⁡MTln⁡(1+ε) ≤ (1+ε) λ∗+ρln⁡MTln⁡(1+ε).\lambda_{\mathrm{frac}} \ \le\ \frac{\varepsilon}{\ln(1 + \varepsilon)}\, \lambda^* + \frac{\rho \ln M}{T \ln(1 + \varepsilon)} \ \le\ (1 + \varepsilon)\, \lambda^* + \frac{\rho \ln M}{T \ln(1 + \varepsilon)}.

Proof. Line L7 sets wet+1=wet(1+εuet)w^{t+1}_e = w^t_e (1 + \varepsilon u^t_e). Sum over ee and write pet=wet/Wtp^t_e = w^t_e / W^t:

Wt+1=Wt(1+ε∑epetuet).W^{t+1} = W^t \Big( 1 + \varepsilon \sum_e p^t_e u^t_e \Big).

Here ∑epetuet=1ρ∑ewetWtceloadet=LBt/ρ≤λ∗/ρ\sum_e p^t_e u^t_e = \frac{1}{\rho} \sum_e \frac{w^t_e}{W^t c_e} \mathrm{load}^t_e = \mathrm{LB}_t / \rho \le \lambda^* / \rho by Lemma 2. With 1+z≤ez1 + z \le e^z and W1=MW^1 = M,

WT+1≤Mexp⁡(ερ∑t=1TLBt)≤Mexp⁡(εTλ∗ρ).W^{T+1} \le M \exp\Big( \frac{\varepsilon}{\rho} \sum_{t=1}^{T} \mathrm{LB}_t \Big) \le M \exp\Big( \frac{\varepsilon T \lambda^*}{\rho} \Big).

For one edge ee, let Se=∑t=1TuetS_e = \sum_{t=1}^{T} u^t_e. By Lemmas 3 and 4, weT+1=∏t(1+εuet)≥∏t(1+ε)uet=(1+ε)Sew^{T+1}_e = \prod_t (1 + \varepsilon u^t_e) \ge \prod_t (1 + \varepsilon)^{u^t_e} = (1 + \varepsilon)^{S_e}. All weights are positive, so weT+1≤WT+1w^{T+1}_e \le W^{T+1}. Take logarithms:

Seln⁡(1+ε)≤ln⁡M+εTλ∗ρ.S_e \ln(1 + \varepsilon) \le \ln M + \frac{\varepsilon T \lambda^*}{\rho}.

By Lemma 1, loade(x)/ce=1T∑tloadet/ce=ρSe/T\mathrm{load}_e(x) / c_e = \frac{1}{T} \sum_t \mathrm{load}^t_e / c_e = \rho S_e / T. Multiply the inequality by ρ/(Tln⁡(1+ε))\rho / (T \ln(1 + \varepsilon)):

loade(x)ce≤ρln⁡MTln⁡(1+ε)+εln⁡(1+ε)λ∗.\frac{\mathrm{load}_e(x)}{c_e} \le \frac{\rho \ln M}{T \ln(1 + \varepsilon)} + \frac{\varepsilon}{\ln(1 + \varepsilon)} \lambda^*.

This holds for every edge, so it holds for the maximum, λfrac\lambda_{\mathrm{frac}}. For the second form, ln⁡(1+ε)=∫0εds1+s≥ε1+ε\ln(1 + \varepsilon) = \int_0^\varepsilon \frac{ds}{1 + s} \ge \frac{\varepsilon}{1 + \varepsilon}, so εln⁡(1+ε)≤1+ε\frac{\varepsilon}{\ln(1 + \varepsilon)} \le 1 + \varepsilon. □\square

Corollary (rounds needed). If 0<ε≤10 < \varepsilon \le 1, λ∗>0\lambda^* > 0 and T≥2ρln⁡M/(ε2λ∗)T \ge 2 \rho \ln M / (\varepsilon^2 \lambda^*), then λfrac≤(1+2ε)λ∗\lambda_{\mathrm{frac}} \le (1 + 2 \varepsilon) \lambda^*.

Proof. From the last step, ln⁡(1+ε)≥ε/(1+ε)≥ε/2\ln(1 + \varepsilon) \ge \varepsilon / (1 + \varepsilon) \ge \varepsilon / 2 for ε≤1\varepsilon \le 1. So the additive term is at most 2ρln⁡M/(Tε)≤ελ∗2 \rho \ln M / (T \varepsilon) \le \varepsilon \lambda^*. Add it to (1+ε)λ∗(1 + \varepsilon) \lambda^*. □\square

Lemma 5 (rounding). Line L9 picks route PP for net ii with probability xiPx_{iP}, independently over the nets. Then the expected load of edge ee after rounding is loade(x)≤λfracce\mathrm{load}_e(x) \le \lambda_{\mathrm{frac}} c_e, and the load is a sum of kk independent 0-1 variables, one per net.

Proof. The indicator that net ii uses ee has expectation ∑P∋exiP\sum_{P \ni e} x_{iP}. Sum over ii by linearity of expectation. Independence holds because each net draws its own random number. □\square

With unit capacities, Lemma 5 is the only input that the analysis on the randomized rounding page needs, with λfrac\lambda_{\mathrm{frac}} in place of the LP optimum. It gives congestion O(log⁡M/log⁡log⁡M)⋅max⁡(λfrac,1)O(\log M / \log \log M) \cdot \max(\lambda_{\mathrm{frac}}, 1) with high probability.

Complexity

  • One round. kk oracle calls, each a Dijkstra search in O(Elog⁡V)O(E \log V) time with a binary heap, and O(E)O(E) for the weights and lengths. So a round costs O(kElog⁡V)O(k E \log V).
  • All rounds. O(TkElog⁡V)O(T k E \log V). The bound above needs T=O(ρlog⁡E/(ε2λ∗))T = O(\rho \log E / (\varepsilon^2 \lambda^*)) rounds for a (1+2ε)(1 + 2\varepsilon) factor. This number depends on the width ρ\rho, so it is pseudo-polynomial when capacities are small and nets are many. The method of Garg and Könemann, with variable steps, removes the dependence on the width.
  • Space. O(E)O(E) for the weights, and one counter for each distinct route that the oracle returns, at most TT per net, each with up to VV edges.
  • Rounding. O(kT)O(k T) to pick the routes from the counters.
  • Exact arithmetic. The test implementation uses fractions, whose size grows with TT. Real routers use floating point and normalize the weights.

Properties

  • What is proved. The fractional solution is within the factor and the additive term above, and the lower bound is valid. For two-pin nets with unit capacities, randomized rounding gives congestion O(log⁡∣E∣/log⁡log⁡∣E∣)⋅max⁡(λfrac,1)O(\log |E| / \log \log |E|) \cdot \max(\lambda_{\mathrm{frac}}, 1) with high probability, by the proof on the randomized rounding page, which uses only the bound on the expected load of each edge.
  • A certificate. λfrac/LB\lambda_{\mathrm{frac}} / \mathrm{LB} is a proved bound on how far the fractional solution is from optimal, computed during the run.
  • What is measured. The final quality after rounding and repair is measured on benchmarks. The integral solution can be twice the fractional optimum or more, as in the examples above, and the repair stage has no proof.
  • Randomized. The fractional part is deterministic for a fixed tie rule. The rounding uses random choices, with a fixed seed in the implementation.
  • Splittable by design. Each round adds at most one route per net, so after TT rounds a net uses at most TT routes, often far fewer.

Variants and improvements

  • Garg and Könemann steps. Increase the lengths along one shortest route at a time, with a step that depends on the bottleneck capacity of that route, and stop when the dual value reaches a threshold. This removes the width from the number of steps.
  • Multi-pin nets. Let Ri\mathcal{R}_i be the Steiner trees of net ii and let the oracle return a cheapest tree. A minimum Steiner tree is NP-hard to find, so routers use a heuristic tree, and then the factor of the method is multiplied by the ratio of the heuristic.
  • Exact LP. For small instances, solve the path LP with column generation by the simplex method, with the same shortest path oracle as the pricing step.
  • Derandomized rounding. Replace line L9 by the method of conditional expectations with a pessimistic estimator, which gives the same congestion bound without random choices.
  • Negotiation after rounding. Feed the rounded routes to negotiated congestion routing, which removes the remaining overflow.

When to use it

  • When a proved lower bound on congestion is wanted, to know how far a routing is from the best possible.
  • When the nets are many and the grid is crowded, so that the order of a sequential router matters much.
  • As a start for a rip-up and reroute stage, since the rounded routes spread the nets well.

When speed is the first goal and the congestion is mild, pattern routing and negotiated congestion routing are simpler and faster.

Pitfalls

  • Treating λfrac\lambda_{\mathrm{frac}} as the answer. It is the congestion of a split routing. A real routing can need much more, and the rounding can make edges overflow.
  • Wrong width. If ρ\rho is too small, some loade/(ρce)\mathrm{load}_e / (\rho c_e) exceeds 1 and the proof fails. If it is much too large, the run needs many more rounds.
  • Edges of capacity 0. The lengths divide by cec_e. Remove such edges from the graph before the run, or give them a huge length.
  • Oracle that is not shortest. The lower bound needs the oracle to return a true shortest route. A heuristic Steiner tree oracle gives a weaker bound.
  • Few rounds. The additive term ρln⁡∣E∣/(Tln⁡(1+ε))\rho \ln |E| / (T \ln(1 + \varepsilon)) can dominate. In the crossing example with T=10T = 10 it is about 1.24, so the proved bound is about 2.36 while the true value is 1.
  • Rounding many nets on thin edges. The rounding bound is weakest when the expected load of each edge is small, as on edges of capacity 1 or 2. Large overflow after rounding is common on crowded grids, and the repair step does the rest.

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.

multicommodity_flow_global_routing.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multicommodity-flow-global-routing/. The authors are listed in prov/6WN748.jsonl.

"""Global routing as a fractional multicommodity flow, then randomized rounding.

The routing graph has nodes 0 .. n_nodes - 1 and undirected edges (u, v),
each with a positive capacity. A net has one route out of a set of routes:
all paths between its two pins (the Dijkstra oracle), or an explicit list
of candidate routes. The fractional problem is the linear program

    minimize lam  subject to  sum_P x[i][P] = 1 for each net i,
                              x >= 0,
                              load_e(x) <= lam * c_e for each edge e.

The solver is the averaged multiplicative weights method with a shortest
route oracle, in the style of Garg and Koenemann. All arithmetic is exact.
"""

import heapq
import random
from fractions import Fraction
from typing import Optional, Sequence

Edge = tuple[int, int]
Route = frozenset[int]


def grid_graph(width: int, height: int) -> tuple[int, list[Edge]]:
    """Grid of width * height gcells. Node (x, y) has the index y * width + x."""
    edges = []
    for y in range(height):
        for x in range(width - 1):
            edges.append((y * width + x, y * width + x + 1))
    for y in range(height - 1):
        for x in range(width):
            edges.append((y * width + x, (y + 1) * width + x))
    return width * height, edges


def shortest_route(n_nodes: int, edges: Sequence[Edge], length: Sequence[Fraction], s: int, t: int) -> Route:
    """Dijkstra from s to t. Ties go to the smaller node index. Returns the edge set of the path."""
    adj: list[list[tuple[int, int]]] = [[] for _ in range(n_nodes)]
    for e, (u, v) in enumerate(edges):
        adj[u].append((v, e))
        adj[v].append((u, e))
    dist = {s: Fraction(0)}
    prev: dict[int, tuple[int, int]] = {}
    heap = [(Fraction(0), s)]
    done = set()
    while heap:
        d, u = heapq.heappop(heap)
        if u in done:
            continue
        done.add(u)
        if u == t:
            break
        for v, e in sorted(adj[u]):
            nd = d + length[e]
            if v not in dist or nd < dist[v]:
                dist[v] = nd
                prev[v] = (u, e)
                heapq.heappush(heap, (nd, v))
    if t not in done:
        raise ValueError("the pins of a net are not connected")
    route = set()
    v = t
    while v != s:
        u, e = prev[v]
        route.add(e)
        v = u
    return frozenset(route)


def congestion(routes: Sequence[Route], caps: Sequence[int]) -> Fraction:
    """Largest ratio load / capacity over all edges for one route per net."""
    load = [0] * len(caps)
    for r in routes:
        for e in r:
            load[e] += 1
    return max((Fraction(l, c) for l, c in zip(load, caps)), default=Fraction(0))


def multicommodity_flow_global_routing(
    n_nodes: int,
    edges: Sequence[Edge],
    caps: Sequence[int],
    nets: Sequence[tuple[int, int]],
    eps: Fraction = Fraction(1, 4),
    rounds: int = 200,
    candidates: Optional[Sequence[Sequence[Route]]] = None,
    seed: int = 0,
) -> dict:
    """Return a dict with the keys
    x: for each net, a dict that maps a route to its weight (the weights add up to 1),
    lam_frac: the congestion of x, lower_bound: a proven lower bound on the fractional
    optimum, rho: the width, routes: one route per net after randomized rounding, and
    lam_int: the congestion of the rounded routes.
    With candidates, net i chooses from candidates[i] and nets is not used for routing.
    """
    m = len(edges)
    if any(c <= 0 for c in caps) or len(caps) != m:
        raise ValueError("one positive capacity per edge is needed")
    k = len(candidates) if candidates is not None else len(nets)
    if k == 0 or rounds < 1:
        raise ValueError("at least one net and one round are needed")

    def oracle(i: int, length: list[Fraction]) -> Route:
        if candidates is None:
            s, t = nets[i]
            return shortest_route(n_nodes, edges, length, s, t)
        best = None
        for r in candidates[i]:
            key = sum((length[e] for e in r), Fraction(0))
            if best is None or key < best[0]:
                best = (key, r)
        assert best is not None
        return best[1]

    w = [Fraction(1)] * m  # @line L1
    rho = Fraction(k, min(caps))
    counts: list[dict[Route, int]] = [{} for _ in range(k)]
    lower_bound = Fraction(0)
    for _ in range(rounds):  # @line L2
        total = sum(w)
        length = [w[e] / (total * caps[e]) for e in range(m)]  # @line L3
        load = [0] * m
        for i in range(k):
            r = oracle(i, length)  # @line L4
            counts[i][r] = counts[i].get(r, 0) + 1  # @line L5
            for e in r:
                load[e] += 1
        lower_bound = max(lower_bound, sum((length[e] * load[e] for e in range(m)), Fraction(0)))  # @line L6
        w = [w[e] * (1 + eps * load[e] / (rho * caps[e])) for e in range(m)]  # @line L7

    x = [{r: Fraction(c, rounds) for r, c in cnt.items()} for cnt in counts]  # @line L8
    avg = [Fraction(0)] * m
    for xi in x:
        for r, f in xi.items():
            for e in r:
                avg[e] += f
    lam_frac = max(avg[e] / caps[e] for e in range(m))

    rng = random.Random(seed)
    routes = []
    for cnt in counts:  # @line L9
        pick = rng.randrange(rounds)
        for r, c in cnt.items():
            if pick < c:
                routes.append(r)
                break
            pick -= c
    return {  # @line L10
        "x": x,
        "lam_frac": lam_frac,
        "lower_bound": lower_bound,
        "rho": rho,
        "routes": routes,
        "lam_int": congestion(routes, caps),
    }
test_multicommodity_flow_global_routing.py 157 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multicommodity-flow-global-routing/. The authors are listed in prov/6WN748.jsonl.

import itertools
import math
import random
from fractions import Fraction
from typing import Optional

from multicommodity_flow_global_routing import (
    congestion,
    grid_graph,
    multicommodity_flow_global_routing,
    shortest_route,
)


def solve(a: list[list[Fraction]], b: list[Fraction]) -> Optional[list[Fraction]]:
    """Gauss-Jordan elimination in exact arithmetic. None if the matrix is singular."""
    n = len(a)
    mat = [row[:] + [bb] for row, bb in zip(a, b)]
    for c in range(n):
        p = next((r for r in range(c, n) if mat[r][c] != 0), None)
        if p is None:
            return None
        mat[c], mat[p] = mat[p], mat[c]
        for r in range(n):
            if r != c and mat[r][c] != 0:
                f = mat[r][c] / mat[c][c]
                mat[r] = [x - f * y for x, y in zip(mat[r], mat[c])]
    return [mat[i][n] / mat[i][i] for i in range(n)]


def lp_optimum(caps: list[int], cands: list[list[frozenset[int]]]) -> Fraction:
    """Fractional optimum lam* by enumeration of the vertices of the LP
    min lam s.t. sum_P x_iP = 1, x >= 0, load_e(x) <= lam c_e."""
    var = [(i, j) for i in range(len(cands)) for j in range(len(cands[i]))]
    n = len(var) + 1
    rows: dict[tuple[int, ...], int] = {}
    for e, c in enumerate(caps):
        inc = tuple(int(e in cands[i][j]) for i, j in var)
        if any(inc):
            rows[inc] = min(rows.get(inc, c), c)  # edges with the same users: the smallest capacity binds
    eqs = [([Fraction(int(vi == i)) for vi, _ in var] + [Fraction(0)], Fraction(1)) for i in range(len(cands))]
    ineqs = [([Fraction(-int(q == r)) for r in range(len(var))] + [Fraction(0)], Fraction(0)) for q in range(len(var))]
    ineqs += [([Fraction(v) for v in inc] + [Fraction(-c)], Fraction(0)) for inc, c in rows.items()]
    best = None
    for tight in itertools.combinations(range(len(ineqs)), n - len(eqs)):
        sol = solve([r for r, _ in eqs] + [ineqs[s][0] for s in tight], [v for _, v in eqs] + [ineqs[s][1] for s in tight])
        if sol is None:
            continue
        if all(sum((p * q for p, q in zip(row, sol)), Fraction(0)) <= rhs for row, rhs in ineqs):
            if best is None or sol[-1] < best:
                best = sol[-1]
    assert best is not None
    return best


def simple_paths(n_nodes: int, edges: list[tuple[int, int]], s: int, t: int) -> list[frozenset[int]]:
    adj: list[list[tuple[int, int]]] = [[] for _ in range(n_nodes)]
    for e, (u, v) in enumerate(edges):
        adj[u].append((v, e))
        adj[v].append((u, e))
    out = []

    def go(u: int, seen: set[int], used: list[int]) -> None:
        if u == t:
            out.append(frozenset(used))
            return
        for v, e in adj[u]:
            if v not in seen:
                go(v, seen | {v}, used + [e])

    go(s, {s}, [])
    return out


def integral_optimum(caps: list[int], cands: list[list[frozenset[int]]]) -> Fraction:
    return min(congestion(list(c), caps) for c in itertools.product(*cands))


def upper_bound(lam: Fraction, rho: Fraction, m: int, eps: Fraction, rounds: int) -> float:
    e = float(eps)
    return e / math.log1p(e) * float(lam) + float(rho) * math.log(m) / (rounds * math.log1p(e))


def check_run(r: dict, caps: list[int], cands: list[list[frozenset[int]]], eps: Fraction, rounds: int) -> None:
    lam = lp_optimum(caps, cands)
    for xi, ci in zip(r["x"], cands):
        assert sum(xi.values()) == 1 and set(xi) <= set(ci)
    assert r["lower_bound"] <= lam <= r["lam_frac"]
    assert float(r["lam_frac"]) <= upper_bound(lam, r["rho"], len(caps), eps, rounds) + 1e-12
    assert r["lam_int"] >= integral_optimum(caps, cands) >= lam
    assert all(route in ci for route, ci in zip(r["routes"], cands))


def test_example_two_crossing_nets() -> None:
    n, edges = grid_graph(2, 2)
    caps = [1, 1, 1, 1]
    nets = [(0, 3), (1, 2)]
    r = multicommodity_flow_global_routing(n, edges, caps, nets, eps=Fraction(1, 4), rounds=10)
    half = Fraction(1, 2)
    assert r["x"] == [{frozenset({0, 3}): half, frozenset({1, 2}): half}, {frozenset({0, 2}): half, frozenset({1, 3}): half}]
    assert r["lam_frac"] == 1 and r["lower_bound"] == 1 and r["rho"] == 2
    cands = [simple_paths(n, edges, s, t) for s, t in nets]
    assert lp_optimum(caps, cands) == 1
    assert integral_optimum(caps, cands) == 2 == r["lam_int"]


def test_oracle_is_shortest() -> None:
    rng = random.Random(5)
    n, edges = grid_graph(3, 3)
    for _ in range(40):
        length = [Fraction(rng.randrange(1, 9), rng.randrange(1, 5)) for _ in edges]
        s, t = rng.sample(range(n), 2)
        got = shortest_route(n, edges, length, s, t)
        best = min(sum(length[e] for e in p) for p in simple_paths(n, edges, s, t))
        assert sum(length[e] for e in got) == best
        assert got in simple_paths(n, edges, s, t)


def test_dijkstra_oracle_against_lp() -> None:
    rng = random.Random(2)
    n, edges = grid_graph(2, 2)
    eps = Fraction(1, 4)
    for _ in range(6):
        caps = [rng.choice([1, 2]) for _ in edges]
        nets = [tuple(rng.sample(range(n), 2)) for _ in range(rng.choice([2, 3]))]
        rounds = 60
        r = multicommodity_flow_global_routing(n, edges, caps, nets, eps=eps, rounds=rounds, seed=1)
        check_run(r, caps, [simple_paths(n, edges, s, t) for s, t in nets], eps, rounds)


def test_candidate_oracle_against_lp() -> None:
    rng = random.Random(4)
    n, edges = grid_graph(3, 3)
    eps = Fraction(1, 5)
    for _ in range(6):
        caps = [rng.choice([1, 1, 2]) for _ in edges]
        cands = []
        for _ in range(3):
            s, t = rng.sample(range(n), 2)
            cands.append(rng.sample(simple_paths(n, edges, s, t), 2))
        rounds = 60
        r = multicommodity_flow_global_routing(n, edges, caps, [], eps=eps, rounds=rounds, candidates=cands, seed=3)
        check_run(r, caps, cands, eps, rounds)


def test_bad_input() -> None:
    n, edges = grid_graph(2, 1)
    for caps, nets in (([0], [(0, 1)]), ([1], [])):
        try:
            multicommodity_flow_global_routing(n, edges, caps, nets)
        except ValueError:
            pass
        else:
            raise AssertionError("bad input was accepted")

History

Raghavan and Thompson (1987) wrote global wiring as a 0-1 multicommodity flow, solved its linear relaxation and rounded it at random, which gave the first congestion bound for the rounded routing. Approximation schemes for fractional multicommodity flow with shortest path oracles followed, among them the method of Garg and Könemann (FOCS 1998, journal version 2007) and its speedup by Fleischer. Albrecht (ISPD 2000 and IEEE TCAD 2001) used this method for chip global routing, followed by rounding to one route per net.

References

  1. Christoph Albrecht, Global routing by new approximation algorithms for multicommodity flow, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 20(5), 622 to 632, 2001, the approximation algorithm for the fractional global routing problem, based on the method of Garg and Könemann with Fleischer's extensions, and the rounding to one route per net (general locator)
  2. Christoph Albrecht, Provably good global routing by a new approximation algorithm for multicommodity flow, Proceedings of the International Symposium on Physical Design (ISPD), 19 to 25, 2000, the conference version (general locator)
  3. Naveen Garg and Jochen Könemann, Faster and simpler algorithms for multicommodity flow and other fractional packing problems, SIAM Journal on Computing 37(2), 630 to 652, 2007, the length-function method, with multiplicative length updates along shortest paths and the dual bound
  4. Prabhakar Raghavan and Clark D. Thompson, Randomized rounding, a technique for provably good algorithms and algorithmic proofs, Combinatorica 7(4), 365 to 374, 1987, the 0-1 multicommodity flow form of global wiring, its linear relaxation and the bound after randomized rounding
  5. Sanjeev Arora, Elad Hazan and Satyen Kale, The multiplicative weights update method, a meta-algorithm and applications, Theory of Computing 8, 121 to 164, 2012, the multiplicative weights method for packing and covering linear programs with an oracle, and the role of the width

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