TExcelTAD
Home › Approximation Algorithms › Steiner Trees and the Metric Closure

Steiner Trees and the Metric Closure

A Steiner tree connects a given set of terminals R⊆VR \subseteq V in a graph with edge costs ce≥0c_e \ge 0; 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 R=VR = V it is the minimum spanning tree problem; when ∣R∣=2\lvert R \rvert = 2 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 VV: d(u,v)d(u, v) = the cost of a shortest uu-vv 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 O(n3)O(n^3) time with Floyd-Warshall.

The algorithm

text
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 paths

Theorem. The algorithm returns a Steiner tree of cost at most 2(1−1∣R∣)OPT2\left(1 - \frac{1}{\lvert R \rvert}\right)\text{OPT}.

Proof. Let T∗T^* be an optimal Steiner tree. Double its edges and take an Euler circuit, of cost 2 OPT2\,\text{OPT}. Shortcut it to the terminals in order of first visit: by the triangle inequality this gives a cycle through the t=∣R∣t = \lvert R \rvert terminals of cost at most 2 OPT2\,\text{OPT}. Delete the most expensive of its tt edges: what remains is a spanning path on RR of cost at most (1−1t)⋅2 OPT(1 - \frac{1}{t}) \cdot 2\,\text{OPT}. A spanning path is a spanning tree on RR, so the MST T′T' costs no more, and steps 3 and 4 do not increase the cost. □\square

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.

python · try it yourself
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.

cpp · try it yourself
#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 tt terminals at distance 1 from a hub and at distance 2 from each other, the MST costs 2(t−1)2(t - 1) and the star tt, so the ratio 2(1−1t)2(1 - \frac{1}{t}) of the theorem is attained.

The same star family in a program, for growing tt: 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.

python · try it yourself
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 116\frac{11}{6} by greedily adding Steiner vertices that join three terminals ("3-restricted" components).
  • Robins and Zelikovsky (2005): 1+ln⁡32≈1.551 + \frac{\ln 3}{2} \approx 1.55.
  • Byrka, Grandoni, Rothvoß and Sanità (2010, journal version 2013): ln⁡4+ε≈1.39\ln 4 + \varepsilon \approx 1.39, by iterated randomized rounding of an LP over kk-restricted components (the directed component relaxation).
  • Hardness: no 9695\frac{96}{95}-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 23≈1.155\frac{2}{\sqrt{3}} \approx 1.155; 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 (si,ti)(s_i, t_i), 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?

  1. Because shortest paths are unique
  2. 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
  3. Because Steiner vertices can be ignored
  4. Because the closure is a tree

Where does the factor 1−1∣R∣1 - \frac{1}{\lvert R \rvert} in the bound come from?

  1. From Prim's algorithm
  2. From deleting the most expensive of the ∣R∣\lvert R \rvert edges of the shortcut cycle on the terminals
  3. From the number of Steiner vertices
  4. From the triangle inequality

On a star with tt terminal leaves at distance 1 from a Steiner centre, what does the terminal MST cost?

  1. tt
  2. 2(t−1)2(t - 1), since terminals are at distance 2 from each other
  3. t−1t - 1
  4. 2t2t