我有一个 Dijsktra 算法,我将其应用于从开放街道地图获得的图表。它适用于单个图表。
但是当我绘制两个相邻城市的图时,相同的算法在图之间找不到任何方法.. 我注意到连接两个城市的道路没有被任何 osmid 识别。:-/
我错过了什么吗?
class Pathfinding(nx.MultiDiGraph):
def __init__(self, incomin_graphe_data = None, **attr):
nx.MultiDiGraph.__init__(self,incomin_graphe_data,**attr)
def dijsktra(self,depart,final):
inf = float("inf")
F ,ds, s= set(), None ,None
D = {i: inf for i in self.nodes}
D[ depart ] = 0
pred = {}
priority_queue = [(0 , depart)]
while s != final:
ds, s = heapq.heappop(priority_queue)
F.add(s)
for y in self.neighbors(s):
w = self[s][y][0]['lenght']
dy = ds + w
if y not in F :
if D[y] > dy :
D[y] = dy
heapq.heappush(priority_queue,(dy,y))
pred[y] = s
path = [s]
while s != depart:
s = pred[s]
path.append(s)
return path
我使用的是 Dijkstra,下面的类型图是 MultiDiGraph。
add_Aubervilliers = "Aubervilliers, France"
Graphe_Aubervilliers = ox.graph_from_place(add_Aubervilliers, network_type='drive')
add_Saint_denis = " Saint denis, France "
Graphe_Saint_denis = ox.graph_from_place(add_Saint_denis, network_type = "drive")
Graph_Paris_Auber = nx.compose_all([ Graphe_Saint_denis, Graphe_Aubervilliers ])
我还尝试了以下命令
add_Saint_denis = " Saint denis, France "
Graphe_Saint_denis = ox.graph_from_adress(add_Saint_denis, infrastructure='way['highway']')
但它给出了同样的问题......我错过了什么吗?