当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python NetworkX dag_longest_path用法及代码示例

本文简要介绍 networkx.algorithms.dag.dag_longest_path 的用法。

用法:

dag_longest_path(G, weight='weight', default_weight=1, topo_order=None)

返回有向无环图 (DAG) 中的最长路径。

如果G 具有带有weight 属性的边,则边数据用作权重值。

参数

GNetworkX 有向图

有向无环图 (DAG)

weightstr,可选

用于权重的边数据键

default_weight整数,可选

没有权重属性的边的权重

topo_order: list or tuple, optional

G 的拓扑顺序(如果没有,该函数将计算一个)

返回

列表

最长路径

抛出

NetworkXNotImplemented

如果 G 未定向

例子

>>> 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(DG)
[0, 1, 2]
>>> nx.dag_longest_path(DG, weight="cost")
[0, 2]

相关用法


注:本文由纯净天空筛选整理自networkx.org大神的英文原创作品 networkx.algorithms.dag.dag_longest_path。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。