1
0
Fork 0

Doc - Dataset and example for Multiple Path Search (#5483)

This commit is contained in:
maxkernbach 2018-06-05 09:39:48 +02:00 committed by sleto-it
parent 861f4cef92
commit 9d622c566c
5 changed files with 74 additions and 19 deletions

View File

@ -10,32 +10,33 @@ then a shortest path query from **A** to **C** may return the path `A -> B -> C`
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
)
```
@startDocuBlockInline GRAPHTRAV_multiplePathSearch
@EXAMPLE_AQL{GRAPHTRAV_multiplePathSearch}
@DATASET{mps_graph}
RETURN LENGTH(
FOR v IN OUTBOUND
SHORTEST_PATH "verts/A" TO "verts/C" edges
RETURN v
)
@END_EXAMPLE_AQL
@endDocuBlock GRAPHTRAV_multiplePathSearch
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 traversal 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 point **C**.
The following query returns all parts with length 2, start vertex **A** and target vertex **C**:
```
FOR v, e, p IN 2..2 OUTBOUND "verts/A" edges
FILTER v._id == "verts/C"
RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)
```
Output:
@startDocuBlockInline GRAPHTRAV_multiplePathSearch2
@EXAMPLE_AQL{GRAPHTRAV_multiplePathSearch2}
@DATASET{mps_graph}
FOR v, e, p IN 2..2 OUTBOUND "verts/A" edges
FILTER v._id == "verts/C"
RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)
@END_EXAMPLE_AQL
@endDocuBlock GRAPHTRAV_multiplePathSearch2
```
[
"A -> B -> C",
"A -> D -> C"
]
```
A traversal depth of `3..3` would return `A -> E -> F -> C` and `2..3` all three paths.

View File

@ -0,0 +1,11 @@
@Q:
RETURN LENGTH(
FOR v IN OUTBOUND
SHORTEST_PATH <span class="hljs-string">"verts/A"</span> TO <span class="hljs-string">"verts/C"</span> edges
RETURN v
)
@R
[
<span class="hljs-number">3</span>
]

View File

@ -0,0 +1,10 @@
@Q:
FOR v, e, p IN <span class="hljs-number">2.</span><span class="hljs-number">.2</span> OUTBOUND <span class="hljs-string">"verts/A"</span> edges
FILTER v._id == <span class="hljs-string">"verts/C"</span>
RETURN CONCAT_SEPARATOR(<span class="hljs-string">" -&gt; "</span>, p.vertices[*]._key)
@R
[
<span class="hljs-string">"A -&gt; B -&gt; C"</span>,
<span class="hljs-string">"A -&gt; D -&gt; C"</span>
]

View File

@ -37,6 +37,14 @@ exports.Examples = {
examples.dropGraph("traversalGraph");
}
},
'mps_graph': {
createDS: function() {
examples.loadGraph("mps_graph");
},
removeDS: function() {
examples.dropGraph("mps_graph");
}
},
'joinSampleDataset': {
createDS: function() {
db._create("users");

View File

@ -52,6 +52,28 @@ var createTraversalExample = function () {
return g;
};
// we create a graph with 'edges' pointing from 'verts' to 'verts'
var createMpsTraversal = function () {
var g = Graph._create('mps_graph',
[Graph._relation('edges', 'verts', 'verts')]
);
var a = g.verts.save({_key: 'A'});
var b = g.verts.save({_key: 'B'});
var c = g.verts.save({_key: 'C'});
var d = g.verts.save({_key: 'D'});
var e = g.verts.save({_key: 'E'});
var f = g.verts.save({_key: 'F'});
g.edges.save(a._id, b._id, {vertex:a._key});
g.edges.save(a._id, e._id, {vertex:a._key});
g.edges.save(a._id, d._id, {vertex:a._key});
g.edges.save(b._id, c._id, {vertex:b._key});
g.edges.save(d._id, c._id, {vertex:d._key});
g.edges.save(e._id, f._id, {vertex:e._key});
g.edges.save(f._id, c._id, {vertex:f._key});
return g;
};
// we create a graph with 'relation' pointing from 'female' to 'male' and 'male
var createSocialGraph = function () {
db._create("female");
@ -375,6 +397,9 @@ var knownGraphs = {
'knows_graph': {create: createTraversalExample, dependencies: [
'knows', 'persons'
]},
'mps_graph': {create: createMpsTraversal, dependencies: [
'edges', 'verts'
]},
'routeplanner': {create: createRoutePlannerGraph, dependencies: [
'frenchHighway', 'frenchCity', 'germanCity', 'germanHighway', 'internationalHighway'
]},