Steiner Trees and the Metric Closure
A Steiner tree connects a given set of terminals in a graph with edge costs ; other vertices, called Steiner vertices, may be used if they help. The problem models wiring a chip, laying fibre between cities, or building a multicast tree in a network. When it is the minimum spanning tree problem; when it is a shortest path. In between it is NP-hard (Karp, 1972). This lesson gives the classical 2-approximation, which uses the same doubling-and-shortcutting argument as TSP, and prepares the ground for the primal-dual algorithm of Primal-Dual for Steiner Forest.
Reducing to metric costs
Replace the graph by its metric closure on : = the cost of a shortest - path. A Steiner tree in the closure turns into a connected subgraph of the original graph of no greater cost (expand each edge into its path; if the union has cycles, delete edges), and every tree of the original graph is also a tree in the closure. So the optimum does not change, and from now on costs are metric. All shortest paths take time with Floyd-Warshall.
The algorithm
MST-STEINER(G, c, R)
1 d = shortest-path distances of G -- the metric closure
2 T' = a minimum spanning tree of the complete graph on R with costs d
3 replace every edge of T' by a shortest path in G
4 return a spanning tree of the union of those pathsTheorem. The algorithm returns a Steiner tree of cost at most .
Proof. Let be an optimal Steiner tree. Double its edges and take an Euler circuit, of cost . Shortcut it to the terminals in order of first visit: by the triangle inequality this gives a cycle through the terminals of cost at most . Delete the most expensive of its edges: what remains is a spanning path on of cost at most . A spanning path is a spanning tree on , so the MST costs no more, and steps 3 and 4 do not increase the cost.
The lower bound here is subtler than for TSP: it is not a single computable number but the statement "some spanning tree on the terminals costs at most twice the optimum", which is enough because the MST is the cheapest spanning tree.
import random
from itertools import combinations
from math import inf
def closure(n, edges):
d = [[0 if u == v else inf for v in range(n)] for u in range(n)]
for u, v, w in edges:
d[u][v] = d[v][u] = min(d[u][v], w)
for m in range(n):
for u in range(n):
for v in range(n):
if d[u][m] + d[m][v] < d[u][v]:
d[u][v] = d[u][m] + d[m][v]
return d
def mst_cost(nodes, d):
nodes = list(nodes)
inside, total = {nodes[0]}, 0
while len(inside) < len(nodes):
w, v = min((d[u][v], v) for u in inside for v in nodes if v not in inside)
inside.add(v)
total += w
return total
def steiner_opt(n, R, d):
# an optimal Steiner tree in the closure is an MST on R plus some set of Steiner vertices
others = [v for v in range(n) if v not in R]
return min(mst_cost(set(R) | set(S), d) for k in range(len(others) + 1) for S in combinations(others, k))
rng = random.Random(4)
print(" n |R| MST on R OPT ratio bound")
for _ in range(6):
n = 10
edges = [(u, v, rng.randint(1, 9)) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.4]
edges += [(i, i + 1, 9) for i in range(n - 1)] # keep the graph connected
d = closure(n, edges)
R = sorted(rng.sample(range(n), rng.randint(3, 5)))
a, o = mst_cost(R, d), steiner_opt(n, R, d)
print(f"{n:2} {len(R):4} {a:9} {o:5} {a / o:6.3f} {2 * (1 - 1 / len(R)):6.3f}") n |R| MST on R OPT ratio bound
10 3 12 11 1.091 1.333
10 3 7 7 1.000 1.333
10 3 14 14 1.000 1.333
10 4 11 11 1.000 1.500
10 4 23 21 1.095 1.500
10 5 17 17 1.000 1.600
In C++
Floyd-Warshall for the closure, then Prim on the terminals only.
#include <cstdio>
#include <vector>
int main() {
const int INF = 1 << 29, n = 7;
int edges[][3] = {{0, 4, 2}, {1, 4, 2}, {2, 4, 2}, {3, 4, 2}, {0, 1, 3}, {1, 2, 3}, {2, 3, 3}, {3, 5, 1}, {5, 6, 1}, {6, 0, 5}};
std::vector<std::vector<int>> d(n, std::vector<int>(n, INF));
for (int v = 0; v < n; v++) d[v][v] = 0;
for (auto& e : edges) d[e[0]][e[1]] = d[e[1]][e[0]] = e[2];
for (int m = 0; m < n; m++)
for (int u = 0; u < n; u++)
for (int v = 0; v < n; v++)
if (d[u][m] + d[m][v] < d[u][v]) d[u][v] = d[u][m] + d[m][v];
std::vector<int> R = {0, 1, 2, 3}; // terminals; 4, 5, 6 are Steiner vertices
std::vector<int> best(R.size(), INF);
std::vector<bool> in(R.size(), false);
best[0] = 0;
int total = 0;
for (size_t it = 0; it < R.size(); it++) {
int u = -1;
for (size_t i = 0; i < R.size(); i++) if (!in[i] && (u < 0 || best[i] < best[u])) u = i;
in[u] = true;
total += best[u];
for (size_t i = 0; i < R.size(); i++) if (!in[i] && d[R[u]][R[i]] < best[i]) best[i] = d[R[u]][R[i]];
}
std::printf("MST on the terminals in the closure: %d\n", total);
std::printf("star through Steiner vertex 4: %d\n", 4 * 2);
}MST on the terminals in the closure: 9
star through Steiner vertex 4: 8
The star through vertex 4 costs 8, while the terminal MST, which may not use vertex 4 as a junction, pays 9 for three edges of cost 3. With terminals at distance 1 from a hub and at distance 2 from each other, the MST costs and the star , so the ratio of the theorem is attained.
The same star family in a program, for growing : the closure distances are 1 from the hub and 2 between terminals, and the exact optimum (allowing the hub as a Steiner vertex) is the star.
def mst_cost(nodes, d):
nodes = list(nodes)
inside, total = {nodes[0]}, 0
while len(inside) < len(nodes):
w, v = min((d(u, v), v) for u in inside for v in nodes if v not in inside)
inside.add(v)
total += w
return total
for t in [3, 4, 6, 10, 20]:
d = lambda u, v: 0 if u == v else (1 if 0 in (u, v) else 2) # vertex 0 is the hub
terminals = range(1, t + 1)
alg, opt = mst_cost(terminals, d), mst_cost([0, *terminals], d)
print(f"t = {t:2}: MST on terminals {alg:2}, optimum {opt:2}, ratio {alg / opt:.3f} = 2(1 - 1/t) = {2 * (1 - 1 / t):.3f}")t = 3: MST on terminals 4, optimum 3, ratio 1.333 = 2(1 - 1/t) = 1.333
t = 4: MST on terminals 6, optimum 4, ratio 1.500 = 2(1 - 1/t) = 1.500
t = 6: MST on terminals 10, optimum 6, ratio 1.667 = 2(1 - 1/t) = 1.667
t = 10: MST on terminals 18, optimum 10, ratio 1.800 = 2(1 - 1/t) = 1.800
t = 20: MST on terminals 38, optimum 20, ratio 1.900 = 2(1 - 1/t) = 1.900
Better algorithms and limits
- Zelikovsky (1993) improved the factor to by greedily adding Steiner vertices that join three terminals ("3-restricted" components).
- Robins and Zelikovsky (2005): .
- Byrka, Grandoni, Rothvoß and Sanità (2010, journal version 2013): , by iterated randomized rounding of an LP over -restricted components (the directed component relaxation).
- Hardness: no -approximation unless P = NP (Chlebík and Chlebíková, 2008), so Steiner tree is APX-hard and has no PTAS.
- In the Euclidean plane, where Steiner points can be placed anywhere, the MST of the terminals is within a small constant factor of the optimum (Gilbert and Pollak, 1968, conjectured ; the conjecture is still considered open), and Arora's method (Euclidean TSP: the Idea of Arora's PTAS) gives a PTAS.
The Steiner forest problem connects several terminal pairs , each pair to its partner, with a forest. The MST trick no longer applies, since the components are not known in advance; the primal-dual method handles it with factor 2.
Test yourself
Why can the Steiner tree problem be solved on the metric closure without changing the optimum?
- Because shortest paths are unique
- Every closure edge expands into a path of the same cost in the original graph, and every original edge is a closure edge of no greater cost
- Because Steiner vertices can be ignored
- Because the closure is a tree
Where does the factor in the bound come from?
- From Prim's algorithm
- From deleting the most expensive of the edges of the shortcut cycle on the terminals
- From the number of Steiner vertices
- From the triangle inequality
On a star with terminal leaves at distance 1 from a Steiner centre, what does the terminal MST cost?
- , since terminals are at distance 2 from each other