topological_generations#
- graph_tool.structure.topological_generations(g)[git][source]#
Return the topological generation of every vertex of a directed acyclic graph.
- Parameters:
- g
Graph Directed acyclic graph.
- g
- Returns:
- gen
VertexPropertyMap The generation of every vertex: zero for the vertices without in-edges, and otherwise the length of the longest path from one of them.
- gen
See also
topological_sortA topological ordering
dag_longest_pathLongest path of a directed acyclic graph
antichainsAll antichains of a directed acyclic graph
Notes
The generations partition the vertices into layers such that every edge goes from a layer to a later one, as used e.g. by
layered_layout(). They are computed with Kahn’s algorithm [kahn-topological-1962] in time \(O(V + E)\). AValueErroris raised if the graph has a cycle.References
[kahn-topological-1962]Arthur B. Kahn, “Topological sorting of large networks”, Communications of the ACM 5, 558-562 (1962), DOI: 10.1145/368996.369025 [sci-hub, @tor]
Examples
>>> g = gt.Graph([(0, 1), (0, 2), (1, 3), (2, 3), (3, 4), (0, 4)]) >>> print(gt.topological_generations(g).a) [0 1 1 2 3]