diff --git a/NEWS.md b/NEWS.md index 6430b5a88e9..72d0f622d78 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,7 +9,14 @@ ### pgRouting 3.7.1 Release Notes -No Changes Yet +To see all issues & pull requests closed by this release see the [Git closed +milestone for 3.7.1 +](https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.7.1%22) + +**Bug fixes** + +* [#2689](https://github.com/pgRouting/pgrouting/pull/2689) When point is a + vertex, the withPoints family do not return results. ### pgRouting 3.7.0 Release Notes diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 25348a5ef74..154fb2c4bf7 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -40,7 +40,14 @@ pgRouting 3.7 pgRouting 3.7.1 Release Notes ------------------------------------------------------------------------------- -No Changes Yet +To see all issues & pull requests closed by this release see the `Git closed +milestone for 3.7.1 +`__ + +.. rubric:: Bug fixes + +* `#2689 `__ When point is a + vertex, the withPoints family do not return results. pgRouting 3.7.0 Release Notes ------------------------------------------------------------------------------- diff --git a/docqueries/trsp/four_edges.pg b/docqueries/trsp/four_edges.pg deleted file mode 100644 index 34f647337ed..00000000000 --- a/docqueries/trsp/four_edges.pg +++ /dev/null @@ -1,148 +0,0 @@ --- CopyRight(c) pgRouting developers --- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ -SET extra_float_digits=-3; -CREATE TABLE four_edges ( - id BIGINT, - source BIGINT, - target BIGINT, - cost FLOAT, - reverse_cost FLOAT); - -INSERT INTO four_edges (id, source, target, cost, reverse_cost) VALUES -( 719 , 52163 , -56570 , 179.400001 , 179.400001), -( 717 , 52222 , 52163 , 977.000001 , 977.000001), -( 718 , 52220 , 52222 , 961.000001 , 961.000001), -( 716 , -21019 , 52220 , 992.000001 , 992.000001); - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM - (VALUES - (719, 52163, -56570, 179.400001, 179.400001), - (717, 52222, 52163, 977.000001, 977.000001), - (718, 52220, 52222, 961.000001, 961.000001), - (716, -21019, 52220, 992.000001, 992.000001) - ) AS t (id, source, target, cost, reverse_cost)$$, - 719, 0, - 718, 0, - true, true, NULL); - - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM - (VALUES - (719, 52163, -56570, 179.40000, 179.40000), - (717, 52222, 52163, 977.00000, 977.00000), - (718, 52220, 52222, 961.00000, 961.00000), - (716, -21019, 52220, 992.00000, 992.00000) - ) AS t (id, source, target, cost, reverse_cost)$$, - (SELECT source::int FROM four_edges WHERE id = 719), - (SELECT source::int FROM four_edges WHERE id = 718), - true, true, NULL); - - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0, - 718, 0, - true, true, NULL); - -SELECT * FROM pgr_dijkstra( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 52163, - 52220, - false); - -SELECT * FROM pgr_dijkstra( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - (SELECT source FROM four_edges WHERE id = 719), - (SELECT source FROM four_edges WHERE id = 718), - true); - -/* Comparing withPoints and trsp*/ - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0.5, - 718, 0, - true, true, NULL); - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$SELECT 719 AS edge_id, 0.5::float AS fraction$$, - -1, - /* selecting source because we have 0 */ - (SELECT source FROM four_edges WHERE id = 718), - true); - -/* TODO should give result more or less the same as above*/ -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0.5::float AS fraction) - UNION - (SELECT 718, 0)$$, - -1, -2, - true); - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0, - 718, 0.5, - true, true, NULL); - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$SELECT 718 AS edge_id, 0.5::float AS fraction$$, - /* selecting source because we have 0 */ - (SELECT source FROM four_edges WHERE id = 719), - -1, - true); - -/* TODO should give result more or less the same as above*/ -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0::float AS fraction) - UNION - (SELECT 718, 0.5)$$, - -1, -2, - true); - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0.5, - 718, 0.5, - true, true, NULL); - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0.5::float AS fraction) - UNION - (SELECT 718, 0.5)$$, - -1, -2, - true); - diff --git a/docqueries/trsp/four_edges.result b/docqueries/trsp/four_edges.result deleted file mode 100644 index c1404ab2db3..00000000000 --- a/docqueries/trsp/four_edges.result +++ /dev/null @@ -1,232 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -SET extra_float_digits=-3; -SET -CREATE TABLE four_edges ( - id BIGINT, - source BIGINT, - target BIGINT, - cost FLOAT, - reverse_cost FLOAT); -CREATE TABLE -INSERT INTO four_edges (id, source, target, cost, reverse_cost) VALUES -( 719 , 52163 , -56570 , 179.400001 , 179.400001), -( 717 , 52222 , 52163 , 977.000001 , 977.000001), -( 718 , 52220 , 52222 , 961.000001 , 961.000001), -( 716 , -21019 , 52220 , 992.000001 , 992.000001); -INSERT 0 4 -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM - (VALUES - (719, 52163, -56570, 179.400001, 179.400001), - (717, 52222, 52163, 977.000001, 977.000001), - (718, 52220, 52222, 961.000001, 961.000001), - (716, -21019, 52220, 992.000001, 992.000001) - ) AS t (id, source, target, cost, reverse_cost)$$, - 719, 0, - 718, 0, - true, true, NULL); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------------ - 0 | 52163 | 717 | 977.000001 - 1 | 52222 | 718 | 961.000001 - 2 | 52220 | -1 | 0 -(3 rows) - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM - (VALUES - (719, 52163, -56570, 179.40000, 179.40000), - (717, 52222, 52163, 977.00000, 977.00000), - (718, 52220, 52222, 961.00000, 961.00000), - (716, -21019, 52220, 992.00000, 992.00000) - ) AS t (id, source, target, cost, reverse_cost)$$, - (SELECT source::int FROM four_edges WHERE id = 719), - (SELECT source::int FROM four_edges WHERE id = 718), - true, true, NULL); -WARNING: pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------ - 0 | 52163 | 717 | 977 - 1 | 52222 | 718 | 961 - 2 | 52220 | -1 | 0 -(3 rows) - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0, - 718, 0, - true, true, NULL); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------------ - 0 | 52163 | 717 | 977.000001 - 1 | 52222 | 718 | 961.000001 - 2 | 52220 | -1 | 0 -(3 rows) - -SELECT * FROM pgr_dijkstra( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 52163, - 52220, - false); - seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost ------+----------+-----------+---------+-------+------+------------+------------- - 1 | 1 | 52163 | 52220 | 52163 | 717 | 977.000001 | 0 - 2 | 2 | 52163 | 52220 | 52222 | 718 | 961.000001 | 977.000001 - 3 | 3 | 52163 | 52220 | 52220 | -1 | 0 | 1938.000002 -(3 rows) - -SELECT * FROM pgr_dijkstra( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - (SELECT source FROM four_edges WHERE id = 719), - (SELECT source FROM four_edges WHERE id = 718), - true); - seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost ------+----------+-----------+---------+-------+------+------------+------------- - 1 | 1 | 52163 | 52220 | 52163 | 717 | 977.000001 | 0 - 2 | 2 | 52163 | 52220 | 52222 | 718 | 961.000001 | 977.000001 - 3 | 3 | 52163 | 52220 | 52220 | -1 | 0 | 1938.000002 -(3 rows) - -/* Comparing withPoints and trsp*/ -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0.5, - 718, 0, - true, true, NULL); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------------ - 0 | -1 | 719 | 89.7000005 - 1 | 52163 | 717 | 977.000001 - 2 | 52222 | 718 | 961.000001 - 3 | 52220 | -1 | 0 -(4 rows) - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$SELECT 719 AS edge_id, 0.5::float AS fraction$$, - -1, - /* selecting source because we have 0 */ - (SELECT source FROM four_edges WHERE id = 718), - true); - seq | path_seq | node | edge | cost | agg_cost ------+----------+-------+------+------------+-------------- - 1 | 1 | -1 | 719 | 89.7000005 | 0 - 2 | 2 | 52163 | 717 | 977.000001 | 89.7000005 - 3 | 3 | 52222 | 718 | 961.000001 | 1066.7000015 - 4 | 4 | 52220 | -1 | 0 | 2027.7000025 -(4 rows) - -/* TODO should give result more or less the same as above*/ -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0.5::float AS fraction) - UNION - (SELECT 718, 0)$$, - -1, -2, - true); - seq | path_seq | node | edge | cost | agg_cost ------+----------+------+------+------+---------- -(0 rows) - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0, - 718, 0.5, - true, true, NULL); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------------- - 0 | 52163 | 717 | 977.000001 - 1 | 52222 | 718 | 480.5000005 - 2 | -2 | -1 | 0 -(3 rows) - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$SELECT 718 AS edge_id, 0.5::float AS fraction$$, - /* selecting source because we have 0 */ - (SELECT source FROM four_edges WHERE id = 719), - -1, - true); - seq | path_seq | node | edge | cost | agg_cost ------+----------+-------+------+-------------+-------------- - 1 | 1 | 52163 | 717 | 977.000001 | 0 - 2 | 2 | 52222 | 718 | 480.5000005 | 977.000001 - 3 | 3 | -1 | -1 | 0 | 1457.5000015 -(3 rows) - -/* TODO should give result more or less the same as above*/ -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0::float AS fraction) - UNION - (SELECT 718, 0.5)$$, - -1, -2, - true); - seq | path_seq | node | edge | cost | agg_cost ------+----------+------+------+------+---------- -(0 rows) - -SELECT * FROM pgr_trsp( - $$SELECT - id::int, source::int, target::int, cost::float, reverse_cost::float - FROM four_edges$$, - 719, 0.5, - 718, 0.5, - true, true, NULL); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-------+-----+------------- - 0 | -1 | 719 | 89.7000005 - 1 | 52163 | 717 | 977.000001 - 2 | 52222 | 718 | 480.5000005 - 3 | -2 | -1 | 0 -(4 rows) - -SELECT * FROM pgr_withPoints( - $$SELECT - id, source, target, cost, reverse_cost - FROM four_edges$$, - $$(SELECT 719 AS edge_id, 0.5::float AS fraction) - UNION - (SELECT 718, 0.5)$$, - -1, -2, - true); - seq | path_seq | node | edge | cost | agg_cost ------+----------+-------+------+-------------+-------------- - 1 | 1 | -1 | 718 | 480.5000005 | 0 - 2 | 2 | 52222 | 717 | 977.000001 | 480.5000005 - 3 | 3 | 52163 | 719 | 89.7000005 | 1457.5000015 - 4 | 4 | -2 | -1 | 0 | 1547.200002 -(4 rows) - -ROLLBACK; -ROLLBACK diff --git a/docqueries/trsp/test.conf b/docqueries/trsp/test.conf index c8a12420d63..d3c981e3e64 100644 --- a/docqueries/trsp/test.conf +++ b/docqueries/trsp/test.conf @@ -14,7 +14,6 @@ issue693.pg issue704.pg issue717.pg - four_edges.pg )], }, ); diff --git a/pgtap/contraction/deadend/directed/big_ids.pg b/pgtap/contraction/deadend/directed/big_ids.pg index 1709f504443..ce3bb110b7b 100644 --- a/pgtap/contraction/deadend/directed/big_ids.pg +++ b/pgtap/contraction/deadend/directed/big_ids.pg @@ -97,16 +97,18 @@ SELECT set_eq('q4', -- input: 5 <-> 6 <- 10 <- 15 -- output: 6{5, 10, 15} PREPARE q5 AS -SELECT * FROM pgr_contraction( +SELECT type, id, unnest(contracted_vertices) FROM pgr_contraction( $$SELECT id, source, target, cost, reverse_cost FROM edges WHERE id IN (100000001, 100000002, 100000003)$$, ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], true); PREPARE sol5 AS -SELECT type, id, contracted_vertices, source, target, cost +SELECT type, id, unnest FROM (VALUES - ('v'::CHAR, 100000006::BIGINT, ARRAY[100000005, 100000010, 100000015]::BIGINT[], -1::BIGINT, -1::BIGINT, -1::FLOAT) -) AS t(type, id, contracted_vertices, source, target, cost ); + ('v'::CHAR, 100000006::BIGINT, 100000005), + ('v'::CHAR, 100000006::BIGINT, 100000015), + ('v'::CHAR, 100000006::BIGINT, 100000010) +) AS t(type, id, unnest); SELECT set_eq('q5', 'sol5'); diff --git a/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg b/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..9dcd0f7d6d2 --- /dev/null +++ b/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg @@ -0,0 +1,186 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT CASE WHEN min_version('3.6.0') THEN plan(38) ELSE plan(1) END; + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +CREATE OR REPLACE FUNCTION test_vertex_points() RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.6.0'); + RETURN; + END IF; + + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_KSP( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $1, $2, 3, true) WHERE edge < 0; + +-- its a straigh line and one extreme are reachable +RETURN QUERY SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +RETURN QUERY SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + -1, $1, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + -2, $1, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + $1, $2, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + $1, $2, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + $1, $2, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsKSP( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + $1, $2, 3, 'r', true) WHERE edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +SELECT test_vertex_points(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/trsp/trspVia_withPoints/edge_cases/point_in_vertex.pg b/pgtap/trsp/trspVia_withPoints/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..0a95f2d8822 --- /dev/null +++ b/pgtap/trsp/trspVia_withPoints/edge_cases/point_in_vertex.pg @@ -0,0 +1,192 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(38) ELSE plan(1) END; + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +CREATE OR REPLACE FUNCTION test_vertex_points() RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; + END IF; + + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_dijkstraVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +-- its a straigh line and one extreme are reachable +RETURN QUERY SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +RETURN QUERY SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-1, $1], true) WHERE node = $1 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-2, $1], true) WHERE node = $1 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT path, cost FROM restrictions$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +SELECT test_vertex_points(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPoints/edge_cases/point_in_vertex.pg b/pgtap/withPoints/withPoints/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..d5ac988e0b5 --- /dev/null +++ b/pgtap/withPoints/withPoints/edge_cases/point_in_vertex.pg @@ -0,0 +1,170 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT plan(38); + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_dijkstra( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $1, $2, true) WHERE edge < 0; + +-- its a straigh line and one extreme are reachable +SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + -1, $1, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + -2, $1, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + $1, $2, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + $1, $2, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + $1, $2, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPoints( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + $1, $2, true) WHERE edge < 0; + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsCost/edge_cases/point_in_vertex.pg b/pgtap/withPoints/withPointsCost/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..8a6a230d9cc --- /dev/null +++ b/pgtap/withPoints/withPointsCost/edge_cases/point_in_vertex.pg @@ -0,0 +1,170 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT plan(38); + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_dijkstraCost( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $1, $2, true); + +-- its a straigh line and one extreme are reachable +SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + -1, $1, true) ; + +SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + -2, $1, true) ; + +SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + $1, $2, true); + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + $1, $2, true); + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + $1, $2, true); + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCost( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + $1, $2, true); + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsCostMatrix/edge_cases/point_in_vertex.pg b/pgtap/withPoints/withPointsCostMatrix/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..a0dddf51fdf --- /dev/null +++ b/pgtap/withPoints/withPointsCostMatrix/edge_cases/point_in_vertex.pg @@ -0,0 +1,170 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT plan(38); + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_dijkstraCostMatrix( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + ARRAY[$1, $2], true) LIMIT 1; + +-- its a straigh line and one extreme are reachable +SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-1, $1], true) LIMIT 1; + +SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-2, $1], true) LIMIT 1; + +SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + ARRAY[$1, $2], true)LIMIT 1; + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + ARRAY[$1, $2], true) LIMIT 1; + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + ARRAY[$1, $2], true) LIMIT 1; + +SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsCostMatrix( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + ARRAY[$1, $2], true) LIMIT 1; + +SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsDD/edge_cases/point_in_vertex.pg b/pgtap/withPoints/withPointsDD/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..eab2cf5eee6 --- /dev/null +++ b/pgtap/withPoints/withPointsDD/edge_cases/point_in_vertex.pg @@ -0,0 +1,186 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT CASE WHEN min_version('3.6.0') THEN plan(38) ELSE plan(1) END; + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +CREATE OR REPLACE FUNCTION test_vertex_points() RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.6.0'); + RETURN; + END IF; + + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_drivingDistance( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $1, 5, true) WHERE node = $2; + +-- its a straigh line and one extreme are reachable +RETURN QUERY SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +RETURN QUERY SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + -1, 3200.0, 'r', true) WHERE node = $1; + +RETURN QUERY SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + -2, 3200.0, 'r', true) WHERE node = $1; + +RETURN QUERY SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + $1, 3200.0, 'r', true) WHERE node = $2; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + $1, 3200.0, 'r', true) WHERE node = $2; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + $1, 3200.0, 'r', true) WHERE node = $2; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsDD( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + $1, 3200.0, 'r', true) WHERE node = $2; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +SELECT test_vertex_points(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsVia/edge_cases/point_in_vertex.pg b/pgtap/withPoints/withPointsVia/edge_cases/point_in_vertex.pg new file mode 100644 index 00000000000..15db9d89847 --- /dev/null +++ b/pgtap/withPoints/withPointsVia/edge_cases/point_in_vertex.pg @@ -0,0 +1,186 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SET extra_float_digits=-3; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(38) ELSE plan(1) END; + +CREATE VIEW four_edges AS +SELECT * FROM edges WHERE id IN (1,4,10,14); + +CREATE OR REPLACE FUNCTION test_vertex_points() RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; + END IF; + + +PREPARE dijkstra1(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_dijkstraVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +-- its a straigh line and one extreme are reachable +RETURN QUERY SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); +RETURN QUERY SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); + + +/* Points + midpoint of edge 1 (-1 by default) +*/ +PREPARE expectedCost1(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-1, $1], true) WHERE node = $1 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost1(6)$$, ARRAY[0.5]::TEXT[], 'Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost1(7)$$, ARRAY[1.5]::TEXT[] , 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost1(8)$$, ARRAY[2.5]::TEXT[] , 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost1(9)$$, ARRAY[3.5]::TEXT[] , 'Cost from midpoint on 1 to 9'); + +/* Points + midpoint of edge 1 (-2 assigned) +*/ +PREPARE expectedCost2(BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$ SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$ SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction$$, + ARRAY[-2, $1], true) WHERE node = $1 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost2(6)$$, $$expectedCost1(6)$$, 'Cost from midpoint on 1 (-2 assigned) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost2(7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost2(8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost2(9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +/* UNION ALL data is not sorted + source point of edge 10 (-1 by default) + midpoint of edge 1 (-2 by default) +*/ +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION ALL SELECT 1, 0.5 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(UNION ALL) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* UNION data is sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 10 AS edge_id, 0::float AS fraction UNION SELECT 1, 0.5 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(UNION) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* VALUES data is not sorted + midpoint of edge 1 (-1 by default) + source point of edge 10 (-2 by default) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT * FROM (VALUES (1,0.5), (10, 0)) AS t (edge_id, fraction)$$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-1,6)$$, $$expectedCost1(6)$$, '(VALUES) Cost from midpoint on 1 (-1 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-1,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-2,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-2,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-2,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +/* Points + midpoint of edge 1 (-2 assigned) + source point of edge 10 (-1 assigned) +*/ +DEALLOCATE PREPARE expectedCost3; +PREPARE expectedCost3(BIGINT, BIGINT) AS +SELECT agg_cost::TEXT FROM pgr_withPointsVia( + $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, + $$SELECT 2 AS pid, 1 AS edge_id, 0.5::float AS fraction UNION SELECT 1, 10, 0 $$, + ARRAY[$1, $2], true) WHERE node = $2 and edge < 0; + +RETURN QUERY SELECT results_eq($$expectedCost3(-2,6)$$, $$expectedCost1(6)$$, '(ASSIGNED) Cost from midpoint on 1 (-2 default) to 6'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,7)$$, $$expectedCost1(7)$$, 'Cost from midpoint on 1 to 7'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,8)$$, $$expectedCost1(8)$$, 'Cost from midpoint on 1 to 8'); +RETURN QUERY SELECT results_eq($$expectedCost3(-2,9)$$, $$expectedCost1(9)$$, 'Cost from midpoint on 1 to 9'); + +RETURN QUERY SELECT CASE WHEN min_version('3.7.1') +THEN + collect_tap( + set_eq($$expectedCost3(-1,9)$$, $$dijkstra1(7,9)$$, 'Cost from target on 10 (-1 default, aka 7) to 9'), + set_eq($$expectedCost3(-1,8)$$, $$dijkstra1(7,8)$$, 'Cost from target on 10 to 8'), + set_eq($$expectedCost3(-1,7)$$, ARRAY[0]::TEXT[], 'Cost from target on 10 to 7') + ) +ELSE skip('Fix implemented on 3.7.1',3) +END; + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +SELECT test_vertex_points(); + +SELECT finish(); +ROLLBACK; diff --git a/src/common/basePath_SSEC.cpp b/src/common/basePath_SSEC.cpp index c2f62c6825c..23a7f84e29f 100644 --- a/src/common/basePath_SSEC.cpp +++ b/src/common/basePath_SSEC.cpp @@ -160,8 +160,6 @@ Path Path::getSubpath(unsigned int j) const { for (auto i = path.begin(); i != path.begin() + j; ++i) { result.push_back((*i)); } - pgassert(result.tot_cost() != 0); - pgassert(this->tot_cost() != 0); return result; } diff --git a/src/withPoints/withPoints.cpp b/src/withPoints/withPoints.cpp index 9123fed8de4..98a619caeb3 100644 --- a/src/withPoints/withPoints.cpp +++ b/src/withPoints/withPoints.cpp @@ -390,11 +390,15 @@ Pg_points_graph::create_new_edges() { } if (point.fraction == 0) { log << "Point's vertex_id = source" << edge.source << "\n"; - point.vertex_id = edge.source; + point.vertex_id = -point.pid; + Edge_t new_edge = {edge.id, edge.source, -point.pid, 0, 0}; + m_new_edges.push_back(new_edge); } if (point.fraction == 1) { log << "point's vertex_id = target" << edge.target << "\n"; - point.vertex_id = edge.target; + point.vertex_id = -point.pid; + Edge_t new_edge = {edge.id, edge.target, -point.pid, 0, 0}; + m_new_edges.push_back(new_edge); } if (point.fraction > 0 && point.fraction < 1) { log << "vertex_id of the point is " << -point.pid << "\n";