我正在使用 ArangoDB 3.0,我想创建一个 AQL 查询来获取从 A 到 B 的最短路径,深度 = 3,过滤某些边缘属性。

查询的“ArangoDB 2.0”版本如下:

FOR e IN GRAPH_SHORTEST_PATH('CityGraph', 'city/rome', 'city/turin', 
  {  
    edgeExamples: [{filterProperty: 'FIRST'}, {filterProperty: 'SECOND' }]}  
  ) 

我阅读了有关 arangoDB 3.0 ( https://docs.arangodb.com/3.0/AQL/Graphs/ShortestPath.html ) 的文档,它说:

Conditional shortest path

The SHORTEST_PATH computation will only find an unconditioned shortest path. With this construct it is not possible to define a condition like: "Find the shortest path where all edges are of type X". If you want to do this, use a normal Traversal instead with the option {bfs: true} in combination with LIMIT 1.

那么,有人可以告诉我我可以执行哪种类型的 AQL 查询吗? 根据建议,我这样写:

FOR n, e IN 1..3 ANY 'city/rome' GRAPH 'CityGraph' OPTIONS {bfs: true} FILTER e.filterProperty IN ['FIRST', 'SECOND'] LIMIT 1 return {n, e}

但它只返回图深度的第一层,而不是深度n。

提前谢谢你。

最好的问候,

丹妮尔

请您参考如下方法:

使用 LIMIT 1,您指定将 AQL 的结果集限制为仅获取最短路径。

上述查询的翻译应如下所示:

FOR n, e, p IN 1..3 ANY 'city/rome' 
    GRAPH 'CityGraph' 
    OPTIONS {bfs: true} 
    FILTER p.edges[*].filterProperty ALL IN ['FIRST', 'SECOND'] 
    FILTER n._key == 'turin' 
    LIMIT 1 
  RETURN {n, e} 
  • 您过滤所有边以使其 filterProperty 为 FIRSTSECOND,如果通过的边没有这两者之一,则丢弃此路径。
  • 最短路径的结束节点是turin


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!