简体   繁体   中英

Multiple path search in arangoDB

Is there any posibility to find many variants of shortest paths in ArangoDB? I need to find many variants, like First Path - distance 2 Second Path distance 3 etc.

Is there OOB include algrorithm? I want to specify nodes which should be mandatory found in results of search.

Is there support of vector weights? I mean that weight is characterized by an array where weights go in order of priority.

Thanks in advance.

The shortest path algorithm can only determine one shortest path.
For example, if this is the full graph:

示例图

...then a shortest path query from A to C may return the path A -> B -> C or A -> D -> C , but it's undefined which one (not taking edge weights into account here).

You can use the efficient shortest path algorithm however, to determine the shortest path length:

RETURN LENGTH(
  FOR v IN OUTBOUND
    SHORTEST_PATH "verts/A" TO "verts/C" edges
    RETURN v
)

The result is 3 for the example graph (includes the start vertex). Now, subtract 1 to get the edge count / traversal depth. You can run a pattern matching traversals to find all paths with this length (or longer ones by increasing the min and max depth). Starting point is A again, and a filter on the document ID of v (or p.vertices[-1] ) ensures that we only retrieve paths that end at C :

FOR v, e, p IN 2..2 OUTBOUND "verts/A" edges
  FILTER v._id == "verts/C"
  RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)
[
  "A -> B -> C",
  "A -> D -> C"
]

A traversal depth of 3..3 would return A -> E -> F -> C , and 2..3 all three paths.

Note that two separate queries are required to compute the shortest path length and to do the pattern matching based on the shortest path length (minus 1), because min and max depth can't be expressions (they have to be known in advance, so either be number literals or bind parameters).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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