【问题标题】:How to find the shortest path between Vertices, but have a limit to search depth, using Tinkerpop 3?如何使用 Tinkerpop 3 找到顶点之间的最短路径,但对搜索深度有限制?
【发布时间】:2016-04-21 12:32:19
【问题描述】:

我试图在 Tinkerpop 3 中找到两个顶点(fromNode 和 toNode)之间的最短路径,其限制是我需要在某个深度 N 处停止搜索。没有这个限制,我将永远无法完成图表太大。

到目前为止,这是我能想到的最好的:

titanGraph.traversal().V(fromNode)
    .repeat(out().simplePath())
    .times(N)
    .emit(hasId(toNode)).path();

这个问题,以及我尝试过的所有其他方法,是长度为 N 的路径作为结果返回,即使它们没有到达 toNode。

我需要返回 fromNode 和 toNode 之间长度为 N 或以下的所有路径。

【问题讨论】:

    标签: graph-databases titan gremlin tinkerpop3


    【解决方案1】:

    你是在正确的轨道上

    titanGraph.traversal().V(fromNode)
        .repeat(out().simplePath())
        .times(N)
        .emit(hasId(toNode)).hasId(toNode).path();
    

    【讨论】:

    • 感谢您的指导,我很乐意接受答案,但我的 tinkerpop 版本为此提供了 NPE。我必须升级我正在使用的 Titan 版本来升级 tinkerpop。之后会回来查看。
    • 好的,我很确定我用 TinkerPop 3.0.1 对 Titan 1.0 运行了这个。如果您有一个小示例图来重现 NPE,请将其添加到您的问题中。谢谢。
    • 实际上,这很好用。非常感谢,我的 NPE 与 Times 和 Until 的组合有关。
    • 一个问题 - 我怎样才能确保只找到最短路径,并且一旦找到路径就不会继续遍历?例如。如果不需要,它不会遍历 N 个链接。
    • 知道了,只需要最后加上'limit(1)'即可。
    猜你喜欢
    • 2021-03-11
    • 1970-01-01
    • 2017-06-06
    • 2021-05-25
    • 1970-01-01
    • 2016-10-30
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多