@@ -3,24 +3,22 @@ title: k Paths in AQL
3
3
menuTitle : k Paths
4
4
weight : 30
5
5
description : >-
6
- Determine all paths between a start and end vertex limited specified path
7
- lengths
6
+ Find all paths between two vertices with a fixed range of path lengths
8
7
---
9
8
## General query idea
10
9
11
- This type of query finds all paths between two given documents,
12
- * startVertex* and * targetVertex* in your graph. The paths are restricted
13
- by minimum and maximum length of the paths .
10
+ This type of query finds all paths between two given documents
11
+ ( * startVertex* and * targetVertex* ) in your graph. The paths are restricted
12
+ by a minimum and maximum length that you specify .
14
13
15
- Every such path will be returned as a JSON object with two components:
14
+ Every such path is returned as a JSON object with two components:
16
15
17
16
- an array containing the ` vertices ` on the path
18
17
- an array containing the ` edges ` on the path
19
18
20
19
** Example**
21
20
22
- Let us take a look at a simple example to explain how it works.
23
- This is the graph that we are going to find some paths on:
21
+ Here is an example graph to explain how the k Paths algorithm works:
24
22
25
23
![ Train Connection Map] ( ../../../images/train_map.png )
26
24
@@ -30,9 +28,9 @@ between cities and are the edges of the graph. The numbers near the arrows
30
28
describe how long it takes to get from one station to another. They are used
31
29
as edge weights.
32
30
33
- Let us assume that we want to go from ** Aberdeen** to ** London** by train.
31
+ Assume that you want to go from ** Aberdeen** to ** London** by train.
34
32
35
- Here we have a couple of alternatives:
33
+ You have a couple of alternatives:
36
34
37
35
a) Straight way
38
36
@@ -72,8 +70,9 @@ d) Detour at Edinburgh to York
72
70
6 . York
73
71
7 . London
74
72
75
- Note that we only consider paths as valid that do not contain the same vertex
76
- twice. The following alternative would visit Aberdeen twice and will not be returned by k Paths:
73
+ Note that only paths that do not contain the same vertex twice are consider to
74
+ be valid. The following alternative would visit Aberdeen twice and is ** not**
75
+ returned by the k Paths algorithm:
77
76
78
77
1 . Aberdeen
79
78
2 . ** Inverness**
@@ -86,16 +85,16 @@ twice. The following alternative would visit Aberdeen twice and will not be retu
86
85
## Example Use Cases
87
86
88
87
The use-cases for k Paths are about the same as for unweighted k Shortest Paths.
89
- The main difference is that k Shortest Paths will enumerate all paths with
90
- ** increasing length** . It will stop as soon as a given limit is reached.
91
- k Paths will instead only enumerate ** all paths** within a given range of
92
- path length, and are thereby upper-bounded.
88
+ The main difference is that k Shortest Paths enumerates all paths with
89
+ ** increasing length** . It stops as soon as a given number of paths is reached.
90
+ k Paths enumerates all paths within a given ** range of path lengths ** instead,
91
+ and is thereby upper-bounded.
93
92
94
93
The k Paths traversal can be used as foundation for several other algorithms:
95
94
96
95
- ** Transportation** of any kind (e.g. road traffic, network package routing)
97
- - ** Flow problems** : We need to transfer items from A to B, which alternatives
98
- do we have? What is their capacity?
96
+ - ** Flow problems** : You need to transfer items from A to B, which alternatives
97
+ do you have? What is their capacity?
99
98
100
99
## Syntax
101
100
@@ -105,8 +104,8 @@ minimum and maximum length of the path.
105
104
106
105
{{< warning >}}
107
106
It is highly recommended that you use a reasonable maximum path length or a
108
- ** LIMIT** statement, as k Paths is a potentially expensive operation. On large
109
- connected graphs it can return a large number of paths.
107
+ ** LIMIT** statement, as k Paths is a potentially expensive operation. It can
108
+ return a large number of paths for large connected graphs .
110
109
{{< /warning >}}
111
110
112
111
### Working with named graphs
@@ -121,23 +120,23 @@ FOR path
121
120
- ` FOR ` : Emits the variable ** path** which contains one path as an object
122
121
containing ` vertices ` and ` edges ` of the path.
123
122
- ` IN ` ` MIN..MAX ` : The minimal and maximal depth for the traversal:
124
- - ** min** (number, * optional* ): Paths returned by this query will
125
- have at least a length of * min * many edges.
126
- If not specified, it defaults to 1 . The minimal possible value is 0 .
127
- - ** max** (number, * optional* ): Paths returned by this query will
128
- have at most a length of * max * many edges.
129
- If omitted, * max * defaults to * min* . Thus only the vertices and edges in
130
- the range of * min* are returned. * max * cannot be specified without * min* .
123
+ - ** min** (number, * optional* ): Paths returned by this query
124
+ have at least a length of this many edges.
125
+ If not specified, it defaults to ` 1 ` . The minimal possible value is ` 0 ` .
126
+ - ** max** (number, * optional* ): Paths returned by this query
127
+ have at most a length of this many edges.
128
+ If omitted, it defaults to the value of ` min ` . Thus, only the vertices and
129
+ edges in the range of ` min ` are returned. You cannot specify ` max ` without ` min ` .
131
130
- ` OUTBOUND|INBOUND|ANY ` : Defines in which direction
132
- edges are followed (outgoing, incoming, or both)
133
- - ` K_PATHS ` : The keyword to compute all Paths
131
+ edges are followed (outgoing, incoming, or both).
132
+ - ` K_PATHS ` : The keyword to compute all paths with the specified lengths.
134
133
- ** startVertex** ` TO ` ** targetVertex** (both string\| object): The two vertices
135
- between which the paths will be computed. This can be specified in the form of
136
- a document identifier string or in the form of an object with the attribute
137
- ` _id ` . All other values will lead to a warning and an empty result. This is
134
+ between which the paths are computed. This can be specified in the form of
135
+ a document identifier string or in the form of an object with the ` _id `
136
+ attribute . All other values lead to a warning and an empty result. This is
138
137
also the case if one of the specified documents does not exist.
139
138
- ` GRAPH ` ** graphName** (string): The name identifying the named graph.
140
- Its vertex and edge collections will be looked up.
139
+ Its vertex and edge collections are looked up for the path search .
141
140
142
141
### Working with collection sets
143
142
@@ -168,14 +167,14 @@ FOR vertex IN OUTBOUND K_PATHS
168
167
edges1, ANY edges2, edges3
169
168
```
170
169
171
- All collections in the list that do not specify their own direction will use the
170
+ All collections in the list that do not specify their own direction use the
172
171
direction defined after ` IN ` (here: ` OUTBOUND ` ). This allows to use a different
173
172
direction for each collection in your path search.
174
173
175
174
## Examples
176
175
177
- We load an example graph to get a named graph that reflects some possible
178
- train connections in Europe and North America.
176
+ You can load the ` kShortestPathsGraph ` example graph to get a named graph that
177
+ reflects some possible train connections in Europe and North America.
179
178
180
179
![ Train Connection Map] ( ../../../images/train_map.png )
181
180
@@ -192,7 +191,7 @@ db.places.toArray();
192
191
db .connections .toArray ();
193
192
```
194
193
195
- Suppose we want to query all routes from ** Aberdeen** to ** London** .
194
+ Suppose you want to query all routes from ** Aberdeen** to ** London** .
196
195
197
196
``` aql
198
197
---
@@ -205,7 +204,7 @@ GRAPH 'kShortestPathsGraph'
205
204
RETURN { places: p.vertices[*].label, travelTimes: p.edges[*].travelTime }
206
205
```
207
206
208
- If we ask for routes that don't exist we get an empty result
207
+ If you ask for routes that don't exist, you get an empty result
209
208
(from ** Aberdeen** to ** Toronto** ):
210
209
211
210
``` aql
0 commit comments