steiner_tree#
- graph_tool.structure.steiner_tree(g, terminals, weights=None, tree_map=None)[git][source]#
Return an approximate minimum Steiner tree connecting the given terminal vertices.
- Parameters:
- g
Graph Undirected graph to be used.
- terminalsiterable of
Vertexorint The vertices to be connected.
- weights
EdgePropertyMap(optional, default:None) Nonnegative edge weights. If not given, every edge has unit weight.
- tree_map
EdgePropertyMap(optional, default:None) If provided, the edges of the tree will be marked in this property map.
- g
- Returns:
- tree_map
EdgePropertyMap Boolean edge property map marking the edges of the tree.
- tree_map
See also
minimum_spanning_treeMinimum spanning tree
voronoi_cellsClosest terminal of every vertex
connected_dominating_setConnected set of vertices adjacent to all others
Notes
A Steiner tree of a set of terminals is a subtree of the graph that contains all the terminals, and possibly other vertices, and a minimum one minimizes the total weight \(\sum_e w_e\) of its edges. Finding it is NP-hard, and the 2-approximation of Mehlhorn [mehlhorn-faster-1988] is used: the vertices are assigned to their nearest terminal, the shortest connections between the regions of neighboring terminals form a graph on the terminals, whose minimum spanning tree is expanded into shortest paths, and the minimum spanning tree of these paths is pruned of the leaves that are not terminals. The total weight is at most twice the minimum. The algorithm runs in time \(O(E + V\log V)\).
If the terminals are not all connected, a Steiner forest with a tree for every connected component is returned.
References
[mehlhorn-faster-1988]Kurt Mehlhorn, “A faster approximation algorithm for the Steiner problem in graphs”, Information Processing Letters 27, 125-128 (1988), DOI: 10.1016/0020-0190(88)90066-X [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> tree = gt.steiner_tree(g, [8, 16, 26]) >>> print(tree.fa.sum()) 5
The tree can be highlighted in a drawing of the network:
>>> vcolor = g.new_vp("string", val="#cccccc") >>> for v in [8, 16, 26]: ... vcolor[v] = "#f28c8e" >>> ecolor = g.new_ep("string", vals=np.where(tree.a, "#e41a1c", ... "#999999")) >>> ewidth = g.new_ep("double", vals=np.where(tree.a, 2.5, 1)) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor, ... edge_color=ecolor, edge_pen_width=ewidth, ... output="steiner_tree-karate.pdf") <...>
Approximate minimum Steiner tree of vertices 8, 16 and 26 of Zachary’s karate club network. The terminals are shown in red, and the edges of the tree in red.#