我正在尝试分别读取具有源目标权重值的文件,以找到最短路径并使用最终权重打印该路径。我正在使用Networkx来使用Dijkstra功能。但是,当我执行时,我会收到此通知:
<function shortest_path at 0x7f9a13c39230>
<function bidirectional_dijkstra at 0x7f9a13c48140>
我最初只使用shortest_path
函数,因为我以某种方式搞砸了它,因此使用了bidirectional_dijkstra
函数。
有问题的文件包含标题为example.txt的虚拟数据:
D1 D5 7
D1 D2 6
D5 D4 7
D5 D3 7
D5 D3 3
D5 D2 4
D2 D2 1
D4 D3 1
我在Python中的方法:
#!/usr/bin/env python
import os.path
import networkx as nx
from sys import argv
#!script, filename = argv
#assigns example to open the file example.txt
example = open("example.txt", "r")
print("\n This is what we have in our file:\n")
#prints the open file
print example.read()
G =nx.Graph()
for line in example:
source, target, weight = line.split()
nx.shortest_path(G,[source, target, weight])
print ( nx.shortest_path)
print ( nx.bidirectional_dijkstra)
#for some reason, this is printing:
#
#<function shortest_path at 0x7fe480d56230>
#<function bidirectional_dijkstra at 0x7fe480d65140>
答案 0 :(得分:0)
所以,我收到的消息是因为我没有正确定义边缘。 这是更新后的代码:
Margin