Skip to content

Commit 1593939

Browse files
committed
[dagShortestPaths] changed function's signature
1 parent 487e8da commit 1593939

6 files changed

Lines changed: 164 additions & 6 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
\i setup.sql
2+
3+
SELECT plan(1156);
4+
5+
SET client_min_messages TO ERROR;
6+
7+
UPDATE edge_table SET cost = cost + 0.001 * id * id, reverse_cost = reverse_cost + 0.001 * id * id;
8+
9+
CREATE or REPLACE FUNCTION dagshortestpath_compare_dijkstra(cant INTEGER default 17)
10+
RETURNS SETOF TEXT AS
11+
$BODY$
12+
DECLARE
13+
inner_sql TEXT;
14+
dijkstra_sql TEXT;
15+
dagshortestpath_sql TEXT;
16+
BEGIN
17+
18+
FOR i IN 1.. cant LOOP
19+
FOR j IN 1.. cant LOOP
20+
21+
-- DIRECTED
22+
inner_sql := 'SELECT id, source, target, cost, reverse_cost FROM edge_table';
23+
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
24+
|| ', true)';
25+
26+
dagshortestpath_sql := 'SELECT * FROM pgr_dagshortestpath($$' || inner_sql || '$$, ' || i || ', ' || j
27+
|| ', true)';
28+
RETURN query SELECT set_eq(dagshortestpath_sql, dijkstra_sql, dagshortestpath_sql);
29+
30+
31+
inner_sql := 'SELECT id, source, target, cost FROM edge_table';
32+
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
33+
|| ', true)';
34+
35+
dagshortestpath_sql := 'SELECT * FROM pgr_dagshortestpath($$' || inner_sql || '$$, ' || i || ', ' || j
36+
|| ', true)';
37+
RETURN query SELECT set_eq(dagshortestpath_sql, dijkstra_sql, dagshortestpath_sql);
38+
39+
40+
41+
-- UNDIRECTED
42+
inner_sql := 'SELECT id, source, target, cost, reverse_cost FROM edge_table';
43+
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
44+
|| ', false)';
45+
46+
dagshortestpath_sql := 'SELECT * FROM pgr_dagshortestpath($$' || inner_sql || '$$, ' || i || ', ' || j
47+
|| ', false)';
48+
RETURN query SELECT set_eq(dagshortestpath_sql, dijkstra_sql, dagshortestpath_sql);
49+
50+
51+
inner_sql := 'SELECT id, source, target, cost FROM edge_table';
52+
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
53+
|| ', false)';
54+
55+
dagshortestpath_sql := 'SELECT * FROM pgr_dagshortestpath($$' || inner_sql || '$$, ' || i || ', ' || j
56+
|| ', false)';
57+
RETURN query SELECT set_eq(dagshortestpath_sql, dijkstra_sql, dagshortestpath_sql);
58+
59+
60+
END LOOP;
61+
END LOOP;
62+
63+
RETURN;
64+
END
65+
$BODY$
66+
language plpgsql;
67+
68+
SELECT * from dagshortestpath_compare_dijkstra();
69+
70+
71+
SELECT * FROM finish();
72+
ROLLBACK;
73+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
\i setup.sql
2+
3+
SELECT plan(137);
4+
SET client_min_messages TO ERROR;
5+
6+
7+
SELECT has_function('pgr_dagshortestpath',
8+
ARRAY['text', 'bigint', 'bigint']);
9+
10+
SELECT function_returns('pgr_dagshortestpath',
11+
ARRAY['text', 'bigint', 'bigint'],
12+
'setof record');
13+
14+
SELECT style_dijkstra('pgr_dagshortestpath', ', 2, 3)');
15+
16+
17+
18+
19+
SELECT finish();
20+
ROLLBACK;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
SELECT plan(4);
3+
4+
SELECT has_function('pgr_dagshortestpath');
5+
6+
SELECT has_function('pgr_dagshortestpath', ARRAY[ 'text', 'bigint', 'bigint' ]);
7+
8+
SELECT function_returns('pgr_dagshortestpath', ARRAY[ 'text', 'bigint', 'bigint' ], 'setof record');
9+
10+
-- testing column names
11+
SELECT bag_has(
12+
$$SELECT proargnames from pg_proc where proname = 'pgr_dagshortestpath'$$,
13+
$$SELECT '{"","","","seq","path_seq","node","edge","cost","agg_cost"}'::TEXT[] $$
14+
);
15+

sql/dagShortestPath/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
SET(LOCAL_FILES
3+
_dagShortestPath.sql
34
dagShortestPath.sql
45
)
56

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*PGR-GNU*****************************************************************
2+
File: _dagShortestPath.sql
3+
4+
Generated with Template by:
5+
Copyright (c) 2016 pgRouting developers
6+
Mail: project@pgrouting.org
7+
8+
Function's developer:
9+
Copyright (c) 2018 Sourabh Garg
10+
Mail: sourabh.garg.mat@gmail.com
11+
12+
------
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program; if not, write to the Free Software
26+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27+
28+
********************************************************************PGR-GNU*/
29+
30+
CREATE OR REPLACE FUNCTION _pgr_dagShortestPath(
31+
TEXT,
32+
BIGINT,
33+
BIGINT,
34+
directed BOOLEAN DEFAULT true,
35+
only_cost BOOLEAN DEFAULT false,
36+
OUT seq INTEGER,
37+
OUT path_seq INTEGER,
38+
OUT node BIGINT,
39+
OUT edge BIGINT,
40+
OUT cost FLOAT,
41+
OUT agg_cost FLOAT)
42+
43+
RETURNS SETOF RECORD AS
44+
'$libdir/${PGROUTING_LIBRARY_NAME}', 'dagShortestPath'
45+
LANGUAGE c IMMUTABLE STRICT;
46+

sql/dagShortestPath/dagShortestPath.sql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ CREATE OR REPLACE FUNCTION pgr_dagShortestPath(
3131
TEXT,
3232
BIGINT,
3333
BIGINT,
34-
directed BOOLEAN DEFAULT true,
35-
only_cost BOOLEAN DEFAULT false,
36-
OUT seq INTEGER,
34+
35+
OUT seq INTEGER,
3736
OUT path_seq INTEGER,
3837
OUT node BIGINT,
3938
OUT edge BIGINT,
4039
OUT cost FLOAT,
4140
OUT agg_cost FLOAT)
4241

4342
RETURNS SETOF RECORD AS
44-
'$libdir/${PGROUTING_LIBRARY_NAME}', 'dagShortestPath'
45-
LANGUAGE c IMMUTABLE STRICT;
46-
43+
$BODY$
44+
SELECT a.seq, a.path_seq, a.node, a.edge, a.cost, a.agg_cost
45+
FROM _pgr_dagShortestPath(_pgr_get_statement($1), $2::BIGINT, $3::BIGINT, true, false ) AS a;
46+
$BODY$
47+
LANGUAGE sql VOLATILE
48+
COST 100
49+
ROWS 1000;

0 commit comments

Comments
 (0)