networkx shortest_path() 如何在距离相近的情况下选择跳数较少的路径

问题描述 投票:0回答:0

我想实现一个最短路径算法,在距离相近的情况下选择跳数较少的路径

我可以这样设置权重回调:

def get_weight(src, dst, attr):
    # can here get the current path length ??
    # return weight + path_length*length_factor

    return 1


path = nx.shortest_path(g, source=s, target=d, weight=get_weight)

但是在

get_weight()
中没有获取当前路径长度的信息。

NetworkX 可以实现吗?或者还有其他 python 库支持此功能吗?

谢谢。

python routes networkx path-finding
© www.soinside.com 2019 - 2024. All rights reserved.