Provided by: erlang-manpages_16.b.3-dfsg-1ubuntu2_all

**NAME**

digraph_utils - Algorithms for Directed Graphs

**DESCRIPTION**

Thedigraph_utilsmodule implements some algorithms based on depth-first traversal of directed graphs. See thedigraphmodule for basic functions on directed graphs. Adirectedgraph(or just "digraph") is a pair (V, E) of a finite set V ofverticesand a finite set E ofdirectededges(or just "edges"). The set of edges E is a subset of V x V (the Cartesian product of V with itself). Digraphs can be annotated with additional information. Such information may be attached to the vertices and to the edges of the digraph. A digraph which has been annotated is called alabeleddigraph, and the information attached to a vertex or an edge is called alabel. An edge e = (v, w) is said toemanatefrom vertex v and to beincidenton vertex w. If there is an edge emanating from v and incident on w, then w is said to be anout-neighbourof v, and v is said to be anin-neighbourof w. ApathP from v[1] to v[k] in a digraph (V, E) is a non-empty sequence v[1], v[2], ..., v[k] of vertices in V such that there is an edge (v[i],v[i+1]) in E for 1 <= i < k. Thelengthof the path P is k-1. P is acycleif the length of P is not zero and v[1] = v[k]. Aloopis a cycle of length one. Anacyclicdigraphis a digraph that has no cycles. Adepth-firsttraversalof a directed digraph can be viewed as a process that visits all vertices of the digraph. Initially, all vertices are marked as unvisited. The traversal starts with an arbitrarily chosen vertex, which is marked as visited, and follows an edge to an unmarked vertex, marking that vertex. The search then proceeds from that vertex in the same fashion, until there is no edge leading to an unvisited vertex. At that point the process backtracks, and the traversal continues as long as there are unexamined edges. If there remain unvisited vertices when all edges from the first vertex have been examined, some hitherto unvisited vertex is chosen, and the process is repeated. Apartialorderingof a set S is a transitive, antisymmetric and reflexive relation between the objects of S. The problem oftopologicalsortingis to find a total ordering of S that is a superset of the partial ordering. A digraph G = (V, E) is equivalent to a relation E on V (we neglect the fact that the version of directed graphs implemented in thedigraphmodule allows multiple edges between vertices). If the digraph has no cycles of length two or more, then the reflexive and transitive closure of E is a partial ordering. AsubgraphG' of G is a digraph whose vertices and edges form subsets of the vertices and edges of G. G' ismaximalwith respect to a property P if all other subgraphs that include the vertices of G' do not have the property P. Astronglyconnectedcomponentis a maximal subgraph such that there is a path between each pair of vertices. Aconnectedcomponentis a maximal subgraph such that there is a path between each pair of vertices, considering all edges undirected. Anarborescenceis an acyclic digraph with a vertex V, theroot, such that there is a unique path from V to every other vertex of G. Atreeis an acyclic non-empty digraph such that there is a unique path between every pair of vertices, considering all edges undirected.

**DATA** **TYPES**

digraph()A digraph as returned bydigraph:new/0,1.

**EXPORTS**

