您可以用cyclicPath步骤来找到在图中遍历时访问以前访问的顶点的路径。这并不是说访问了起始顶点,它可能在搜索图的时候任何一个已经访问过的顶点。下面是一个环路的例子。下面的专门构造的查询:找到10个开始和结束顶点都是AUS且中转一次的路径。
You can use the cyclicPath step to find paths through the graph that revisit a vertex seen earlier in
the traversal. This does not necessarily mean revisiting the starting vertex, it can be any vertex
already seen while traversing a graph. An example of some cyclic paths is shown below. The rather
contrived query below finds ten routes that both start and end in Austin (AUS) with a stop along the
way.

 运行查询结果在这。

Here are the results from running the query.

 您也可以把cyclicPath作为repeat循环的终止条件。下面这个查询语句中沿着出边走,直到它回到了起始点。只选择结果中的前10条。

You can also use cyclicPath as a termination condition for a repeat loop. The query below keeps
following outbound route edges until it ends up back where it started. Once again, only the first ten
results are selected. 

 运行查询的结果在这。如您所见,这次生成了相同的结果,但是如果我们让它运行更长时间,不只是10个结果,那么它最终会找到更多的环路,因为它没有限定从起点出发只进行一跳。事实上,如查我们不限制结果的数量,这个查询最终会找到图中的每一条环路。这个查询会运行相当长的时候,笔者不推荐进行这样的尝试。

Here are the results from running the query. As you can see it generated the same results in this
instance but if we let it run for longer than just ten results it would ultimately find a lot more cyclic
paths as it is not restricted to just going out one hop from its starting point. Indeed, if we did not
restrict the number of results we wanted the query would ultimately find every cyclic route in the
graph. That query could run for quite a while so I would not recommend trying it!

 如果我们让前边的查询运行100次,您将看到环路不是回到起始点。让查询找到500个环路,下面的这两个结果就会生成。注意第二个环路是回到了Miami而不是回到出发点AUS 

If we let the previous query run a few hundred times you would start to see examples of where the
cycle is not back to the starting vertex. The two results below were generated by letting the query
find 500 cyclic paths. Note that in the second case the cycle is back to Miami (MIA) and not the
starting vertex (AUS).

 您也可以把not和cyclicPath组合使用,这样就可以避免查询返回的结果中出现环路。

You can also use cyclicPath combined with a not predicate to avoid returning cyclic results from a
query. 

 注意如果我们把查询重写成下面所示的这样,它们对于航线图产生的作用是相同的。

Note that for the air-routes graph this has the same effect as if we had written the query as shown
below. 

 在一些图中,它包含这样的顶点,从该顶点有一条边,立即回到同一个顶点。看下面的代码:创建一条标签是loop的边,它从ID是3的顶点出发再回到ID是3的同一个顶点。

Some graphs contain vertices that have an edge that loops immediately back to the same vertex.
Take a look at the code below that creates an edge with a label of loop from the vertex with an ID of
3 back to the same vertex.

 我们可以用cyclicPath步骤找到图中所有这样的边。

We can then use the cyclicPath step to find such loops in the graph.

 为了把边包括在结果中,您可以稍修改一下查询,写成下面这样。

To include the edge in the result, you just need to modify the query a little as shown below.

 

 

posted on 2022-04-20 17:28  bokeyuannicheng0000  阅读(21)  评论(0)    收藏  举报