all_topological_sorts#
- graph_tool.structure.all_topological_sorts(g)[git][source]#
Return an iterator over all topological orderings of a directed acyclic graph.
- Parameters:
- g
Graph Directed acyclic graph.
- g
- Returns:
- ordersiterator over
numpy.ndarray Every ordering of the vertices in which all edges point forward.
- ordersiterator over
See also
topological_sortA single topological ordering
antichainsAll antichains of a directed acyclic graph
Notes
The orderings are generated by backtracking over the vertices without remaining in-edges [knuth-structured-1974], in time \(O(V)\) per ordering. Their number can grow factorially with the number of vertices. A
ValueErroris raised if the graph has a cycle.References
[knuth-structured-1974]Donald E. Knuth and Jayme L. Szwarcfiter, “A structured program to generate all topological sorting arrangements”, Information Processing Letters 2, 153-157 (1974), DOI: 10.1016/0020-0190(74)90001-5 [sci-hub, @tor]
Examples
>>> g = gt.Graph([(0, 1), (0, 2), (1, 3), (2, 3)]) >>> for o in gt.all_topological_sorts(g): ... print(o) [0 1 2 3] [0 2 1 3]