Algorithmadvanced
Bounded-radius bounded-cost tree
Also called BRBC.
Cong and coauthors' routing tree that walks the MST and adds shortcuts to the source, so the radius is within 1 + eps of optimal and the cost within 1 + 2/eps of the MST.
- Time
- Θ(n^2) worst
- Space
- Θ(n) extra
- Where
- n = the number of pins
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jason Cong, Andrew B. Kahng, Gabriel Robins, Majid Sarrafzadeh, C. K. Wong, 1992
The bounded-radius bounded-cost (BRBC) tree of Jason Cong, Andrew Kahng, Gabriel Robins, Majid Sarrafzadeh and C. K. Wong is a routing tree for a net in electronic design automation (EDA) with proved bounds on both its length and its longest path from the source. Given a parameter , it walks around the minimum spanning tree of the pins and, whenever the walk has gone more than since the last shortcut, adds a direct edge from the source to the current pin, where is the largest distance from the source to a pin. A shortest path tree of the result has radius at most and cost at most times the minimum spanning tree. Small gives short paths and more wire; large gives a tree close to the minimum spanning tree.
In plain words
The driver of a net sends a signal to many sinks. The minimum spanning tree uses the least wire, but a sink can be far from the driver along the tree. A direct wire to every sink gives the shortest paths, but too much wire.
Start with the minimum spanning tree. Walk around it, along every edge down and back up, as you would trace its outline with a pencil. Keep a counter of how far you have walked. When the counter passes , add a wire straight from the driver to the sink you are at, and reset the counter.
Every sink is then close, along the walk, to a sink with a direct wire, so its path from the driver is short. The walk has a fixed length, twice the spanning tree, so not many direct wires are added, and the extra wire is limited too.
The problem
The input is a set of points with a source , and a metric , in routing the L1 distance. For a tree rooted at , the cost is the sum of its edge lengths and the radius is the largest path length from to a point in the tree. Let , a lower bound on the radius of every tree, and let be the cost of a minimum spanning tree, a lower bound on the cost of every spanning tree. Given , the task is a spanning tree with radius at most and cost within a constant factor of that depends only on .
The algorithm
BRBC(points, s, ε)- 1
Q ← a minimum spanning tree of the points; R ← max_v dist(s, v) - 2
run ← 0 - 3
for each step from u to v of the depth-first tour of Q from s do - 4
run ← run + dist(u, v) - 5
if run > ε · R then - 6
if v ≠ s and v has no edge to s yet then add the edge (s, v) to Q - 7
run ← 0 - 8
return a shortest path tree from s in the graph Q, found with Dijkstra's algorithm
The depth-first tour goes down each tree edge to a child and back up, so it has steps and length . The graph after line L7 is the tree plus at most shortcuts, so the shortest path tree of line L8 is cheap to find.
Example
Take nine points that run up, across and down, with the source at the bottom left:
, , , , , , , , .
The minimum spanning tree is the chain with cost 27, and , the distance to . In the chain, is 27 away from the source. Take , so the threshold is 18.
| step of the tour | run after the step | action |
|---|---|---|
| to | 4, 8, 12, 15, 18 | none, 18 is not more than 18 |
| to | 21 | add of length 15, reset |
| to , back to | 3, 6, 9, 12, 15, 18 | none |
| to | 21 | add of length 12, reset |
| back to | 4, 8, 12 | none |
The shortest path tree of the chain plus the two shortcuts gives the path lengths , so the radius is 21, within the bound . Its edges are , , , , , , and , of cost 47, within the bound .
| shortcuts to | cost | radius | |
|---|---|---|---|
| 1/4 | 61 | 18 | |
| 1/2 | 63 | 18 | |
| 1 | 47 | 21 | |
| 2 | 39 | 27 | |
| 100 | none | 27 | 27 |
A smaller is not always cheaper for the same radius: adds four shortcuts and costs more than . The Prim-Dijkstra tradeoff with reaches radius 18 here at cost 33.
Correctness
The proof shows the following.
- A spanning tree. The graph is connected, since it contains the minimum spanning tree, so the shortest path tree of line L8 spans all points.
- Radius. Every point is reached on the tour at a moment when the run since the last reset is at most . The last reset happened at the source or at a point with an edge to the source, so , and the tree path from to is no longer than that part of the tour. So .
- Cost. Each shortcut uses up a part of the tour of length more than , and these parts do not overlap. The tour has length , so there are fewer than shortcuts, each of length at most . The shortest path tree is a subgraph of , so its cost is at most .
Proof: The BRBC tree has radius at most (1 + ε) R and cost at most (1 + 2/ε) times the minimum spanning treefull
Let the points have source and a metric . Let be the minimum spanning tree of line L1 with cost , let , and fix . The depth-first tour of from is the sequence of points in which each step goes along a tree edge, down to a child or back up to the parent. Each tree edge is used twice, so the tour has length , and every point appears in it. Let be the graph at line L8, and let be the distance from to in , which is the path length in the shortest path tree of line L8.
Lemma 1 (spanning tree). The output is a spanning tree of all points rooted at , and its path lengths are .
Proof. contains , so it is connected. Dijkstra's algorithm from on the connected graph with lengths that are not negative gives a shortest path tree that spans all points, with path lengths .
Lemma 2 (reset points). Call a reset point if line L7 runs after the step to , and also call a reset point. Every reset point has .
Proof. If , then . Otherwise line L6 makes sure that has the edge , either added now or before, so .
Lemma 3 (tour segments). If and with are points of the tour, then the distance between them in is at most the length of the tour from to .
Proof. The tour from to is a walk in between these points, and the tree path is the shortest walk in a tree, since every walk between two vertices of a tree uses each edge of the path between them.
Theorem 1 (radius). For every point , .
Proof. Let be the first time the tour reaches , and let , , be the last reset point at or before position . If , Lemma 2 gives . Otherwise no reset happened after the steps to , so after each of these steps the run was at most . The run after the step to is the length of the tour from to , so this length is at most . By Lemma 3 and since , , using Lemma 2.
Theorem 2 (cost). The output costs at most .
Proof. Let the reset points other than be in tour order, and set . The run is reset after each, so the tour from to has length more than , by the test of line L5. These parts of the tour do not overlap, so when , and in all cases. Each shortcut is added at a reset point, at most one per reset, and has length . So the total length of is at most . The output tree is a subgraph of , so it costs no more. If , all points coincide with , every cost is 0, and the bound holds.
Running time. Line L1 takes with Prim's algorithm on all pairs. The tour has steps, each with a stack. has at most edges, so Dijkstra's algorithm with a binary heap takes . The total is time and space.
Complexity
- Time. The minimum spanning tree with Prim's algorithm on all pairs takes . The tour has steps of each. Dijkstra's algorithm with a binary heap on , which has at most edges, takes . The total is , or with the rectilinear minimum spanning tree in the L1 metric.
- Space. The tree, the shortcuts, the tour stack and the distances take .
Properties
- What is proved. For every the result is a spanning tree with radius at most and cost at most . As the radius goes to , and as the cost bound goes to .
- The tradeoff is real. Some point sets have no tree that is near both lower bounds at once. For the source at and the points for , every point is at distance from the source, so a tree of radius exactly must join each point straight to the source and costs , while the minimum spanning tree costs .
- What is measured. On 100 random nets of 30 points with coordinates from 0 to 999, the source being the first point (Python
random.Random(2027)):
| mean cost / MST | worst cost / MST | mean radius / | worst radius / | |
|---|---|---|---|---|
| 1/4 | 2.670 | 3.584 | 1.030 | 1.202 |
| 1/2 | 2.106 | 2.571 | 1.049 | 1.224 |
| 1 | 1.617 | 1.919 | 1.102 | 1.439 |
| 2 | 1.307 | 1.522 | 1.256 | 2.017 |
All values are within the proved bounds, and far inside the cost bound. On the same nets the Prim-Dijkstra tree with had a mean cost ratio of 1.150 and a mean radius ratio of 1.054. These are toy inputs, not benchmark results.
- Deterministic. The tour visits children in the order of their index, and ties in the shortest path tree go to the first path found.
Variants and improvements
- Steiner trees. The output is a spanning tree. Routers turn it into a rectilinear Steiner tree by merging overlapping wires, which lowers the cost and does not make any path longer, so both bounds still hold.
- Per-sink bounds. Later constructions bound each path by its own lower bound, for every , with a cost bound of the same form. These trees are called light approximate shortest-path trees in the work of Khuller, Raghavachari and Young.
- Prim-Dijkstra. The Prim-Dijkstra tradeoff has no proved cost bound but often gives better trees in practice, as in the measurements above.
- Arborescences. If every path must be shortest, the tree is a rectilinear Steiner arborescence, the Steiner form of the case .
When to use it
- When a routing tree must come with a guarantee on both its delay, through the radius, and its wire, through the cost.
- As a baseline with proved bounds when testing timing-driven tree heuristics.
When the best practical tradeoff matters more than a guarantee, try the Prim-Dijkstra tradeoff for a few values of . When a better delay model than the path length is needed, evaluate the trees with the Elmore delay.
Pitfalls
- Taking R as the radius of the MST. The threshold uses , the distance in the plane, not the radius of the spanning tree. With the tree radius the threshold is larger, and the bound on the radius no longer holds.
- Keeping the walk tree as the output. The graph after the shortcuts has cycles. The output is a shortest path tree of it, not itself.
- Resetting at the wrong time. The run must be reset whenever the threshold is passed, also when the point already has an edge to the source or is the source. Otherwise the cost bound breaks, since one shortcut would no longer stand for its own part of the tour.
- Floating point thresholds. With as a float, a run that equals may or may not pass it. Use exact numbers when the tie matters, as in the tests.
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/bounded-radius-bounded-cost-tree/. The authors are listed in prov/58DVMM.jsonl.
import heapq
from fractions import Fraction
from typing import Sequence, Union
Point = tuple[int, int]
Number = Union[int, Fraction]
def l1(p: Point, q: Point) -> int:
return abs(p[0] - q[0]) + abs(p[1] - q[1])
def mst_parent(points: Sequence[Point], source: int) -> list[int]:
"""Prim's minimum spanning tree under L1, rooted at the source. O(n^2)."""
n = len(points)
parent = [-1] * n
best = [(l1(points[source], p), source) for p in points]
used = [False] * n
used[source] = True
for _ in range(n - 1):
v = min((i for i in range(n) if not used[i]), key=lambda i: (best[i][0], i))
used[v] = True
parent[v] = best[v][1]
for w in range(n):
if not used[w] and l1(points[v], points[w]) < best[w][0]:
best[w] = (l1(points[v], points[w]), v)
return parent
def brbc(points: Sequence[Point], eps: Number, source: int = 0) -> tuple[list[int], list[int], list[int]]:
"""Cong, Kahng, Robins, Sarrafzadeh and Wong's bounded-radius bounded-cost tree.
Walks a depth-first tour of the L1 minimum spanning tree from the source and
adds the edge (source, v) when the tour length since the last added edge
exceeds eps * R, where R is the largest distance from the source. Returns
(parent, d, shortcuts): the shortest path tree of the MST plus the added
edges, the path lengths d from the source, and the points v that got an
edge. For eps > 0, every d[v] <= (1 + eps) R and the cost is at most
(1 + 2 / eps) times the MST.
"""
if eps <= 0:
raise ValueError("eps must be positive")
n = len(points)
if n == 0:
return [], [], []
tparent = mst_parent(points, source) # @line L1
children: list[list[int]] = [[] for _ in range(n)]
for v, u in enumerate(tparent):
if u >= 0:
children[u].append(v)
R = max(l1(points[source], p) for p in points)
adj: list[list[tuple[int, int]]] = [[] for _ in range(n)]
for v, u in enumerate(tparent):
if u >= 0:
w = l1(points[u], points[v])
adj[u].append((w, v))
adj[v].append((w, u))
shortcuts: list[int] = []
has_edge: set[int] = set()
run: Number = 0 # @line L2
stack = [(source, 0)] # (vertex, index of the next child) for the depth-first tour
while stack: # @line L3
u, k = stack[-1]
if k < len(children[u]):
stack[-1] = (u, k + 1)
v = children[u][k]
nxt = v
stack.append((v, 0))
else:
stack.pop()
if not stack:
break
nxt = stack[-1][0]
run += l1(points[u], points[nxt]) # @line L4
if run > eps * R: # @line L5
# The source and points that already have an edge need no new one.
if nxt != source and nxt not in has_edge: # @line L6
has_edge.add(nxt)
shortcuts.append(nxt)
w = l1(points[source], points[nxt])
adj[source].append((w, nxt))
adj[nxt].append((w, source))
run = 0 # @line L7
dist = [-1] * n
parent = [-1] * n
heap = [(0, source, -1)] # @line L8
while heap:
du, u, pu = heapq.heappop(heap)
if dist[u] >= 0:
continue
dist[u] = du
parent[u] = pu
for w, v in adj[u]:
if dist[v] < 0:
heapq.heappush(heap, (du + w, v, u))
return parent, dist, shortcuts
def tree_cost(points: Sequence[Point], parent: Sequence[int]) -> int:
return sum(l1(points[v], points[u]) for v, u in enumerate(parent) if u >= 0)
test_bounded_radius_bounded_cost_tree.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bounded-radius-bounded-cost-tree/. The authors are listed in prov/58DVMM.jsonl.
import random
from fractions import Fraction
from bounded_radius_bounded_cost_tree import brbc, l1, tree_cost
def mst_length(pts: list[tuple[int, int]]) -> int:
"""Kruskal on all pairs, written apart from the tree builder."""
n = len(pts)
parent = list(range(n))
def find(a: int) -> int:
while parent[a] != a:
a = parent[a]
return a
total = 0
for d, i, j in sorted((l1(pts[i], pts[j]), i, j) for i in range(n) for j in range(i + 1, n)):
if find(i) != find(j):
parent[find(i)] = find(j)
total += d
return total
def path_lengths(pts: list[tuple[int, int]], parent: list[int], source: int) -> list[int]:
"""Length of the tree path from the source to each point, by walking up the parents."""
out = []
for v in range(len(pts)):
total, seen = 0, set()
while v != source:
assert v not in seen and parent[v] >= 0
seen.add(v)
total += l1(pts[v], pts[parent[v]])
v = parent[v]
out.append(total)
return out
EXAMPLE = [(0, 0), (1, 3), (2, 6), (3, 9), (6, 9), (9, 9), (9, 6), (9, 3), (9, 0)]
def test_example() -> None:
parent, d, cuts = brbc(EXAMPLE, 1)
assert mst_length(EXAMPLE) == 27 and max(l1(EXAMPLE[0], p) for p in EXAMPLE) == 18
assert cuts == [6, 3]
assert d == [0, 4, 8, 12, 15, 18, 15, 18, 21]
assert tree_cost(EXAMPLE, parent) == 47
parent, d, cuts = brbc(EXAMPLE, 100)
assert cuts == [] and tree_cost(EXAMPLE, parent) == 27 and max(d) == 27
def test_edges() -> None:
assert brbc([], 1) == ([], [], [])
assert brbc([(5, 5)], 1) == ([-1], [0], [])
parent, d, _ = brbc([(0, 0), (3, 1)], Fraction(1, 4))
assert parent == [-1, 0] and d == [0, 4]
def test_bounds(seed: int = 37) -> None:
rng = random.Random(seed)
for _ in range(300):
n = rng.randint(1, 16)
pts = [(rng.randint(0, 40), rng.randint(0, 40)) for _ in range(n)]
s = rng.randrange(n)
eps = rng.choice([Fraction(1, 10), Fraction(1, 4), Fraction(1, 2), Fraction(1), Fraction(3)])
parent, d, _ = brbc(pts, eps, s)
assert d == path_lengths(pts, parent, s)
R = max(l1(pts[s], p) for p in pts)
assert all(x <= (1 + eps) * R for x in d)
assert tree_cost(pts, parent) <= (1 + 2 / eps) * mst_length(pts)
History
The minimum spanning tree and the shortest path tree were the two classical routing trees when wire delay began to matter in the early 1990s. Jason Cong, Andrew Kahng, Gabriel Robins, Majid Sarrafzadeh and C. K. Wong presented the BRBC construction, with its bounds on both the radius and the cost, at ISCAS and in IEEE Transactions on Computer-Aided Design in 1992, under the title of provably good performance-driven global routing. Charles Alpert and coauthors compared it with their Prim-Dijkstra trees in 1995. In network design, Samir Khuller, Balaji Raghavachari and Neal Young gave trees with a bound for each path in 1995.
References
- J. Cong, A. B. Kahng, G. Robins, M. Sarrafzadeh and C. K. Wong, Provably good performance-driven global routing, IEEE Transactions on Computer-Aided Design 11(6), 739 to 752, 1992, the BRBC algorithm and the bounds (1 + ε) R on the radius and (1 + 2/ε) on the cost ratio
- C. J. Alpert, T. C. Hu, J. H. Huang, A. B. Kahng and D. Karger, Prim-Dijkstra tradeoffs for improved performance-driven routing tree design, IEEE Transactions on Computer-Aided Design 14(7), 890 to 896, 1995, the comparison of BRBC trees with the Prim-Dijkstra trees
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 58DVMM Edit this page History Report an error Markdown