all_spanning_arborescences#
- graph_tool.structure.all_spanning_arborescences(g, weights=None, root=None, maximum=False)[git][source]#
Return an iterator over the spanning arborescences of a directed graph, in order of increasing (or decreasing) weight.
- Parameters:
- g
Graph Directed graph to be used.
- weights
EdgePropertyMap(optional, default:None) The edge weights. If not supplied, every edge has unit weight.
- root
Vertex(optional, default:None) Root of the arborescences. If not supplied, arborescences with any root are generated.
- maximum
bool(optional, default:False) If
True, the arborescences are generated in order of decreasing weight.
- g
- Returns:
- arborescencesiterator over
EdgePropertyMap Iterator over Boolean edge property maps that mark the edges of each arborescence.
- arborescencesiterator over
See also
minimum_spanning_arborescenceMinimum spanning arborescence only
common_spanning_treesSpanning trees common to two graphs
graph_tool.spectral.num_spanning_treesNumber of spanning trees
Notes
A spanning arborescence with root \(r\) is a set of \(V-1\) edges in which every vertex other than \(r\) has exactly one incoming edge and which contains a directed path from \(r\) to every vertex, and its weight is the sum of the weights of its edges. The arborescences are generated with the partition scheme of Sörensen and Janssens [sorensen-algorithm-2005]: the arborescences that contain a set of included edges and avoid a set of excluded edges are represented by the minimum one among them, found with
minimum_spanning_arborescence()after removing the excluded edges and the other edges that point to the heads of the included ones. After this arborescence is generated, its set is split along its edges \(f_1,\dots,f_m\) that are not included into the sets with the included edges extended by \(f_1,\dots,f_{i-1}\) and the excluded edges extended by \(f_i\). The sets are kept in a priority queue ordered by their minimum weight, so that every arborescence takes time \(O(VE\log V)\). Self-loops are ignored, and arborescences of equal weight are generated in an unspecified order.References
[sorensen-algorithm-2005]Kenneth Sörensen and Gerrit K. Janssens, “An algorithm to generate all spanning trees of a graph in order of increasing cost”, Pesquisa Operacional 25, 219-229 (2005), DOI: 10.1590/S0101-74382005000200004 [sci-hub, @tor]
Examples
>>> g = gt.complete_graph(4, directed=True) >>> w = g.new_ep("double", vals=np.arange(g.num_edges())) >>> print(*[(tree.a * w.a).sum() for tree in ... gt.all_spanning_arborescences(g, w, root=0)]) 3.0 6.0 6.0 9.0 9.0 10.0 12.0 13.0 13.0 13.0 16.0 16.0 16.0 19.0 20.0 23.0