Algorithmcore
Iterated 1-Steiner heuristic
Also called 1-Steiner heuristic, Kahng-Robins heuristic.
Kahng and Robins's heuristic that repeatedly adds the Hanan grid point that shortens the rectilinear MST most, and stops when no point makes it shorter.
- Time
- O(R n^3 log n) totalO(n^3 log n) per_iteration
- Space
- Θ(n^2) extra
- Where
- R = the number of rounds; n = the number of pins
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Andrew B. Kahng, Gabriel Robins, 1990
The iterated 1-Steiner heuristic of Andrew Kahng and Gabriel Robins builds a short rectilinear Steiner tree for a net in electronic design automation (EDA). It starts from the rectilinear minimum spanning tree of the pins. In each round it tries every point of the Hanan grid, the crossings of the horizontal and vertical lines through the pins, as one extra Steiner point, and keeps the point that makes the minimum spanning tree shortest. It then drops Steiner points that no longer help, and repeats until no point makes the tree shorter. The tree is never longer than the minimum spanning tree, so it is within 3/2 of the optimum by Hwang's theorem. It is exact for three pins, but not for all nets, since the rectilinear Steiner tree problem is NP-hard.
In plain words
You must join some pins with horizontal and vertical wire, as short as possible. Joining the pins directly, pin to pin, is the minimum spanning tree. Often the wire gets shorter if you add a branch point that is not a pin, where three wires meet.
Where should such a point go? Draw a horizontal and a vertical line through every pin. Some best tree has all its branch points on the crossings of these lines, so only these crossings are worth trying.
Try each crossing in turn. Add it as an extra pin, compute the minimum spanning tree again, and see how much wire it saves. Keep the crossing that saves most. Then do it again with the new set of pins. If a branch point you added now joins only one or two wires, throw it away, because it saves nothing. Stop when no crossing saves any wire.
The problem
The input is a set of pins in the plane. A rectilinear Steiner tree is a set of extra points, the Steiner points, and a tree on whose edges are drawn as horizontal and vertical wires, so that each edge costs the L1 distance . The output is a tree of small total length. For a fixed the best tree is the minimum spanning tree under L1, so the task is to choose .
The Hanan grid of is the set of the crossings of the vertical lines through the pins and the horizontal lines through the pins, at most points. By Hanan's theorem some optimal tree has all its Steiner points on it. The gain of a point for the set is
The algorithm
ITERATED-1-STEINER(P)- 1
H ← the points of the Hanan grid of P that are not pins; S ← ∅ - 2
loop - 3
T ← MST(P ∪ S); base ← length(T) - 4
for each x in H \ S do gain(x) ← base − length(MST(P ∪ S ∪ {x})) - 5
if no x has gain(x) > 0 then return T - 6
add to S a point x of largest gain - 7
repeat remove from S each point of degree at most 2 in MST(P ∪ S) - 8
until no point is removed
Line L4 does not build each tree from nothing. The minimum spanning tree of uses only edges of and edges from , so it is the minimum spanning tree of a graph with fewer than edges, found by Kruskal's algorithm in time. Ties in line L6 go to the first point in the order of the Hanan grid, by and then by .
Example
Take the five pins , , , and , the example of the rectilinear minimum spanning tree page. The lines through the pins have and , so the Hanan grid has 25 points, and 20 of them are not pins.
| round | base length | best points and gains | added |
|---|---|---|---|
| 1 | 16 | and with gain 2, six points with gain 1 | |
| 2 | 14 | with gain 1 | |
| 3 | 13 | none | stop |
In round 1 the two best points tie, and comes first in the order of the grid. Both added points have degree 3 in the tree, so line L7 removes nothing. The final tree has the edges
to of length 1, to of 1, to of 2, to of 2, to of 3 and to of 4,
with total length 13. A brute force over all sets of at most three Hanan points gives 13 as the optimum, so here the heuristic is exact, and it saves 3 of the 16 units of the minimum spanning tree.
Correctness
The proof shows the following.
- Fast gains. The minimum spanning tree of can be taken from the edges of and the edges from . This is the cycle property: an edge outside the old tree has a path in the old tree whose edges are all at most .
- Removal is safe. A Steiner point of degree 1 or 2 can be removed without making the tree longer, since its one or two edges can be replaced by nothing or by the direct edge between its two neighbors, which is no longer by the triangle inequality.
- Never worse than the MST. The length after every round is at most the length before it, so the output is at most , and so at most 3/2 times the optimum.
- Termination. Each round makes the length strictly shorter, so no set comes back, and there are finitely many subsets of the Hanan grid.
- At most Steiner points. After line L8 every Steiner point has degree at least 3 in a tree with pins, which allows at most of them.
- Exact for three pins. The point with the median and the median is on the Hanan grid, and the star from it has the optimal length, the half perimeter of the bounding box.
Proof: Iterated 1-Steiner never makes the tree longer than the minimum spanning tree, ends, keeps at most n − 2 Steiner points and is exact for three pinsfull
Let be a set of distinct pins and the L1 distance. For a finite set of points, is a minimum spanning tree of the complete graph on with lengths , and is its length. The value does not depend on which minimum spanning tree is taken. Let be the Hanan grid of minus the pins, and let be the current set of Steiner points.
Lemma 1 (path bound). Let be a minimum spanning tree of a complete graph with lengths , and let be two of its vertices. Every edge on the path of from to has length at most .
Proof. Suppose an edge on the path has . Removing splits into two parts, and and are in different parts, since is on the path between them. Then is a spanning tree shorter than , a contradiction.
Lemma 2 (fast gain update). Let be a finite set of points, a minimum spanning tree of and . Let be the graph on with the edges of and the edges for all . Then a minimum spanning tree of is a minimum spanning tree of the complete graph on .
Proof. Let be a minimum spanning tree of the complete graph on with the most edges in . Suppose has an edge not in . Every edge at is in , so . Removing splits into two parts with and in different parts. The path of from to has an edge that joins the two parts, and by Lemma 1. So is a spanning tree no longer than , so it is minimum, and it has one more edge in , a contradiction. So lies in . A minimum spanning tree of is no longer than , and no shorter, since it spans the same points.
So line L4 computes the exact gain from and the edges at .
Lemma 3 (removal is safe). Let be a spanning tree of and let be a set of points that each have degree at most 2 in . Then .
Proof. Remove the points of one at a time. Let be the next point, with degree at most 2 in the current tree. If has degree 1, remove and its edge. If has degree 2 with neighbors and , remove and its two edges, and add the edge . In both cases the result is a spanning tree of the remaining points, and it is no longer, since by the triangle inequality. A point of that was a neighbor of loses the edge to and gains at most one new edge, so its degree does not grow and stays at most 2. At the end we have a spanning tree of no longer than , and the minimum spanning tree is no longer than that.
Theorem 1 (never longer than the MST). Let be at line L3 of round . Then and for every round that does not return. So the output tree is a rectilinear Steiner tree of with .
Proof. At the start . If round does not return, line L6 adds a point with , so the length after line L6 is . Each removal in line L7 does not make the length longer, by Lemma 3. So . The output is a spanning tree of , so it is a Steiner tree of with the points of as Steiner points, and its length is the last , which is at most .
By Hwang's theorem, , so the output is within a factor 3/2 of the optimum.
Theorem 2 (termination). The algorithm returns after finitely many rounds.
Proof. The value depends only on the set at line L3, and strictly decreases by Theorem 1. So the sets at line L3 of different rounds are all different. They are subsets of the finite set , so there are at most rounds. The loop of lines L7 and L8 ends because each pass that does not stop removes a point from the finite set .
Lemma 4 (at most Steiner points). After line L8, .
Proof. After line L8 every point of has degree at least 3 in . Let . If then has points, so every pin has degree at least 1. The degrees of a tree sum to , so , which gives .
Theorem 3 (exact for ). For the output is a rectilinear Steiner minimal tree.
Proof. For every Steiner tree has length at least for the two pins, and the minimum spanning tree has exactly this length. Let , and let be the half perimeter of the bounding box of , the width plus the height. Every Steiner tree of has length at least : its edges project onto the axis with total length at least the width, since the tree connects the leftmost and the rightmost pin, and the same holds for the axis. Let be the point with the median and the median of the pins, a point of the Hanan grid. For three numbers , , so the star from to the three pins has length exactly . If is a pin, the star is a spanning tree of , so and the output, which is no longer, is optimal. Otherwise and . If the start is optimal. If not, the gain of in round 1 is positive, so the point chosen in line L6 has gain at least that of , and the length after round 1 is at most . By Theorem 1 the output is at most this, so it equals .
Running time of one round. By Lemma 4, at line L3 the set has fewer than points, so the minimum spanning tree of line L3 takes time on all pairs. For each of the at most points , Lemma 2 gives the gain from a graph with fewer than edges, and Kruskal's algorithm takes on it. Each pass of lines L7 and L8 takes and removes a point, so there are passes, for . A round takes time and space.
Complexity
- One round. The Hanan grid has at most points. After line L8 there are at most Steiner points, so each tree has fewer than points. The gain of one point takes edges from and a Kruskal run on edges, which is . A round is .
- Rounds. The proof bounds the number of rounds only by the finite number of subsets of the grid. Each round adds one point, so is at least the number of Steiner points in the output. With integer coordinates each round saves at least 1, so .
- Space. The Hanan grid takes space, and the trees take .
- Faster gains. The gains of all points in a round can be computed faster than one Kruskal run per point, by data structures over the old tree. The implementation here uses the simple update per point.
Properties
- What is proved. The output is a rectilinear Steiner tree no longer than the rectilinear minimum spanning tree, so its ratio to the optimum is at most 3/2. The loop ends. The output has at most Steiner points. The output is optimal for . The heuristic is not optimal on all inputs.
- What is measured. On random nets with integer coordinates from 0 to 99 (Python
random.Random(2026)), compared with the brute-force optimum over pins plus at most Hanan points: for 200 nets of 5 pins, the mean ratio to the optimum was 1.0008, the worst 1.0443, and 191 nets were optimal; for 25 nets of 6 pins, the mean was 1.0007, the worst 1.0170, and 24 were optimal. On the same nets the minimum spanning tree had mean ratios 1.1106 and 1.1065. These are toy inputs, not benchmark results. - Greedy. Each round makes the choice with the best immediate gain. It is a greedy algorithm and a form of local search over sets of Steiner points.
- Deterministic. With fixed tie rules the output depends only on the input.
Variants and improvements
- Batched 1-Steiner. Instead of one point per round, sort the points by gain and add, in this order, each point whose gain is still positive after the points added before it in the round. This needs fewer rounds, and the length after each round is still never longer than before it.
- Graphs and other metrics. The same step works in any metric where a finite set of candidate points is known, and in graphs, where the candidates are the vertices that are not terminals.
- Lookup tables. For nets with few pins, FLUTE finds an optimal tree from precomputed tables much faster, and it is the usual choice inside placement tools.
- Exact methods. For exact trees of larger nets, exact Steiner tree solvers use the Hanan theorem and full components. They are much slower than this heuristic.
When to use it
- When a short rectilinear Steiner tree is needed for nets of up to a few hundred pins, and the time of a few rounds of is acceptable.
- As a reference heuristic when testing faster Steiner tree methods.
For nets of a few pins inside an inner loop, use FLUTE. For a quick estimate with a proved bound, the rectilinear minimum spanning tree is enough.
Pitfalls
- Keeping useless Steiner points. After later points are added, an earlier Steiner point can end up with degree 2 or 1. If it is not removed, the number of Steiner points can grow past and each round gets slower. The length is not hurt, but the bound on the round time is.
- Rebuilding the MST from nothing. Computing each gain with a fresh minimum spanning tree on all pairs costs per point and per round. Use the update from the old tree.
- Candidates off the grid. Points outside the Hanan grid are never needed for one optimal tree, and adding them as candidates only costs time.
- Expecting optimal trees. The greedy choice can be wrong: a point with the best gain now can block a better pair of points later. The measured results above show that this is rare on small random nets, but it is not proved to be rare.
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/iterated-one-steiner/. The authors are listed in prov/S1Z8DM.jsonl.
from typing import Sequence
Point = tuple[int, int]
Edge = tuple[int, int, int] # (length, i, j), indices into the point list
def l1(p: Point, q: Point) -> int:
return abs(p[0] - q[0]) + abs(p[1] - q[1])
def kruskal(n: int, edges: list[Edge]) -> list[Edge]:
parent = list(range(n))
def find(a: int) -> int:
while parent[a] != a:
parent[a] = parent[parent[a]]
a = parent[a]
return a
tree = []
for d, a, b in sorted(edges):
ra, rb = find(a), find(b)
if ra != rb:
parent[ra] = rb
tree.append((d, a, b))
return tree
def mst(pts: Sequence[Point]) -> list[Edge]:
"""Minimum spanning tree of pts under the L1 metric, by Kruskal on all pairs."""
n = len(pts)
return kruskal(n, [(l1(pts[i], pts[j]), i, j) for i in range(n) for j in range(i + 1, n)])
def mst_with(pts: Sequence[Point], tree: list[Edge], x: Point) -> list[Edge]:
"""MST of pts + [x], from the MST of pts and the edges from x, in O(n log n) time."""
k = len(pts)
edges = tree + [(l1(x, p), k, i) for i, p in enumerate(pts)]
return kruskal(k + 1, edges)
def length(tree: list[Edge]) -> int:
return sum(d for d, _, _ in tree)
def iterated_one_steiner(pins: Sequence[Point]) -> tuple[list[Point], list[Edge]]:
"""Kahng and Robins's iterated 1-Steiner heuristic for the rectilinear Steiner tree.
Returns (points, tree): points is the pin list followed by the chosen Steiner
points, and tree is the L1 minimum spanning tree of points as (length, i, j).
Each round adds the Hanan point that lowers the MST length most, then drops
the Steiner points of degree at most 2. The loop stops when no Hanan point helps.
"""
pins = list(pins)
n = len(pins)
xs = sorted({p[0] for p in pins})
ys = sorted({p[1] for p in pins})
pinset = set(pins)
hanan = [(x, y) for x in xs for y in ys if (x, y) not in pinset] # @line L1
steiner: list[Point] = []
while True: # @line L2
pts = pins + steiner
tree = mst(pts)
base = length(tree) # @line L3
best_gain, best_x = 0, None
used = set(steiner)
for x in hanan:
if x in used:
continue
gain = base - length(mst_with(pts, tree, x)) # @line L4
if gain > best_gain:
best_gain, best_x = gain, x
if best_x is None: # @line L5
return pts, tree
steiner.append(best_x) # @line L6
while True:
pts = pins + steiner
tree = mst(pts)
deg = [0] * len(pts)
for _, a, b in tree:
deg[a] += 1
deg[b] += 1
keep = [p for i, p in enumerate(steiner) if deg[n + i] > 2] # @line L7
if len(keep) == len(steiner): # @line L8
break
steiner = keep
test_iterated_one_steiner.py 77 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterated-one-steiner/. The authors are listed in prov/S1Z8DM.jsonl.
import random
from itertools import combinations
from iterated_one_steiner import iterated_one_steiner, l1, length, mst
def exact_rsmt(pins: list[tuple[int, int]]) -> int:
"""Brute force: the least MST length over pins plus at most n - 2 points of the Hanan grid."""
xs = sorted({p[0] for p in pins})
ys = sorted({p[1] for p in pins})
cand = [(x, y) for x in xs for y in ys if (x, y) not in set(pins)]
best = length(mst(pins))
for k in range(1, max(len(pins) - 1, 1)):
for extra in combinations(cand, k):
best = min(best, length(mst(pins + list(extra))))
return best
def is_tree_on(pts: list[tuple[int, int]], tree: list[tuple[int, int, int]]) -> bool:
n = len(pts)
if len(tree) != max(n - 1, 0):
return False
parent = list(range(n))
def find(a: int) -> int:
while parent[a] != a:
a = parent[a]
return a
for d, a, b in tree:
if d != l1(pts[a], pts[b]) or find(a) == find(b):
return False
parent[find(a)] = find(b)
return True
def test_plus() -> None:
pins = [(1, 0), (0, 1), (2, 1), (1, 2)]
pts, tree = iterated_one_steiner(pins)
assert pts == pins + [(1, 1)]
assert length(tree) == 4 == exact_rsmt(pins)
def test_five_points() -> None:
pins = [(0, 0), (4, 1), (1, 4), (5, 5), (2, 3)]
pts, tree = iterated_one_steiner(pins)
assert length(mst(pins)) == 16
assert length(tree) == 13 == exact_rsmt(pins)
assert is_tree_on(pts, tree)
def test_edges() -> None:
assert iterated_one_steiner([]) == ([], [])
assert iterated_one_steiner([(2, 2)]) == ([(2, 2)], [])
pts, tree = iterated_one_steiner([(0, 0), (3, 4)])
assert length(tree) == 7 and len(pts) == 2
def test_against_exact(seed: int = 23) -> None:
rng = random.Random(seed)
for _ in range(150):
n = rng.randint(2, 5)
pins = [(rng.randint(0, 9), rng.randint(0, 9)) for _ in range(n)]
pins = list(dict.fromkeys(pins))
pts, tree = iterated_one_steiner(pins)
assert pts[: len(pins)] == pins and is_tree_on(pts, tree)
opt = exact_rsmt(pins)
assert opt <= length(tree) <= length(mst(pins))
if len(pins) <= 3:
assert length(tree) == opt
for _ in range(4):
pins = list(dict.fromkeys((rng.randint(0, 20), rng.randint(0, 20)) for _ in range(6)))
pts, tree = iterated_one_steiner(pins)
assert exact_rsmt(pins) <= length(tree) <= length(mst(pins))
History
M. Hanan showed in 1966 that some optimal rectilinear Steiner tree has its Steiner points on the grid of lines through the pins, which gives a finite set of candidates. F. K. Hwang showed in 1976 that the minimum spanning tree is at most 3/2 times the optimal Steiner tree, so any method that starts from the spanning tree and never makes it longer keeps this bound. Andrew Kahng and Gabriel Robins presented the iterated 1-Steiner heuristic at ICCAD in 1990 and published the journal version in 1992. It became a common reference heuristic for rectilinear Steiner trees in VLSI routing. Later methods such as FLUTE (2005 and 2008) aimed at similar quality in much less time.
References
- Andrew B. Kahng and Gabriel Robins, A new class of iterative Steiner tree heuristics with good performance, IEEE Transactions on Computer-Aided Design 11(7), 893 to 902, 1992, the 1-Steiner step, its iteration over the Hanan points and the removal of Steiner points of degree at most 2
- Andrew B. Kahng and Gabriel Robins, A new family of Steiner tree heuristics with good performance: the iterated 1-Steiner approach, Proceedings of ICCAD 1990, 428 to 431, the conference version of the same method
- M. Hanan, On Steiner's problem with rectilinear distance, SIAM Journal on Applied Mathematics 14(2), 255 to 265, 1966, the theorem that the candidate points can be taken on the grid of lines through the pins
- F. K. Hwang, On Steiner minimal trees with rectilinear distance, SIAM Journal on Applied Mathematics 30(1), 104 to 114, 1976, the bound of 3/2 on the ratio of the rectilinear minimum spanning tree to the Steiner minimal tree
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 S1Z8DM Edit this page History Report an error Markdown