Skip to content

Commit 43cb2d9

Browse files
committed
Standardizing pgr_DAGshortestPath to one path result columns
Its an experimental function - New SQL internal function - _pgr_dagShortestPath_v4 - Old SQL removed and C code moved to legacy - _pgr_dagShortestPath - Tests for 4.0.0+ - Added to migration section for one path result columns - Documentation adjusted to standardization - Example queries for documentation upgraded - Update script adjusted
1 parent b0821fe commit 43cb2d9

File tree

17 files changed

+270
-333
lines changed

17 files changed

+270
-333
lines changed

doc/dagShortestPath/pgr_dagShortestPath.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ In particular, the DAG shortest paths algorithm implemented by Boost.Graph.
2727

2828
.. rubric:: Availability
2929

30-
* Version 3.2.0
30+
.. rubric:: Version 4.0.0
3131

32-
* New experimental function.
32+
* Output columns standardized to |short-generic-result|
3333

34-
* pgr_dagShortestPath(Combinations)
34+
.. rubric:: Version 3.2.0
3535

36-
* Version 3.0.0
36+
* New experimental function.
3737

38-
* New experimental function.
38+
* pgr_dagShortestPath(Combinations)
39+
40+
..rubric:: Version 3.0.0
41+
42+
* New experimental function.
3943

4044

4145
Description
@@ -93,7 +97,7 @@ Signatures
9397
| pgr_dagShortestPath(`Edges SQL`_, **start vids**, **end vids**)
9498
| pgr_dagShortestPath(`Edges SQL`_, `Combinations SQL`_)
9599
96-
| Returns set of |result-1-1|
100+
| Returns set of |short-generic-result|
97101
| OR EMPTY SET
98102
99103

@@ -108,7 +112,7 @@ One to One
108112

109113
| pgr_dagShortestPath(`Edges SQL`_, **start vid**, **end vid**)
110114
111-
| Returns set of |result-1-1|
115+
| Returns set of |short-generic-result|
112116
| OR EMPTY SET
113117
114118
:Example: From vertex :math:`5` to vertex :math:`11` on a **directed** graph
@@ -128,7 +132,7 @@ One to Many
128132

129133
| pgr_dagShortestPath(`Edges SQL`_, **start vid**, **end vids**)
130134
131-
| Returns set of |result-1-1|
135+
| Returns set of |short-generic-result|
132136
| OR EMPTY SET
133137
134138
:Example: From vertex :math:`5` to vertices :math:`\{7, 11\}`
@@ -148,7 +152,7 @@ Many to One
148152

149153
| pgr_dagShortestPath(`Edges SQL`_, **start vids**, **end vid**)
150154
151-
| Returns set of |result-1-1|
155+
| Returns set of |short-generic-result|
152156
| OR EMPTY SET
153157
154158
:Example: From vertices :math:`\{5, 10\}` to vertex :math:`11`
@@ -168,7 +172,7 @@ Many to Many
168172

169173
| pgr_dagShortestPath(`Edges SQL`_, **start vids**, **end vids**)
170174
171-
| Returns set of |result-1-1|
175+
| Returns set of |short-generic-result|
172176
| OR EMPTY SET
173177
174178
:Example: From vertices :math:`\{5, 15\}` to vertices :math:`\{11, 17\}` on an
@@ -189,7 +193,7 @@ Combinations
189193

190194
| pgr_dagShortestPath(`Edges SQL`_, `Combinations SQL`_)
191195
192-
| Returns set of |result-1-1|
196+
| Returns set of |short-generic-result|
193197
| OR EMPTY SET
194198
195199
:Example: Using a combinations table on an **undirected** graph
@@ -234,8 +238,8 @@ Return columns
234238
-------------------------------------------------------------------------------
235239

236240
.. include:: pgRouting-concepts.rst
237-
:start-after: return_path_short_start
238-
:end-before: return_path_short_end
241+
:start-after: return_path_complete_start
242+
:end-before: return_path_complete_end
239243

240244
Additional Examples
241245
-------------------------------------------------------------------------------

doc/src/migration.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ types.
8181
- `Migration of single path functions`_
8282
* - .. versionchanged:: 4.0.0 :doc:`pgr_bellmanFord` [3]_
8383
- `Migration of single path functions`_
84+
* - .. versionchanged:: 4.0.0 :doc:`pgr_dagShortestPath` [3]_
85+
- `Migration of single path functions`_
8486
* - .. versionchanged:: 4.0.0 :doc:`pgr_edwardMoore` [3]_
8587
- `Migration of single path functions`_
8688
* - .. versionchanged:: 4.0.0 :doc:`pgr_withPoints` [2]_
@@ -313,6 +315,9 @@ application.
313315
* - ``pgr_bellmanFord``
314316
- v < 4.0
315317
- |old-generic-result|
318+
* - ``pgr_dagShortestPath``
319+
- v < 4.0
320+
- |result-1-1|
316321
* - ``pgr_edwardMoore``
317322
- v < 4.0
318323
- |old-generic-result|
@@ -410,6 +415,24 @@ Before updating pgRouting enumerate the columns: |result-1-1|
410415
:start-after: --bdDijkstra-1-to-1-filter
411416
:end-before: --bdDijkstra-1-to-m
412417

