single_target_shortest_path#
- single_target_shortest_path(G, target, cutoff=None)[源代码]#
从到达目标的所有节点计算到目标的最短路径。
- 参数
- G网络X图表
- target节点标签
路径的目标节点
- cutoff整数,可选
深度以停止搜索。仅返回长度<=截止的路径。
- 返回
- lengths词典
以目标为关键字的最短路径词典。
参见
shortest_path
,single_source_shortest_path
笔记
最短的路径不一定是唯一的。因此,源节点和每个目标节点之间可以有多条路径,所有路径都具有相同的“最短”长度。对于每个目标节点,此函数只返回其中一个路径。
实例
>>> G = nx.path_graph(5, create_using=nx.DiGraph()) >>> path = nx.single_target_shortest_path(G, 4) >>> path[0] [0, 1, 2, 3, 4]