Gremlin从多个顶点到单个顶点的所有最短路径

问题描述 投票:0回答:1

以下堆栈溢出问题

How to increase performance of shortest path using Gremlin?

展示如何找到从id 687的单个起始顶点开始到id为1343的结束顶点的最短路径,并通过使用storewithoutaggregate确保不重复路径来有效地完成

g.V(687).store('x').repeat(out().where(without('x')).aggregate('x')).until(hasId(1343)).limit(1).path()

我想以相同的效率水平执行相同的查询,但是我需要从具有相同标签的多个起始顶点到相同的结束顶点的所有最短路径,例如它看起来像这样(尽管这不是'工作)

g.V().hasLabel('label').store('x').repeat(out().where(without('x')).aggregate('x')).until(hasId(1343)).limit(1).path()

我在语句中尝试了多个带有两个重复的构造,但是无法为每个起始顶点获得独立的store('x')。我也在使用AWS Neptune平台,因此它限制了Gremlin的使用,其中不允许循环/脚本。所有gremlin查询必须以g.开头,并由与.链接在一起的命令组成

https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html

gremlin tinkerpop tinkerpop3 amazon-neptune
1个回答
1
投票

此技术不能应用于多个起始顶点。但是,您可以从另一侧开始,因为这是一个已知的顶点:

g.V(1343).store('x').
  repeat(__.in().where(without('x')).aggregate('x')).
    until(hasLabel('label')).
  path()

如果其中一个起始顶点可以是另一个起始顶点的路径的一部分,那么您可能不会在潜在的起始顶点处中断,而是执行此操作:

g.V(1343).store('x').
  repeat(__.in().where(without('x')).aggregate('x')).
    emit(hasLabel('label')).
  path()
© www.soinside.com 2019 - 2024. All rights reserved.