我正在开发一个使用Apacheage作为图形数据库的Python项目,我需要找到两个可能的 node 之间的最短路径.我如何使用Python实现这一点?创建 node 和图形 struct 的代码如下:
# Python code to create nodes and relationships
from age import Age
age = Age()
node_a = age.create_node("City", {"name": "New York"})
node_b = age.create_node("City", {"name": "Los Angeles"})
node_c = age.create_node("City", {"name": "Chicago"})
node_d = age.create_node("City", {"name": "Houston"})
edge_ab = age.create_edge(node_a, node_b, "CONNECTED", {"distance": 2451})
edge_ac = age.create_edge(node_a, node_c, "CONNECTED", {"distance": 713})
edge_cd = age.create_edge(node_c, node_d, "CONNECTED", {"distance": 940})
edge_bd = age.create_edge(node_b, node_d, "CONNECTED", {"distance": 1375})
# Sample graph structure:
# New York --(2451)-- Los Angeles
# | |
# (713) (1375)
# | |
# Chicago --(940)-- Houston
我怎样才能找到从纽约到休斯顿的最短路由?