Skip to content

Commit

Permalink
Fix issue 1640 pgr_withPoints (#1641)
Browse files Browse the repository at this point in the history
* [withPoints] Added pgtap tests to compare with dijkstra

* [withPoints] Created pgTAP tests for issue1640

* [withPoints] Fixed the issue
  • Loading branch information
krashish8 committed Nov 18, 2020
1 parent 5e7f7b9 commit e275c49
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pgtap/withPoints/issue1640.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
\i setup.sql

SELECT plan(4);

PREPARE q1 AS
SELECT * FROM pgr_withPoints (
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
'SELECT pid, edge_id, fraction FROM pointsOfInterest WHERE pid IN (-1)',
1, -2
);

SELECT * FROM lives_ok('q1');
SELECT * FROM is_empty('q1');

PREPARE q2 AS
SELECT * FROM pgr_withPoints (
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
'SELECT pid, edge_id, fraction FROM pointsOfInterest WHERE pid IN (-1)',
1, 2
);

SELECT * FROM lives_ok('q2');
SELECT * FROM isnt_empty('q2');

SELECT finish();
98 changes: 98 additions & 0 deletions pgtap/withPoints/withPoints_oneToOne-compare-dijkstra.test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*PGR-GNU*****************************************************************
Copyright (c) 2020 pgRouting developers
Mail: [email protected]
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/

\i setup.sql

SELECT plan(1156);

SET extra_float_digits = -3;

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION withPointsCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
$BODY$
DECLARE
inner_sql TEXT;
points_sql TEXT;
dijkstra_sql TEXT;
withPoints_sql TEXT;
result_columns TEXT;
BEGIN
result_columns := 'seq, path_seq, node, edge, cost, agg_cost';
points_sql := 'SELECT pid, edge_id, fraction, side from pointsOfInterest WHERE pid IN (-1)';

FOR i IN 1.. cant LOOP
FOR j IN 1.. cant LOOP

-- DIRECTED WITH REVERSE COST
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', directed => true)';

withPoints_sql := 'SELECT ' || result_columns || ' FROM pgr_withPoints($$' || inner_sql || '$$, $$' || points_sql
|| '$$, ' || i || ', ' || j || ', directed => true)';
RETURN query SELECT set_eq(withPoints_sql, dijkstra_sql, withPoints_sql);

-- DIRECTED WITHOUT REVERSE COST
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', directed => true)';

withPoints_sql := 'SELECT ' || result_columns || ' FROM pgr_withPoints($$' || inner_sql || '$$, $$' || points_sql
|| '$$, ' || i || ', ' || j || ', directed => true)';
RETURN query SELECT set_eq(withPoints_sql, dijkstra_sql, withPoints_sql);


-- UNDIRECTED WITH REVERSE COST
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', directed => false)';

withPoints_sql := 'SELECT ' || result_columns || ' FROM pgr_withPoints($$' || inner_sql || '$$, $$' || points_sql
|| '$$, ' || i || ', ' || j || ', directed => false)';
RETURN query SELECT set_eq(withPoints_sql, dijkstra_sql, withPoints_sql);

-- UNDIRECTED WITHOUT REVERSE COST
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', directed => false)';

withPoints_sql := 'SELECT ' || result_columns || ' FROM pgr_withPoints($$' || inner_sql || '$$, $$' || points_sql
|| '$$, ' || i || ', ' || j || ', directed => false)';
RETURN query SELECT set_eq(withPoints_sql, dijkstra_sql, withPoints_sql);

END LOOP;
END LOOP;

RETURN;
END
$BODY$
language plpgsql;

SELECT * from withPointsCompareDijkstra();


SELECT * FROM finish();
ROLLBACK;

1 change: 0 additions & 1 deletion src/withPoints/withPoints_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ do_pgr_withPoints(
pgassert(!(*return_tuples));
pgassert((*return_count) == 0);
pgassert(edges || edges_of_points);
pgassert(points_p);
pgassert(start_pidsArr);
pgassert(end_pidsArr);

Expand Down

0 comments on commit e275c49

Please sign in to comment.