且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Networkx:使用通用功能进行边缘权重计算

更新时间:2022-11-23 07:39:05

Neither graph.size nor graph.add_edge uses a function to evaluate the weight, they just store values with a given key. To make it easier to work with, just define a function to add an edge with the appropriate weight:

def add_euc2d_edge(graph, u, v):
    graph.add_edge(u, v, weight=euc_2d(graph, u, v))