Skip to content

Stable topological order gives unexpected result #149

@maximebuyse

Description

@maximebuyse

Here is a code snippet that builds a graph and prints the vertices in stable topological order:

module G = 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" 

module Topo = Graph.Topological.Make_stable (G)

let () = Topo.iter (fun v -> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions