【发布时间】:2018-07-20 14:23:50
【问题描述】:
假设我们有 4 个节点:
{id:1, name:"one"}
{id:2, name:"two"}
{id:3, name:"three"}
{id:4, name:"four"}
假设节点 1 链接到节点 2,节点 2 链接到 3,节点 3 链接到 4,所以结果会是这样的:
(1)-->(2)-->(3)-->(4)
如何以任何给定顺序获得多个给定节点之间的最短路径?举几个例子:
findShortestPath(2,4,3) 应该导致:(2)-->(3)-->(4)
findShortestPath(3,1) 应该导致:(1)-->(2)-->(3)
findShortestPath(4,1) 应该导致:(1)-->(2)-->(3)-->(4)
findShortestPath(3,2) 应导致:(2)-->(3)
我尝试过类似的方法,但我觉得我走错了路,这不是最高效的解决方案。请注意,我的查询是以编程方式构建的,因为它可以包含任意数量和种类的节点。
如果输入是:(2),(3),(1)
这将导致双重 for 循环构造如下:
match p=allShortestPaths((p2)-[*]-(p3)),allShortestPaths((p2)-[*]-(p1)),allShortestPaths((p3)-[*]-(p1)) where p1.name="Keanu Reeves" and p2.name="Gene Hackman" and p3.name="Clint Eastwood" return p;
我的问题是我无法为allShortestPaths() 函数提供多个节点。仅允许具有 1 个关系的 2 个节点。
【问题讨论】: