Flatten directed, acyclic graph

graph theoryterminology

Suppose I have a directed, acyclic graph where $A \to B$ represents that $A$ depends on $B$.

I want to 'flatten' this graph so that each vertex has an edge to all direct and indirect dependencies. Ie. create a new graph such that if $A \to B$ and $B \to C$ in the original graph, then the new graph will contain $A \to B$, $B \to C$, and $A \to C$.

What is the proper name for this operation, and are there existing algorithms that can perform this task?

Best Answer

This is the transitive closure graph (or sometimes reachability graph) and can be implemented in nearly all graph software. In Mathematica:

g = Graph[{1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 
   1 \[DirectedEdge] 4, 3 \[DirectedEdge] 4, 2 \[DirectedEdge] 4, 
   4 \[DirectedEdge] 5}, VertexLabels -> "Name"]

enter image description here

TransitiveClosureGraph[g, VertexLabels -> "Name"]

enter image description here