Module Graph1


module Graph1: 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 clear : 'a t -> unit
Empty a graph.
val copy : 'a t -> 'a t
Return a copy of the given graph.
val add_edge : 'a t -> 'a -> 'a -> unit
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 -> unit
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 -> unit
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 -> unit
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 top_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 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.