steiner_tree

Contents

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:
gGraph

Undirected graph to be used.

terminalsiterable of Vertex or int

The vertices to be connected.

weightsEdgePropertyMap (optional, default: None)

Nonnegative edge weights. If not given, every edge has unit weight.

tree_mapEdgePropertyMap (optional, default: None)

If provided, the edges of the tree will be marked in this property map.

Returns:
tree_mapEdgePropertyMap

Boolean edge property map marking the edges of the tree.

See also

minimum_spanning_tree

Minimum spanning tree

voronoi_cells

Closest terminal of every vertex

connected_dominating_set

Connected 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")
<...>
../_images/steiner_tree-karate.png

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.#