418+
.. rubric:: Using ``pgr_DAGshortestPath``
419+
420+
Migrating `this v3.8
421+
<https://docs.pgrouting.org/3.8/en/pgr_dagShortestPath.html#one-to-one>`__
422+
example.
423+
424+
.. literalinclude:: migration.queries
425+
:start-after: --DAGshortestPath-1-to-1
426+
:end-before: --DAGshortestPath-1-to-1-filter
427+
428+
Before updating pgRouting enumerate the columns: |result-1-1|
429+
430+
.. literalinclude:: migration.queries
431+
:start-after: --DAGshortestPath-1-to-1-filter
432+
:end-before: --DAGshortestPath-END
433+
434+
.. note:: This applies to all signatures of ``pgr_DAGshortestPath``
435+
413436
Examples for One to Many with one route result
414437
...............................................................................
415438

docqueries/dagShortestPath/dagShortestPath.result

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,62 @@ SET
66
SELECT * FROM pgr_dagShortestPath(
77
'SELECT id, source, target, cost FROM edges',
88
5, 11);
9-
seq | path_seq | node | edge | cost | agg_cost
10-
-----+----------+------+------+------+----------
11-
1 | 1 | 5 | 1 | 1 | 0
12-
2 | 2 | 6 | 4 | 1 | 1
13-
3 | 3 | 7 | 8 | 1 | 2
14-
4 | 4 | 11 | -1 | 0 | 3
9+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
10+
-----+----------+-----------+---------+------+------+------+----------
11+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
12+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
13+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
14+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
1515
(4 rows)
1616

1717
/* -- q3 */
1818
SELECT * FROM pgr_dagShortestPath(
1919
'SELECT id, source, target, cost FROM edges',
2020
5, ARRAY[7, 11]);
21-
seq | path_seq | node | edge | cost | agg_cost
22-
-----+----------+------+------+------+----------
23-
1 | 1 | 5 | 1 | 1 | 0
24-
2 | 2 | 6 | 4 | 1 | 1
25-
3 | 3 | 7 | -1 | 0 | 2
26-
4 | 1 | 5 | 1 | 1 | 0
27-
5 | 2 | 6 | 4 | 1 | 1
28-
6 | 3 | 7 | 8 | 1 | 2
29-
7 | 4 | 11 | -1 | 0 | 3
21+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
22+
-----+----------+-----------+---------+------+------+------+----------
23+
1 | 1 | 5 | 7 | 5 | 1 | 1 | 0
24+
2 | 2 | 5 | 7 | 6 | 4 | 1 | 1
25+
3 | 3 | 5 | 7 | 7 | -1 | 0 | 2
26+
4 | 1 | 5 | 11 | 5 | 1 | 1 | 0
27+
5 | 2 | 5 | 11 | 6 | 4 | 1 | 1
28+
6 | 3 | 5 | 11 | 7 | 8 | 1 | 2
29+
7 | 4 | 5 | 11 | 11 | -1 | 0 | 3
3030
(7 rows)
3131

3232
/* -- q4 */
3333
SELECT * FROM pgr_dagShortestPath(
3434
'SELECT id, source, target, cost FROM edges',
3535
ARRAY[5, 10], 11);
36-
seq | path_seq | node | edge | cost | agg_cost
37-
-----+----------+------+------+------+----------
38-
1 | 1 | 5 | 1 | 1 | 0
39-
2 | 2 | 6 | 4 | 1 | 1
40-
3 | 3 | 7 | 8 | 1 | 2
41-
4 | 4 | 11 | -1 | 0 | 3
42-
5 | 1 | 10 | 5 | 1 | 0
43-
6 | 2 | 11 | -1 | 0 | 1
36+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
37+
-----+----------+-----------+---------+------+------+------+----------
38+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
39+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
40+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
41+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
42+
5 | 1 | 10 | 11 | 10 | 5 | 1 | 0
43+
6 | 2 | 10 | 11 | 11 | -1 | 0 | 1
4444
(6 rows)
4545

