Menu

#1 [graph] Topological sort with single vertex

1.0
closed
graph (1)
2019-12-11
2019-12-11
No

Hi Alexander,

just tested yours graph library for kotlin when seeking for topological sort in Kotlin.

Unfortunately I failed with graph with single vertex only:

val vertices = arrayOf("vertex")
val mutableGraph = mutableGraphOf<identifier, int="">(values = *vertices)
val toposort = analystOf(mutableGraph).sortTopological()</identifier,>

I was expecting the output of toposort will be set with single item "vertex", but empty set was generated.

I briefly checked your code and found you are copying the graph just by edges / you omit disconnected vertices:
protected constructor(graph: Graph<v, e="">) {
for(vertex in graph.vertexes) {
vertex.startsIn.forEach(::cloneEdge)
vertex.endsIn.forEach(::cloneEdge)
}
}</v,>

I didn't investigate deeper the purpose of this method, but IMO opinion rejecting orphaned vertices is wrong in general for any use-case.

Also I would like to ask you to extend the library by constructor of mutable graph that does not require any vertices/edges when creating new instance. I'm processing large json and gathering all vertices in advance is very inconvenient, later on I have to put edges into the same graph, it would be nice to start with an empty graph and add vertices and edges as going through the structure in single pass.

Discussion

  • Alexander Kornilov

    • status: open --> closed
     
  • Alexander Kornilov

    • summary: [graph] Topological sort with signle vertex --> [graph] Topological sort with single vertex
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.