更新时间: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))