dag_longest_path_length¶
- dag_longest_path_length(G, weight='weight', default_weight=1)[source]¶
Returns the longest path length in a DAG
- Parameters
- GNetworkX DiGraph
A directed acyclic graph (DAG)
- weightstring, optional
Edge data key to use for weight
- default_weightint, optional
The weight of edges that do not have a weight attribute
- Returns
- int
Longest path length
- Raises
- NetworkXNotImplemented
If
G
is not directed
See also
Examples
>>> DG = nx.DiGraph([(0, 1, {'cost':1}), (1, 2, {'cost':1}), (0, 2, {'cost':42})]) >>> list(nx.all_simple_paths(DG, 0, 2)) [[0, 1, 2], [0, 2]] >>> nx.dag_longest_path_length(DG) 2 >>> nx.dag_longest_path_length(DG, weight="cost") 42