common_spanning_trees#
- graph_tool.structure.common_spanning_trees(g1, g2)[git][source]#
Return an iterator over the spanning trees common to two graphs with corresponding edges.
- Parameters:
- Returns:
- treesiterator over
numpy.ndarray For every common spanning tree, a boolean array over the edges, in the order of their indices, marking those in the tree.
- treesiterator over
See also
all_spanning_arborescencesSpanning arborescences in order of weight
random_spanning_treeUniformly sampled spanning tree
Notes
The edges of
g1andg2correspond in the order of their indices (edge_index), and a set of edges is a common spanning tree if it forms a spanning tree of both graphs. Such pairs of graphs arise as the current and voltage graphs of electrical networks with controlled sources, whose common spanning trees give the terms of the network determinant [mayeda-generation-1965]. For simple graphs, they are enumerated with the algorithm of Mayeda and Seshu [mayeda-generation-1965], and for multigraphs instead by binary branching over the edges [read-bounds-1975], where an edge is included only if it closes no cycle in either graph, and a branch is abandoned as soon as the remaining edges cannot connect both graphs. The number of trees can grow exponentially.References
[mayeda-generation-1965] (1,2)Wataru Mayeda and Sundaram Seshu, “Generation of trees without duplications”, IEEE Transactions on Circuit Theory 12, 181-185 (1965), DOI: 10.1109/TCT.1965.1082432 [sci-hub, @tor]
[read-bounds-1975]Ronald C. Read and Robert E. Tarjan, “Bounds on backtrack algorithms for listing cycles, paths, and spanning trees”, Networks 5, 237-252 (1975), DOI: 10.1002/net.1975.5.3.237 [sci-hub, @tor]
Examples
>>> g1 = gt.Graph([(0, 1), (1, 2), (2, 0)], directed=False) >>> g2 = gt.Graph([(0, 1), (0, 2), (2, 1)], directed=False) >>> for t in gt.common_spanning_trees(g1, g2): ... print(t) [ True True False] [ True False True] [False True True]