You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a code snippet that builds a graph and prints the vertices in stable topological order:
moduleG=Graph.Persistent.Digraph.Concrete (String)
let g0 =G.empty
let g1 =G.add_edge g0 "a""b"let g2 =G.add_edge g1 "a""c"let g =G.add_edge g2 "c""a"moduleTopo=Graph.Topological.Make_stable (G)
let()=Topo.iter (funv -> print_endline v) g
The graph created here can be represented as b <- a <-> c, and the topological order given by ocamlgraph is: a, b, c.
It seems to me that this is not a valid topological order because b comes before c and the definition given in the doc is: if vertex x is visited before vertex y then either there is a path from x to y, or there is no path from y to x. Here there is no path from b to c but there is a path from c to b. So my understanding is that c should come before b. The stable order is supposed to take the comparison function (here alphabetical order) only between vertices that are topologically equivalent which I believe b and c are not in this example.
Note that if one uses the classic topological order (Make instead of Make_stable) the order is a, c, b
The text was updated successfully, but these errors were encountered:
The problem seems to be that when dealing with a cycle, all vertices of the cycles are added to the queue. When treating a vertex from the queue, its successors are added to the queue (if they have degree 0) and can later bypass the other vertices of the cycle that are still in the queue (because we don't take order of insertion into account when dequeuing).
A possible fix could be to treat all vertices of the cycles at the same time without using the queue. I implemented this and it seems to work (at least on the example above). I opened a PR with the change.
Here is a code snippet that builds a graph and prints the vertices in stable topological order:
The graph created here can be represented as
b <- a <-> c
, and the topological order given by ocamlgraph is:a, b, c
.It seems to me that this is not a valid topological order because
b
comes beforec
and the definition given in the doc is:if vertex x is visited before vertex y then either there is a path from x to y, or there is no path from y to x
. Here there is no path fromb
toc
but there is a path fromc
tob
. So my understanding is thatc
should come beforeb
. The stable order is supposed to take the comparison function (here alphabetical order) only between vertices that aretopologically equivalent
which I believeb
andc
are not in this example.Note that if one uses the classic topological order (
Make
instead ofMake_stable
) the order isa, c, b
The text was updated successfully, but these errors were encountered: