We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The function pgr_depthFirstSearch is required in pgRouting. Here are the function's signature and usage:
pgr_depthFirstSearch(): Provides the Depth First Search traversal order from a root vertex to a particular max depth.
All the pgRouting functions have a similar name pgr_camelCase, e.g. pgr_breadthFirstSearch. And therefore, I have chosen this name.
boost::depth_first_search
boost::undirected_dfs
pgr_depthFirstSearch(edges_sql, root_vid [, max_depth] [, directed]) RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost) OR EMPTY SET
pgr_depthFirstSearch(edges_sql, root_vids [, max_depth] [, directed]) RETURNS SET OF (seq, depth, start_vid, node, edge, cost, agg_cost) OR EMPTY SET
edges_sql: It should be an SQL query which should return a set of rows with the following columns:
Here, ANY-INTEGER = SMALLINT, INTEGER, BIGINT ANY-NUMERICAL = SMALLINT, INTEGER, BIGINT, REAL, FLOAT
Returns set of (seq, depth, start_vid, node, edge, cost, agg_cost)
Sample Graph:
SELECT * FROM sample_table ORDER BY id; id | source | target | cost | reverse_cost ----+--------+--------+------+-------------- 1 | 3 | 6 | 20 | 15 2 | 3 | 8 | 10 | -10 3 | 6 | 8 | -1 | 12 (3 rows)
Query 1 (Directed):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 3 ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 3 | 3 | -1 | 0 | 0 2 | 1 | 3 | 6 | 1 | 20 | 20 3 | 1 | 3 | 8 | 2 | 10 | 10 (3 rows)
Query 2 (Directed):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 6 ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 6 | 6 | -1 | 0 | 0 2 | 1 | 6 | 3 | 1 | 15 | 15 3 | 2 | 6 | 8 | 2 | 10 | 25 (3 rows)
Query 3 (Directed with max_depth):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 6, max_depth := 1 ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 6 | 6 | -1 | 0 | 0 2 | 1 | 6 | 3 | 1 | 15 | 15 (2 rows)
Query 4 (Vertex does not exist):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 2 ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 2 | 2 | -1 | 0 | 0 (1 rows)
Query 5 (Undirected):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 3, directed := false ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 3 | 3 | -1 | 0 | 0 2 | 1 | 3 | 6 | 1 | 20 | 20 3 | 2 | 3 | 8 | 3 | 12 | 32 (3 rows)
Query 6 (Undirected):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 6, directed := false ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 6 | 6 | -1 | 0 | 0 2 | 1 | 6 | 3 | 1 | 20 | 20 3 | 2 | 6 | 8 | 2 | 10 | 30 (3 rows)
Query 7 (Undirected with max_depth):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', 6, max_depth := 1, directed := false ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 6 | 6 | -1 | 0 | 0 2 | 1 | 6 | 3 | 1 | 20 | 20 3 | 1 | 6 | 8 | 3 | 12 | 12 (3 rows)
Query 8 (Multiple Vertices):
SELECT * FROM pgr_depthFirstSearch ( 'SELECT id, source, target, cost, reverse_cost FROM sample_table ORDER BY id', ARRAY[6, 3, 6] ); seq | depth | start_vid | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+---------- 1 | 0 | 3 | 3 | -1 | 0 | 0 2 | 1 | 3 | 6 | 1 | 20 | 20 3 | 1 | 3 | 8 | 2 | 10 | 10 4 | 0 | 6 | 6 | -1 | 0 | 0 5 | 1 | 6 | 3 | 1 | 15 | 15 6 | 2 | 6 | 8 | 2 | 10 | 25 (6 rows)
The text was updated successfully, but these errors were encountered:
pgr_depthFirstSearch
krashish8
Successfully merging a pull request may close this issue.
The function pgr_depthFirstSearch is required in pgRouting. Here are the function's signature and usage:
Name of the function:
pgr_depthFirstSearch(): Provides the Depth First Search traversal order from a root vertex to a particular max depth.
All the pgRouting functions have a similar name pgr_camelCase, e.g. pgr_breadthFirstSearch. And therefore, I have chosen this name.
Main Characteristics of the function:
boost::depth_first_search
) and undirected graphs (boost::undirected_dfs
).Variants:
Parameters:
Optional Parameters:
Inner Query
edges_sql: It should be an SQL query which should return a set of rows with the following columns:
Here,
ANY-INTEGER = SMALLINT, INTEGER, BIGINT
ANY-NUMERICAL = SMALLINT, INTEGER, BIGINT, REAL, FLOAT
Result Columns:
Returns set of (seq, depth, start_vid, node, edge, cost, agg_cost)
Usage
Sample Graph:
Query 1 (Directed):
Query 2 (Directed):
Query 3 (Directed with max_depth):
Query 4 (Vertex does not exist):
Query 5 (Undirected):
Query 6 (Undirected):
Query 7 (Undirected with max_depth):
Query 8 (Multiple Vertices):
References:
The text was updated successfully, but these errors were encountered: