dag_longest_path_length#

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

返回 DAG 中的最长路径长度

参数:
GNetworkX 有向图

一个有向无环图 (DAG)

weightstring, 可选

用于表示权重的边数据键

default_weightint, 可选

没有 weight 属性的边的权重

返回:
int

最长路径长度

抛出:
NetworkXNotImplemented

如果 G 不是有向图

另请参阅

dag_longest_path

示例

>>> 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