7
7
Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/
8
8
************************************************************************** **
9
9
10
- pgr_depthFirstSearch
10
+ pgr_depthFirstSearch - Experimental
11
11
===============================================================================
12
12
13
- ``pgr_depthFirstSearch `` — Returns the traversal order(s) using Depth
14
- First Search algorithm.
13
+ ``pgr_depthFirstSearch `` — Returns the traversal order(s) using Depth First
14
+ Search algorithm. In particular, the Depth First Search algorithm and the
15
+ Undirected DFS algorithm implemented by Boost.Graph.
15
16
16
17
.. figure :: images/boost-inside.jpeg
17
18
:target: https://www.boost.org/libs/graph/doc/depth_first_search.html
18
19
19
20
Boost Graph Inside
20
21
22
+ .. include :: experimental.rst
23
+ :start-after: begin-warn-expr
24
+ :end-before: end-warn-exp
25
+
21
26
.. rubric :: Availability
22
27
23
28
Description
24
29
-------------------------------------------------------------------------------
25
30
26
- Visits the nodes in Depth First Search ordering from a root vertex to
27
- a particular depth.
31
+ Depth First Search algorithm is a well known traversal algorithm which starts
32
+ from a start vertex (``start_vid ``) and visits all the nodes in a graph in the
33
+ depth-first search traversal order. An optional non-negative maximum depth
34
+ parameter (``max_depth ``) can be specified to get the results upto a particular
35
+ depth.
28
36
29
37
**The main Characteristics are: **
30
38
31
- - Works on both Undirected and Directed Graphs .
39
+ - The implementation works for both undirected and directed graphs .
32
40
- Provides the Depth First Search traversal order from a source node to
33
- a particular max depth level.
41
+ a particular maximum depth level.
42
+ - For optimization purposes, any duplicated values in the `start_vids ` are
43
+ ignored.
44
+ - The returned values are ordered in ascending order of `start_vid `.
45
+ - If the starting vertex does not exist, empty row is returned.
34
46
- Depth First Search Running time: :math: `O(E + V)`
35
47
36
48
Signatures
37
49
-------------------------------------------------------------------------------
38
50
51
+ .. rubric :: Summary
52
+
39
53
.. code-block :: none
40
54
41
- pgr_depthFirstSearch(Edges SQL, Root vid [, max_depth] [, directed])
42
- pgr_depthFirstSearch(Edges SQL, Root vids [, max_depth] [, directed])
55
+ pgr_depthFirstSearch(edges_sql, start_vid [, max_depth] [, directed])
56
+ pgr_depthFirstSearch(edges_sql, start_vids [, max_depth] [, directed])
43
57
44
58
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
59
+ OR EMPTY SET
60
+
61
+ .. rubric :: Using defaults
62
+
63
+ .. code-block :: none
64
+
65
+ pgr_depthFirstSearch(TEXT edges_sql, BIGINT start_vid)
66
+
67
+ RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
68
+ OR EMPTY SET
69
+
70
+ :Example: From start vertex :math: `2 ` on a **directed ** graph
71
+
72
+ .. literalinclude :: doc-pgr_depthFirstSearch.queries
73
+ :start-after: -- q1
74
+ :end-before: -- q2
45
75
46
76
.. index ::
47
77
single: depthFirstSearch(Single vertex)
@@ -51,15 +81,17 @@ Single vertex
51
81
52
82
.. code-block :: none
53
83
54
- pgr_depthFirstSearch(Edges SQL, Root vid [, max_depth] [, directed])
84
+ pgr_depthFirstSearch(TEXT edges_sql, BIGINT start_vid,
85
+ BIGINT max_depth := 9223372036854775807, BOOLEAN directed := true)
55
86
56
87
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
88
+ OR EMPTY SET
57
89
58
- :Example: The Minimum Spanning Tree having as root vertex :math: `2 `
90
+ :Example: From start vertex :math: `2 ` on an ** undirected ** graph
59
91
60
92
.. literalinclude :: doc-pgr_depthFirstSearch.queries
61
- :start-after: --q1
62
- :end-before: --q2
93
+ :start-after: -- q2
94
+ :end-before: -- q3
63
95
64
96
.. index ::
65
97
single: depthFirstSearch(Multiple vertices)
@@ -69,20 +101,156 @@ Multiple vertices
69
101
70
102
.. code-block :: none
71
103
72
- pgr_depthFirstSearch(Edges SQL, Root vids [, max_depth] [, directed])
104
+ pgr_depthFirstSearch(TEXT edges_sql, ARRAY[ANY_INTEGER] start_vids,
105
+ BIGINT max_depth := 9223372036854775807, BOOLEAN directed := true)
73
106
74
107
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
108
+ OR EMPTY SET
75
109
76
- :Example:
110
+ :Example: From start vertices :math: `\{ 11 , 12 \}` with :math: `depth <= 2 `
111
+ on a **directed ** graph
77
112
78
113
.. literalinclude :: doc-pgr_depthFirstSearch.queries
79
- :start-after: --q2
80
- :end-before: --q3
114
+ :start-after: -- q3
115
+ :end-before: -- q4
81
116
82
117
.. Parameters, Inner query & result columns
83
118
84
119
.. depthFirstSearch-information-start
85
120
121
+ Parameters
122
+ -------------------------------------------------------------------------------
123
+
124
+ =================== ====================== =================================================
125
+ Parameter Type Description
126
+ =================== ====================== =================================================
127
+ **edges_sql ** ``TEXT `` SQL query described in `Inner query `_.
128
+ **start_vid ** ``BIGINT `` Identifier of the start vertex of the tree.
129
+
130
+ - Used on `Single Vertex`_.
131
+
132
+ **start_vids ** ``ARRAY[ANY-INTEGER] `` Array of identifiers of the start vertices.
133
+
134
+ - Used on `Multiple Vertices `_.
135
+ - For optimization purposes, any duplicated value is ignored.
136
+ =================== ====================== =================================================
137
+
138
+ Optional Parameters
139
+ ...............................................................................
140
+
141
+ =================== =========== =========================== =================================================
142
+ Parameter Type Default Description
143
+ =================== =========== =========================== =================================================
144
+ **max_depth ** ``BIGINT `` :math: `9223372036854775807 ` Upper limit for depth of node in the tree
145
+
146
+ - When value is ``Negative `` then **throws error **
147
+
148
+ **directed ** ``BOOLEAN `` ``true `` - When ``true `` Graph is considered `Directed `
149
+ - When ``false `` the graph is considered as `Undirected `.
150
+ =================== =========== =========================== =================================================
151
+
152
+ Inner query
153
+ -------------------------------------------------------------------------------
154
+
155
+ .. rubric:: edges_sql
156
+
157
+ .. include:: pgRouting-concepts.rst
158
+ :start-after: basic_edges_sql_start
159
+ :end-before: basic_edges_sql_end
160
+
161
+ Result Columns
162
+ -------------------------------------------------------------------------------
163
+
164
+ .. result columns start
165
+
166
+ Returns SET OF ``(seq, depth, start_vid, node, edge, cost, agg_cost) ``
167
+
168
+ =============== =========== ====================================================
169
+ Column Type Description
170
+ =============== =========== ====================================================
171
+ **seq ** ``BIGINT `` Sequential value starting from :math: `1 `.
172
+ **depth ** ``BIGINT `` Depth of the ``node ``.
173
+
174
+ - :math: `0 ` when ``node `` = ``start_vid ``.
175
+
176
+ **start_vid ** ``BIGINT `` Identifier of the start vertex.
177
+
178
+ - In `Multiple Vertices `_ results are in ascending order.
179
+
180
+ **node ** ``BIGINT `` Identifier of ``node `` reached using ``edge ``.
181
+ **edge ** ``BIGINT `` Identifier of the ``edge `` used to arrive to ``node ``.
182
+
183
+ - :math: `-1 ` when ``node `` = ``start_vid ``.
184
+
185
+ **cost ** ``FLOAT `` Cost to traverse ``edge ``.
186
+ **agg_cost ** ``FLOAT `` Aggregate cost from ``start_vid `` to ``node ``.
187
+ =============== =========== ====================================================
188
+
189
+ .. result columns end
190
+
191
+
192
+ Additional Examples
193
+ -------------------------------------------------------------------------------
194
+
195
+ The examples of this section are based on the :doc: `sampledata ` network.
196
+
197
+ The examples include the traversal with starting vertices as 6, 8 and 15 in a
198
+ directed and undirected graph, for both single vertex and multiple vertices.
199
+
200
+ **Directed Graph **
201
+
202
+ :Examples: For queries marked as ``directed `` with ``cost `` and ``reverse_cost `` columns
203
+
204
+ The examples in this section use the following:
205
+
206
+ * :ref: `fig1 `
207
+
208
+ .. literalinclude:: doc-pgr_depthFirstSearch.queries
209
+ :start-after: -- q5
210
+ :end-before: -- q6
211
+
212
+ **Undirected Graph **
213
+
214
+ :Examples: For queries marked as ``undirected `` with ``cost `` and ``reverse_cost `` columns
215
+
216
+ The examples in this section use the following:
217
+
218
+ * :ref: `fig2 `
219
+
220
+ .. literalinclude:: doc-pgr_depthFirstSearch.queries
221
+ :start-after: -- q7
222
+ :end-before: -- q8
223
+
224
+ **Vertex Out Of Graph **
225
+
226
+ :Example: For queries in which starting vertex is not present in the graph
227
+
228
+ .. literalinclude:: doc-pgr_depthFirstSearch.queries
229
+ :start-after: -- q9
230
+ :end-before: -- q10
231
+
232
+ Equivalences between signatures
233
+ ...............................................................................
234
+
235
+ :Examples: For queries marked as ``directed `` with ``cost `` and ``reverse_cost `` columns
236
+
237
+ The examples in this section use the following:
238
+
239
+ * :ref: `fig1 `
240
+
241
+ .. literalinclude:: doc-pgr_depthFirstSearch.queries
242
+ :start-after: -- q11
243
+ :end-before: -- q12
244
+
245
+ :Examples: For queries marked as ``undirected `` with ``cost `` and ``reverse_cost `` columns
246
+
247
+ The examples in this section use the following:
248
+
249
+ * :ref: `fig2 `
250
+
251
+ .. literalinclude:: doc-pgr_depthFirstSearch.queries
252
+ :start-after: -- q13
253
+ :end-before: -- q14
86
254
87
255
88
256
See Also
0 commit comments