networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesYieldsBackRef
topological_generations(G)

A topological generation is node collection in which ancestors of a node in each generation are guaranteed to be in a previous generation, and any descendants of a node are guaranteed to be in a following generation. Nodes are guaranteed to be in the earliest possible generation that they can belong to.

Notes

The generation in which a node resides can also be determined by taking the max-path-distance from the node to the farthest leaf node. That value can be obtained with this function using :None:None:`enumerate(topological_generations(G))`.

Parameters

G : NetworkX digraph

A directed acyclic graph (DAG)

Raises

NetworkXError

Generations are defined for directed graphs only. If the graph G is undirected, a NetworkXError is raised.

NetworkXUnfeasible

If G is not a directed acyclic graph (DAG) no topological generations exist and a NetworkXUnfeasible exception is raised. This can also be raised if G is changed while the returned iterator is being processed

RuntimeError

If G is changed while the returned iterator is being processed.

Stratifies a DAG into generations.

Yields

sets of nodes

Yields sets of nodes representing each generation.

See Also

topological_sort

Examples

>>> DG = nx.DiGraph([(2, 1), (3, 1)])
... [sorted(generation) for generation in nx.topological_generations(DG)] [[2, 3], [1]]
See :

Back References

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

networkx.algorithms.dag.topological_generations

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#151
type: <class 'function'>
Commit: