10000 Generating all topological orders · Issue #129 · scala-graph/scala-graph · GitHub
[go: up one dir, main page]

Skip to content
Generating all topological orders #129
Open
@kevin-dp

Description

@kevin-dp

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:

afbeelding

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0