def shortest_path(graph, source, target):
"""Return the windowed shortest path between source and target
in the given graph.
Graph is expected to be a dict {node: {successors}}.
Return value is a tuple of 2-tuple, each 2-tuple representing a
window of size 2 on the path.
"""
if source == target: return tuple() # no move needed
nxg = nx.Graph()
for node, succs in graph.items():
for succ in succs:
nxg.add_edge(node, succ)
return tuple(nx.dijkstra_path(nxg, source, target))
评论列表
文章目录