Module Graph


module Graph: sig  end
Directed graphs.

This module implements directed graphs (digraphs). A directed graph is a set V of vertices and a set E of ordered pairs (a,b) called edges, where a, b are in V. The vertex a is called the initial vertex of the edge and b the terminal vertex.


type 'a t 
The type of graphs for vertices of type 'a.
val empty : unit -> 'a t
empty () returns an empty graph.
val copy : 'a t -> 'a t
Return a copy of the given graph.
val add_edge : 'a t -> 'a -> 'a -> 'a t
add_edge g x y adds to graph g the edge from x to y, i.e. the pair (x,y) is added to the set E of edges.
val add_vertex : 'a t -> 'a -> 'a t
add_vertex g v adds vertex v to graph g. This function is useful to add a vertex that is not connected with other vertices of the graph.
val add_adjacency_list : 'a t -> 'a -> 'a list -> 'a t
add_adjacency_list g v l adds for all vertices u in l an edge (v,u) to graph g.
val from_list : 'a t -> ('a * 'a) list -> 'a t
from_list g l adds to graph g all edges that are contained in list l.
val adjacent_vertices : 'a t -> 'a -> 'a list
adjacent_vertices g v returns all vertices u such that there exists an edge (v,u) in g.
val dfs1 : 'a t -> ('a * int * int * int) list
val is_empty : 'a t -> bool
Returns true if and only if the set of vertices of the given graph is empty.
val topological_sort : 'a t -> 'a list
top_sort g returns a topological sort of graph g such that if g contains an edge (u,v), then u appears before v in the ordering.
val scc : 'a t -> 'a list list
scc g returns the strongly connected components of g. A strongly connected component of a directed graph G=(V,E) is a maximal set of vertices U (U is a subset of V) such that for every pair of vertices v and u in U, there is a path from u to v and vice versa; that is, vertices u and v are reachable from each other.
val component_graph : 'a t -> 'a list t
component_graph G returns the component graph SCC(G) obtained by shrinking each strongly connected component of G to a single vertex.
val reachable : 'a t -> 'a -> 'a list
reachable g v returns all vertices u that are reachable from vertex v, i.e. for all u of the result there exists a path from v to u.
val out_degree : 'a t -> 'a -> int
out_degree g x returns the number of edges with x as their initial vertex.
val in_degree : 'a t -> 'a -> int
in_degree g x returns the number of edges with x as their terminal vertex.
val edges : 'a t -> ('a * 'a) list
edges g returns the set E of edges of g as a list of pairs.
val vertices : 'a t -> 'a list
vertices g returns the set V of vertices of g as a list.
val transpose : 'a t -> 'a t
transpose g returns the transpose of g. For a graph G=(V,E) the transpose of G is defined as T(G) = (V,T(E)), where T(E) contains all edges (u,v) such that (v,u) are in E.