我目前正在使用py2neo
来使用使用最短路径的查询,neo4j
代码是:
MATCH p=(c:Ciudad)-[*]-(l:Ciudad)
WHERE c.nombre = '%s' and l.nombre = '%s'
RETURN p as shortestPath, reduce(precio=0, r in relationships(p) | precio+r.precio) AS totalPrecio
ORDER BY totalPrecio ASC LIMIT 1;
当我在web上使用它时,它会给出节点1-关系-节点2的列表,但是当我使用以下命令执行它时:
string= "MATCH p=(c:Ciudad)-[*]-(l:Ciudad)
WHERE c.nombre = '%s' and l.nombre = '%s'
RETURN p as shortestPath, reduce(precio=0, r in relationships(p) | precio+r.precio) AS totalPrecio
ORDER BY totalPrecio ASC LIMIT 1;" %(salida, llegada)
n = graph.run(string)
shortestPath
只有关系,没有节点
有人知道如何得到与网络相同的结果吗
旁白:您的Cypher代码实际上并没有生成保证为单个“最短路径”的值
shortestpath
。它只是生成任意长度的所有匹配路径。为了回答你的问题,我将忽略这个问题,并假设现有的行为是你想要的如果结果中不包含返回路径中的节点,则可以在路径上使用NODES()函数,如以下代码段所示:
相关问题 更多 >
编程相关推荐