networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
transitive_reduction(G)

The transitive reduction 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 (v,w) is in E and there is no path from v to w in G with length greater than 1.

Parameters

G : NetworkX DiGraph

A directed acyclic graph (DAG)

Raises

NetworkXError

If G is not a directed acyclic graph (DAG) transitive reduction is not uniquely defined and a NetworkXError exception is raised.

Returns

NetworkX DiGraph

The transitive reduction of G

Returns transitive reduction of a directed graph

Examples

To perform transitive reduction on a DiGraph:

>>> DG = nx.DiGraph([(1, 2), (2, 3), (1, 3)])
... TR = nx.transitive_reduction(DG)
... list(TR.edges) [(1, 2), (2, 3)]

To avoid unnecessary data copies, this implementation does not return a DiGraph with node/edge data. To perform transitive reduction on a DiGraph and transfer node/edge data:

>>> DG = nx.DiGraph()
... DG.add_edges_from([(1, 2), (2, 3), (1, 3)], color='red')
... TR = nx.transitive_reduction(DG)
... TR.add_nodes_from(DG.nodes(data=True))
... TR.add_edges_from((u, v, DG.edges[u, v]) for u, v in TR.edges)
... list(TR.edges(data=True)) [(1, 2, {'color': 'red'}), (2, 3, {'color': 'red'})]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.dag.transitive_reduction

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/dag.py#751
type: <class 'function'>
Commit: