question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Topological sort returns different result for similar graphs

See original GitHub issue
import 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:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peter-empencommented, Dec 19, 2015

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

topoOrder withLayerOrdering yourOrdering
0reactions
sevenevescommented, Dec 21, 2015

@peter-empen thank you. I’ll give it a try

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found