networkx.algorithms.dag.transitive_closure¶

transitive_closure
(G, reflexive=False)[source]¶ Returns transitive closure of a directed graph
The transitive closure of G = (V,E) is a graph G+ = (V,E+) such that for all v, w in V there is an edge (v, w) in E+ if and only if there is a path from v to w in G.
Handling of paths from v to v has some flexibility within this definition. A reflexive transitive closure creates a selfloop for the path from v to v of length 0. The usual transitive closure creates a selfloop only if a cycle exists (a path from v to v with length > 0). We also allow an option for no selfloops.
 Parameters
G (NetworkX DiGraph) – A directed graph
reflexive (Bool or None, optional (default: False)) – Determines when cycles create selfloops in the Transitive Closure. If True, trivial cycles (length 0) create selfloops. The result is a reflexive tranistive closure of G. If False (the default) nontrivial cycles create selfloops. If None, selfloops are not created.
 Returns
The transitive closure of
G
 Return type
NetworkX DiGraph
 Raises
NetworkXNotImplemented – If
G
is not directed
References
 TODO this function applies to all directed graphs and is probably misplaced
here in dag.py