Topological sort returns different result for similar graphs
See original GitHub issueimport scalax.collection.Graph
import scalax.collection.GraphEdge.DiEdge
import scalax.collection.GraphPredef._
object MainApp extends App {
//Creates new graph
def graph: Graph[String, DiEdge] = Graph(
"A" ~> "B",
"A" ~> "C",
"A" ~> "D",
"B" ~> "E",
"B" ~> "F",
"C" ~> "G",
"C" ~> "H",
"D" ~> "F",
"D" ~> "G"
)
val results = 1 to 20 map { _ =>
graph.topologicalSort.mkString("")
}
println(results.tail.forall(_ == results.head))
}
Given the above code, I expect to get same topological sort for the similar graphs created by graph
method. But this app prints false
and proves the opposite. All of the results of topologicalSort call do comply to topological sort but it’s needed to have a mechanism for fixing this order for similar graphs.
Setting ordering
in graph.componentTraverser(ordering = ...).topologicalSort
does not fix the order for similar graphs.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Topological Sorting - GeeksforGeeks
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge u v, vertex u...
Read more >Topological sorting - Wikipedia
Precisely, a topological sort is a graph traversal in which each node v is visited only after all its dependencies are visited. A...
Read more >Topological Sort Algorithm - Scaler Topics
Essentially, topological sort is an algorithm which sorts a directed graph by returning an array or a vector, or a list, that consists...
Read more >Graph Algorithm #1: Topological Sort - Washington
Topological Sort Algorithm. Step 2: Delete this vertex of in-degree 0 and all its outgoing edges from the graph. Place it in the...
Read more >Coding Patterns: Topological Sort (Graph) - emre.me
Topological ordering starts with one of the sources and ends at one of the sinks. A topological ordering is possible only when the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The topological sort available with Version 2.10.0 fulfills this feature request. You either make the sort ordered or order the result. The latter is done by
@peter-empen thank you. I’ll give it a try