Open
Description
From the documentation it seems that one can generate all valid topological orders by altering the order of nodes in the layers:
Among others, layers are usefull to compute several valid topological orders by altering the order of nodes within layers.
However, the documentation does not explain this any further.
So for a given graph, e.g. the graph below:
i would like to generate all valid topological orders, which are:
- 2 4 7 5
- 2 7 4 5
- 2 4 5 7
At the moment I'm only able to generate one:
import scalax.collection.Graph
import scalax.collection.GraphPredef._
import scalax.collection.GraphEdge._
val graph: Graph[Int, DiEdge] = Graph(2 ~> 4, 2 ~> 7, 4 ~> 5)
graph.topologicalSort match {
case Right(topOrder) => println(topOrder)
case Left(cycleNode) => throw new Error(s"Graph contains a cycle at node: ${cycleNode}.")
}
I've tried using custom node traversers and element traversers but i was not able to make them work. How can i generate all valid topological orders?