A class to generate all possible topological sorting of a dag.
If the graph has no edges, it will generate all possible permutations.
If the graph has edges, it will generate all possible permutations of the dag that are a topological sorting of the graph.
Typical usage:
DagTopologicalSortIterator dag_topological_sort(5);
dag_topological_sort.AddArc(0, 1); dag_topological_sort.AddArc(1, 2); dag_topological_sort.AddArc(3, 4);
for (const auto& permutation : dag_topological_sort) { ///< Do something with each permutation. }
- Note
- to test if there are cycles, it is enough to check if at least one iteration occurred in the above loop.
Note 2: adding an arc during an iteration is not supported and the behavior is undefined.
Definition at line 1011 of file util.h.