4646
/* -- q5 */
4747
SELECT * FROM pgr_dagShortestPath(
4848
'SELECT id, source, target, cost FROM edges',
4949
ARRAY[5, 15], ARRAY[11, 17]);
50-
seq | path_seq | node | edge | cost | agg_cost
51-
-----+----------+------+------+------+----------
52-
1 | 1 | 5 | 1 | 1 | 0
53-
2 | 2 | 6 | 4 | 1 | 1
54-
3 | 3 | 7 | 8 | 1 | 2
55-
4 | 4 | 11 | -1 | 0 | 3
56-
5 | 1 | 5 | 1 | 1 | 0
57-
6 | 2 | 6 | 4 | 1 | 1
58-
7 | 3 | 7 | 8 | 1 | 2
59-
8 | 4 | 11 | 9 | 1 | 3
60-
9 | 5 | 16 | 15 | 1 | 4
61-
10 | 6 | 17 | -1 | 0 | 5
62-
11 | 1 | 15 | 16 | 1 | 0
63-
12 | 2 | 16 | 15 | 1 | 1
64-
13 | 3 | 17 | -1 | 0 | 2
50+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
51+
-----+----------+-----------+---------+------+------+------+----------
52+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
53+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
54+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
55+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
56+
5 | 1 | 5 | 17 | 5 | 1 | 1 | 0
57+
6 | 2 | 5 | 17 | 6 | 4 | 1 | 1
58+
7 | 3 | 5 | 17 | 7 | 8 | 1 | 2
59+
8 | 4 | 5 | 17 | 11 | 9 | 1 | 3
60+
9 | 5 | 5 | 17 | 16 | 15 | 1 | 4
61+
10 | 6 | 5 | 17 | 17 | -1 | 0 | 5
62+
11 | 1 | 15 | 17 | 15 | 16 | 1 | 0
63+
12 | 2 | 15 | 17 | 16 | 15 | 1 | 1
64+
13 | 3 | 15 | 17 | 17 | -1 | 0 | 2
6565
(13 rows)
6666

6767
/* -- q51 */
@@ -79,58 +79,58 @@ SELECT source, target FROM combinations;
7979
SELECT * FROM pgr_dagShortestPath(
8080
'SELECT id, source, target, cost FROM edges',
8181
'SELECT source, target FROM combinations');
82-
seq | path_seq | node | edge | cost | agg_cost
83-
-----+----------+------+------+------+----------
84-
1 | 1 | 5 | 1 | 1 | 0
85-
2 | 2 | 6 | -1 | 0 | 1
82+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
83+
-----+----------+-----------+---------+------+------+------+----------
84+
1 | 1 | 5 | 6 | 5 | 1 | 1 | 0
85+
2 | 2 | 5 | 6 | 6 | -1 | 0 | 1
8686
(2 rows)
8787

8888
/* -- q6 */
8989
SELECT * FROM pgr_dagShortestPath(
9090
'SELECT id, source, target, cost FROM edges',
9191
ARRAY[5, 10, 5, 10, 10, 5], ARRAY[11, 17, 17, 11]);
92-
seq | path_seq | node | edge | cost | agg_cost
93-
-----+----------+------+------+------+----------
94-
1 | 1 | 5 | 1 | 1 | 0
95-
2 | 2 | 6 | 4 | 1 | 1
96-
3 | 3 | 7 | 8 | 1 | 2
97-
4 | 4 | 11 | -1 | 0 | 3
98-
5 | 1 | 5 | 1 | 1 | 0
99-
6 | 2 | 6 | 4 | 1 | 1
100-
7 | 3 | 7 | 8 | 1 | 2
101-
8 | 4 | 11 | 9 | 1 | 3
102-
9 | 5 | 16 | 15 | 1 | 4
103-
10 | 6 | 17 | -1 | 0 | 5
104-
11 | 1 | 10 | 5 | 1 | 0
105-
12 | 2 | 11 | -1 | 0 | 1
106-
13 | 1 | 10 | 5 | 1 | 0
107-
14 | 2 | 11 | 9 | 1 | 1
108-
15 | 3 | 16 | 15 | 1 | 2
109-
16 | 4 | 17 | -1 | 0 | 3
92+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
93+
-----+----------+-----------+---------+------+------+------+----------
94+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
95+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
96+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
97+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
98+
5 | 1 | 5 | 17 | 5 | 1 | 1 | 0
99+
6 | 2 | 5 | 17 | 6 | 4 | 1 | 1
100+
7 | 3 | 5 | 17 | 7 | 8 | 1 | 2
101+
8 | 4 | 5 | 17 | 11 | 9 | 1 | 3
102+
9 | 5 | 5 | 17 | 16 | 15 | 1 | 4
103+
10 | 6 | 5 | 17 | 17 | -1 | 0 | 5
104+
11 | 1 | 10 | 11 | 10 | 5 | 1 | 0
105+
12 | 2 | 10 | 11 | 11 | -1 | 0 | 1
106+
13 | 1 | 10 | 17 | 10 | 5 | 1 | 0
107+
14 | 2 | 10 | 17 | 11 | 9 | 1 | 1
108+
15 | 3 | 10 | 17 | 16 | 15 | 1 | 2
109+
16 | 4 | 10 | 17 | 17 | -1 | 0 | 3
110110
(16 rows)
111111

