简体   繁体   English

Gremlin:从给定顶点查找所有下游(出)路径

[英]Gremlin: Find all downstream (out) paths from given Vertex

I have a directed graph with around 1000 vertices and 3000 edges that contains cycles.我有一个包含循环的大约 1000 个顶点和 3000 个边的有向图。

I am trying to find all downstream (out) paths from given Vertex.我试图从给定的顶点找到所有下游(出)路径。

When using following Gremlin query使用以下 Gremlin 查询时

g.V(45712).repeat(out().simplePath()).until(outE().count().is(0)).path()

For some paths it takes forever to get the result because of the cycles, although the simplePath step should prevent this.对于某些路径,由于循环,需要永远获得结果,尽管simplePath步骤应该防止这种情况。

I tried to optimize the query and not go over the same Vertex twice using aggregate step and without , but now some Vertices are being skipped.我试图优化查询,而不是使用aggregate步骤和without使用aggregate步骤两次遍历同一个顶点,但现在一些顶点被跳过。

g.V(45712).repeat(out().where(without('x'))
.aggregate(Scope.local,'x'))
.until(outE().count().is(0))
.path()

Thanks谢谢

If your data is highly connected, that can be an expensive query.如果您的数据高度连接,那可能是一个昂贵的查询。 Even with a small graph.即使有一个小图形。 I have seen people use constraints to try and restrict the total amount of searching.我见过人们使用约束来尝试限制搜索的总量。 These could include using times or loops to set a maximum search depth.这些可能包括使用timesloops来设置最大搜索深度。 Even with my air-routes data set, which is really quite a small graph, that query could yield a very large result set.即使使用我的航线数据集(实际上是一个很小的图),该查询也可能产生非常大的结果集。 It's not so much that your Gremlin is wrong.并不是说你的 Gremlin 错了。 It's more going to depend on how connected the vertices are.它更多地取决于顶点的连接方式。

Searching for all paths from a given start in general is likely to be expensive query.从给定的开始搜索所有路径通常可能是昂贵的查询。

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

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