Legend:
Library
Module
Module type
Parameter
Class
Class type
Simple Graph Interface
A collections of algorithms on (mostly read-only) graph structures. The user provides her own graph structure as a ('v, 'e) CCGraph.t, where 'v is the type of vertices and 'e the type of edges (for instance, 'e = ('v * 'v) is perfectly fine in many cases).
Such a ('v, 'e) CCGraph.t structure is a record containing three functions: two relate edges to their origin and destination, and one maps vertices to their outgoing edges. This abstract notion of graph makes it possible to run the algorithms on any user-specific type that happens to have a graph structure.
Many graph algorithms here take an iterator of vertices as input. The helper module Iter contains basic functions for that, as does the iter library on opam. If the user only has a single vertex (e.g., for a topological sort from a given vertex), they can use Iter.return x to build a iter of one element.
val is_dag :
tbl:'vset->eq:('v->'v-> bool)->graph:('v, _)t->'viter->
bool
is_dag ~graph vs returns true if the subset of graph reachable from vs is acyclic.
since 0.18
Topological Sort
exceptionHas_cycle
val topo_sort :
eq:('v->'v-> bool)->?rev:bool ->tbl:'vset->graph:('v, 'e)t->'viter->'v list
topo_sort ~graph seq returns a list of vertices l where each element of l is reachable from seq. The list is sorted in a way such that if v -> v' in the graph, then v comes before v' in the list (i.e. has a smaller index). Basically v -> v' means that v is smaller than v'. See wikipedia.
parametereq
equality predicate on vertices (default (=)).
parameterrev
if true, the dependency relation is inverted (v -> v' means v' occurs before v).
Strongly connected components reachable from the given vertices. Each component is a list of vertices that are all mutually reachable in the graph. The components are explored in a topological order (if C1 and C2 are components, and C1 points to C2, then C2 will be yielded before C1). Uses Tarjan's algorithm.
let open CCGraph in
let open Dot in
with_out "/tmp/truc.dot"
(fun out ->
pp ~attrs_v:(fun i -> [`Label (string_of_int i)]) ~graph:divisors_graph out 42
)
val mk_mut_tbl :
eq:('v->'v-> bool)->?hash:('v-> int)->int ->('v, 'a)mut_graph
Make a new mutable graph from a Hashtbl. Edges are labelled with type 'a.
Immutable Graph
A classic implementation of a graph structure on totally ordered vertices, with unlabelled edges. The graph allows to add and remove edges and vertices, and to iterate on edges and vertices.