arborescence_root(Digraph)->no|{yes,Root}Types: Digraph = digraph() Root =digraph:vertex()Returns{yes,Root}ifRootis therootof the arborescenceDigraph,nootherwise.components(Digraph)->[Component]Types: Digraph = digraph() Component = [digraph:vertex()] Returns a list ofconnectedcomponents. Each component is represented by its vertices. The order of the vertices and the order of the components are arbitrary. Each vertex of the digraphDigraphoccurs in exactly one component.condensation(Digraph)->CondensedDigraphTypes: Digraph = CondensedDigraph = digraph() Creates a digraph where the vertices are thestronglyconnectedcomponentsofDigraphas returned bystrong_components/1. If X and Y are two different strongly connected components, and there exist vertices x and y in X and Y respectively such that there is an edgeemanatingfrom x andincidenton y, then an edge emanating from X and incident on Y is created. The created digraph has the same type asDigraph. All vertices and edges have the defaultlabel[]. Each and everycycleis included in some strongly connected component, which implies that there always exists atopologicalorderingof the created digraph.cyclic_strong_components(Digraph)->[StrongComponent]Types: Digraph = digraph() StrongComponent = [digraph:vertex()] Returns a list ofstronglyconnectedcomponents. Each strongly component is represented by its vertices. The order of the vertices and the order of the components are arbitrary. Only vertices that are included in somecycleinDigraphare returned, otherwise the returned list is equal to that returned bystrong_components/1.is_acyclic(Digraph)->boolean()Types: Digraph = digraph() Returnstrueif and only if the digraphDigraphisacyclic.is_arborescence(Digraph)->boolean()Types: Digraph = digraph() Returnstrueif and only if the digraphDigraphis anarborescence.is_tree(Digraph)->boolean()Types: Digraph = digraph() Returnstrueif and only if the digraphDigraphis atree.loop_vertices(Digraph)->VerticesTypes: Digraph = digraph() Vertices = [digraph:vertex()] Returns a list of all vertices ofDigraphthat are included in someloop.postorder(Digraph)->VerticesTypes: Digraph = digraph() Vertices = [digraph:vertex()] Returns all vertices of the digraphDigraph. The order is given by adepth-firsttraversalof the digraph, collecting visited vertices in postorder. More precisely, the vertices visited while searching from an arbitrarily chosen vertex are collected in postorder, and all those collected vertices are placed before the subsequently visited vertices.preorder(Digraph)->VerticesTypes: Digraph = digraph() Vertices = [digraph:vertex()] Returns all vertices of the digraphDigraph. The order is given by adepth-firsttraversalof the digraph, collecting visited vertices in pre-order.reachable(Vertices,Digraph)->ReachableTypes: Digraph = digraph() Vertices = Reachable = [digraph:vertex()] Returns an unsorted list of digraph vertices such that for each vertex in the list, there is apathinDigraphfrom some vertex ofVerticesto the vertex. In particular, since paths may have length zero, the vertices ofVerticesare included in the returned list.reachable_neighbours(Vertices,Digraph)->ReachableTypes: Digraph = digraph() Vertices = Reachable = [digraph:vertex()] Returns an unsorted list of digraph vertices such that for each vertex in the list, there is apathinDigraphof length one or more from some vertex ofVerticesto the vertex. As a consequence, only those vertices ofVerticesthat are included in somecycleare returned.reaching(Vertices,Digraph)->ReachingTypes: Digraph = digraph() Vertices = Reaching = [digraph:vertex()] Returns an unsorted list of digraph vertices such that for each vertex in the list, there is apathfrom the vertex to some vertex ofVertices. In particular, since paths may have length zero, the vertices ofVerticesare included in the returned list.reaching_neighbours(Vertices,Digraph)->ReachingTypes: Digraph = digraph() Vertices = Reaching = [digraph:vertex()] Returns an unsorted list of digraph vertices such that for each vertex in the list, there is apathof length one or more from the vertex to some vertex ofVertices. As a consequence, only those vertices ofVerticesthat are included in somecycleare returned.strong_components(Digraph)->[StrongComponent]Types: Digraph = digraph() StrongComponent = [digraph:vertex()] Returns a list ofstronglyconnectedcomponents. Each strongly component is represented by its vertices. The order of the vertices and the order of the components are arbitrary. Each vertex of the digraphDigraphoccurs in exactly one strong component.subgraph(Digraph,Vertices)->SubGraphsubgraph(Digraph,Vertices,Options)->SubGraphTypes: Digraph = SubGraph = digraph() Vertices = [digraph:vertex()] Options = [{type, SubgraphType} | {keep_labels, boolean()}] SubgraphType = inherit | [digraph:d_type()] Creates a maximalsubgraphofDigraphhaving as vertices those vertices ofDigraphthat are mentioned inVertices. If the value of the optiontypeisinherit, which is the default, then the type ofDigraphis used for the subgraph as well. Otherwise the option value oftypeis used as argument todigraph:new/1. If the value of the optionkeep_labelsistrue, which is the default, then thelabelsof vertices and edges ofDigraphare used for the subgraph as well. If the value isfalse, then the default label,[], is used for the subgraph's vertices and edges.subgraph(Digraph,Vertices)is equivalent tosubgraph(Digraph,Vertices,[]). There will be abadargexception if any of the arguments are invalid.topsort(Digraph)->Vertices|falseTypes: Digraph = digraph() Vertices = [digraph:vertex()] Returns atopologicalorderingof the vertices of the digraphDigraphif such an ordering exists,falseotherwise. For each vertex in the returned list, there are noout-neighboursthat occur earlier in the list.

**SEE** **ALSO**

digraph(3erl)