Skip to content

Commit 09df650

Browse files
authored
Merge pull request #39 from krashish8/pgr_depthFirstSearch
pgr_depthFirstSearch GSoC-2020 Week [1]
2 parents 0dbc5cf + 547c60f commit 09df650

File tree

10 files changed

+818
-32
lines changed

10 files changed

+818
-32
lines changed

configuration.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ chinese | Y | Y | Y
3737
spanningTree | Y | Y | Y
3838
mincut | Y | Y | Y
3939
version | Y | Y | Y
40-
topologicalSort | Y | Y | Y
40+
topologicalSort | Y | Y | Y
4141
transitiveClosure | Y | Y | Y
4242
breadthFirstSearch | Y | Y | Y
43-
depthFirstSearch | Y | Y | N
43+
depthFirstSearch | Y | Y | Y
4444
#----------------------
4545
# SQL only directories
4646
#----------------------

doc/depthFirstSearch/pgr_depthFirstSearch.rst

Lines changed: 185 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,71 @@
77
Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/
88
****************************************************************************
99

10-
pgr_depthFirstSearch
10+
pgr_depthFirstSearch - Experimental
1111
===============================================================================
1212

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.
1516

1617
.. figure:: images/boost-inside.jpeg
1718
:target: https://www.boost.org/libs/graph/doc/depth_first_search.html
1819

1920
Boost Graph Inside
2021

22+
.. include:: experimental.rst
23+
:start-after: begin-warn-expr
24+
:end-before: end-warn-exp
25+
2126
.. rubric:: Availability
2227

2328
Description
2429
-------------------------------------------------------------------------------
2530

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.
2836

2937
**The main Characteristics are:**
3038

31-
- Works on both Undirected and Directed Graphs.
39+
- The implementation works for both undirected and directed graphs.
3240
- 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.
3446
- Depth First Search Running time: :math:`O(E + V)`
3547

3648
Signatures
3749
-------------------------------------------------------------------------------
3850

51+
.. rubric:: Summary
52+
3953
.. code-block:: none
4054
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])
4357
4458
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
4575

4676
.. index::
4777
single: depthFirstSearch(Single vertex)
@@ -51,15 +81,17 @@ Single vertex
5181

5282
.. code-block:: none
5383
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)
5586
5687
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
88+
OR EMPTY SET
5789
58-
:Example: The Minimum Spanning Tree having as root vertex :math:`2`
90+
:Example: From start vertex :math:`2` on an **undirected** graph
5991

6092
.. literalinclude:: doc-pgr_depthFirstSearch.queries
61-
:start-after: --q1
62-
:end-before: --q2
93+
:start-after: -- q2
94+
:end-before: -- q3
6395

6496
.. index::
6597
single: depthFirstSearch(Multiple vertices)
@@ -69,20 +101,156 @@ Multiple vertices
69101

70102
.. code-block:: none
71103
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)
73106
74107
RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost)
108+
OR EMPTY SET
75109
76-
:Example:
110+
:Example: From start vertices :math:`\{11, 12\}` with :math:`depth <= 2`
111+
on a **directed** graph
77112

78113
.. literalinclude:: doc-pgr_depthFirstSearch.queries
79-
:start-after: --q2
80-
:end-before: --q3
114+
:start-after: -- q3
115+
:end-before: -- q4
81116

82117
.. Parameters, Inner query & result columns
83118
84119
.. depthFirstSearch-information-start
85120
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
86254

87255

88256
See Also

doc/src/pgRouting-introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Individuals (in alphabetical order)
4949
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050

5151
Aasheesh Tiwari, Aditya Pratap Singh, Adrien Berchet,
52+
Ashish Kumar,
5253
Cayetano Benavent,
5354
Gudesa Venkata Sai Akhil,
5455
Hang Wu,
@@ -79,6 +80,7 @@ Individuals (in alphabetical order)
7980
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8081

8182
Aasheesh Tiwari, Aditya Pratap Singh, Adrien Berchet, Akio Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Ashraf Hossain,
83+
Ashish Kumar,
8284
Cayetano Benavent, Christian Gonzalez,
8385
Daniel Kastl, Dave Potts, David Techer, Denis Rykov,
8486
Ema Miyawaki,

0 commit comments

Comments
 (0)