简体   繁体   English

密码allShortestPaths仅返回一条路径吗?

[英]Cypher allShortestPaths just return one path?

Background statement: 背景说明:

  • I have a graph like bellow: 我有一个像下面的图: 在此处输入图片说明

  • I want to find all the path between Node A and Node F (something like how many ways I can reach F from A), then my Cypher like this bellow: 我想找到节点A和节点F之间的所有路径(就像我可以从A到达F的方式一样),然后找到如下所示的Cypher:

 MATCH (start:kg:test), (end:kg:test), p = allShortestPaths((start)-[*..8]-(end)) where start.value = 'A' and end.value = 'F' RETURN start, end, p 
  • As I expected, this query will return the whole graph, but it just returns A->F (return the same thing with using the shortestPath function), like bellow: 如我所料,此查询将返回整个图形,但仅返回A-> F(使用shortestPath函数返回相同的内容),例如下面所示: 在此处输入图片说明

Problems 问题

  • Why that query won't return all the different paths in the graph? 为什么该查询不会返回图形中的所有不同路径?
  • Do I misuse the allShortestPaths function? 我会滥用allShortestPaths函数吗?
  • How can I get all the path from Node A to Node F? 如何获取从节点A到节点F的所有路径?

thanks 谢谢

shortestPath() returns the single shortest path between the nodes (and if there are multiple of the same size it just returns the first that it finds). shortestPath()返回节点之间的最短路径(如果有多个相同大小的路径,则仅返回找到的第一个路径)。

If there are multiple paths that could have been returned by shortestPath() (they will all have the same size), then allShortesPaths() will return them. 如果有可能已被退回多路径shortestPath()他们都将具有相同的大小),然后allShortesPaths()将返回他们。

If you just want to find all possible paths between two nodes (the length of the path doesn't matter, and you don't care about shortest paths at all), then you don't need to use either of these functions. 如果只想查找两个节点之间的所有可能路径(路径的长度无关紧要,根本就不关心最短的路径),则不需要使用这两个函数。

MATCH p=(start:kg:test)-[*..8]-(end:kg:test)
    where start.value = 'A' and end.value = 'F'
    RETURN start, end, p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM