dag_longest_path_length#

dag_longest_path_length(G, weight='weight', default_weight=1)[source]#

返回有向无环图中的最长路径长度

Parameters:
GNetworkX DiGraph

一个有向无环图(DAG)

weightstring, 可选

用于权重的边数据键

default_weightint, 可选

没有权重属性的边的权重

Returns:
int

最长路径长度

Raises:
NetworkXNotImplemented

如果 G 不是有向图

See also

dag_longest_path

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