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.
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))`
.
A directed acyclic graph (DAG)
Generations are defined for directed graphs only. If the graph G
is undirected, a NetworkXError
is raised.
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
If G
is changed while the returned iterator is being processed.
Stratifies a DAG into generations.
Yields sets of nodes representing each generation.
>>> DG = nx.DiGraph([(2, 1), (3, 1)])See :
... [sorted(generation) for generation in nx.topological_generations(DG)] [[2, 3], [1]]
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.dag.topological_generations
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