112112
/* -- q7 */
113113
SELECT * FROM pgr_dagShortestPath(
114114
'SELECT id, source, target, cost FROM edges',
115115
ARRAY[5, 10, 11], ARRAY[5, 10, 11]);
116-
seq | path_seq | node | edge | cost | agg_cost
117-
-----+----------+------+------+------+----------
118-
1 | 1 | 5 | 1 | 1 | 0
119-
2 | 2 | 6 | 4 | 1 | 1
120-
3 | 3 | 7 | 8 | 1 | 2
121-
4 | 4 | 11 | -1 | 0 | 3
122-
5 | 1 | 10 | 5 | 1 | 0
123-
6 | 2 | 11 | -1 | 0 | 1
116+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
117+
-----+----------+-----------+---------+------+------+------+----------
118+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
119+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
120+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
121+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
122+
5 | 1 | 10 | 11 | 10 | 5 | 1 | 0
123+
6 | 2 | 10 | 11 | 11 | -1 | 0 | 1
124124
(6 rows)
125125

126126
/* -- q8 */
127127
SELECT * FROM pgr_dagShortestPath(
128128
'SELECT id, source, target, cost FROM edges',
129129
'SELECT * FROM (VALUES (6, 10), (6, 7), (12, 10)) AS combinations (source, target)');
130-
seq | path_seq | node | edge | cost | agg_cost
131-
-----+----------+------+------+------+----------
132-
1 | 1 | 6 | 4 | 1 | 0
133-
2 | 2 | 7 | -1 | 0 | 1
130+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
131+
-----+----------+-----------+---------+------+------+------+----------
132+
1 | 1 | 6 | 7 | 6 | 4 | 1 | 0
133+
2 | 2 | 6 | 7 | 7 | -1 | 0 | 1
134134
(2 rows)
135135

136136
/* -- q9 */

docqueries/src/migration.result

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,12 +1593,12 @@ FROM pgr_bdDijkstra(
15931593
SELECT * FROM pgr_DAGshortestPath(
15941594
'select id, source, target, cost from edges',
15951595
5, 11);
1596-
seq | path_seq | node | edge | cost | agg_cost
1597-
-----+----------+------+------+------+----------
1598-
1 | 1 | 5 | 1 | 1 | 0
1599-
2 | 2 | 6 | 4 | 1 | 1
1600-
3 | 3 | 7 | 8 | 1 | 2
1601-
4 | 4 | 11 | -1 | 0 | 3
1596+
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
1597+
-----+----------+-----------+---------+------+------+------+----------
1598+
1 | 1 | 5 | 11 | 5 | 1 | 1 | 0
1599+
2 | 2 | 5 | 11 | 6 | 4 | 1 | 1
1600+
3 | 3 | 5 | 11 | 7 | 8 | 1 | 2
1601+
4 | 4 | 5 | 11 | 11 | -1 | 0 | 3
16021602
(4 rows)
16031603

16041604
/* --DAGshortestPath-1-to-1-filter */

pgtap/others/dagShortestPath/edge_cases/empty_combinations_empty_result.pg

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
********************************************************************PGR-GNU*/
2020
BEGIN;
2121

22+
UPDATE edges SET cost = sign(cost), reverse_cost = -1 * sign(cost);
2223
SELECT plan(1);
2324

2425
CREATE OR REPLACE FUNCTION empty_combinations()
2526
RETURNS SETOF TEXT AS
2627
$BODY$
2728
BEGIN
2829

29-
IF NOT min_version('3.2.0') THEN
30-
RETURN QUERY
31-
SELECT skip(1, 'Combinations signature is new on 3.2.0');
30+
IF NOT min_version('4.0.0') THEN
31+
RETURN QUERY SELECT skip(1, 'pgr_DAGshortestPath return columns are standardized on v4.0.0');
3232
RETURN;
3333
END IF;
3434

35-
RETURN query SELECT is_empty(
36-
'SELECT seq, path_seq, node, edge, cost, agg_cost FROM pgr_dagShortestPath(
37-
''SELECT id, source, target, cost FROM edges'',
38-
''SELECT * FROM combinations WHERE source IN (-1)'' ) '
39-
);
40-
RETURN;
35+
RETURN query SELECT is_empty(
36+
$$
37+
SELECT seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost FROM pgr_dagShortestPath(
38+
'SELECT id, source, target, cost FROM edges',
39+
'SELECT * FROM combinations WHERE source IN (-1)')
40+
$$
41+
);
42+
4143
END
4244
$BODY$
4345
language plpgsql;

0 commit comments

Comments
 (0)