topological_generations

topological_generations#

graph_tool.structure.topological_generations(g)[git][source]#

Return the topological generation of every vertex of a directed acyclic graph.

Parameters:
gGraph

Directed acyclic graph.

Returns:
genVertexPropertyMap

The generation of every vertex: zero for the vertices without in-edges, and otherwise the length of the longest path from one of them.

See also

topological_sort

A topological ordering

dag_longest_path

Longest path of a directed acyclic graph

antichains

All 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)\). A ValueError is 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]