diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 4a023e06d42..5574b9d43da 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - psql: [13,14,15,16] + psql: [13,14,15,16,17] postgis: [3] os: [ubuntu-latest, ubuntu-22.04, ubuntu-20.04] diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 4c4e5be657d..eb3cfffa2c5 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -28,6 +28,7 @@ jobs: strategy: fail-fast: false matrix: + boost_minor: [56] old_pgr: [3.7.0, 3.6.3, 3.6.2, 3.6.1, 3.6.0, 3.5.1, 3.5.0, 3.4.2, 3.4.1, 3.4.0, 3.3.5, 3.3.4, 3.3.3, 3.3.2, 3.3.1, 3.3.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.6, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0, 3.2.1, 3.2.2] steps: @@ -63,7 +64,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ - libboost-graph-dev \ libtap-parser-sourcehandler-pgtap-perl \ postgresql-${PGVER} \ postgresql-${PGVER}-pgtap \ @@ -74,6 +74,10 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt + wget https://sourceforge.net/projects/boost/files/boost/1.${{ matrix.boost_minor }}.0/boost_1_${{ matrix.boost_minor }}_0.tar.bz2 + sudo tar --bzip2 -xf boost_1_${{ matrix.boost_minor }}_0.tar.bz2 + sudo mv boost_1_${{ matrix.boost_minor }}_0/boost /usr/include/ + - name: get old version uses: actions/checkout@v4 with: diff --git a/NEWS.md b/NEWS.md index c020bcb164b..e4c28d0bd37 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,19 @@ ## pgRouting 3.7 +### pgRouting 3.7.1 Release Notes + +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** + +* [#2680](https://github.com/pgRouting/pgrouting/pull/2680) fails to compile + under mingw64 gcc 13.2 +* [#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 To see all issues & pull requests closed by this release see the [Git closed diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 02b3689b50b..49119a8534e 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -60,6 +60,20 @@ pgRouting 3.7 :local: :depth: 1 +pgRouting 3.7.1 Release Notes +------------------------------------------------------------------------------- + +To see all issues & pull requests closed by this release see the `Git closed +milestone for 3.7.1 +`__ + +.. rubric:: Bug fixes + +* `#2680 `__ fails to compile + under mingw64 gcc 13.2 +* `#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 20f6f2cb048..dd0d7a0f539 100644 --- a/docqueries/trsp/test.conf +++ b/docqueries/trsp/test.conf @@ -12,7 +12,6 @@ trsp-any-02.pg issue693.pg issue704.pg - four_edges.pg )], }, ); diff --git a/include/cpp_common/Dmatrix.hpp b/include/cpp_common/Dmatrix.hpp index a4db572b276..4b22364094b 100644 --- a/include/cpp_common/Dmatrix.hpp +++ b/include/cpp_common/Dmatrix.hpp @@ -1,8 +1,6 @@ /*PGR-GNU***************************************************************** File: Dmatrix.hpp -FILE: Dmatrix.h - Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -34,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include typedef struct IID_t_rt IID_t_rt; diff --git a/pgtap/contraction/deadend/directed/big_ids.pg b/pgtap/contraction/deadend/directed/big_ids.pg deleted file mode 100644 index 1709f504443..00000000000 --- a/pgtap/contraction/deadend/directed/big_ids.pg +++ /dev/null @@ -1,138 +0,0 @@ - -/*PGR-GNU***************************************************************** - -Copyright (c) 2018 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; - -UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT plan(6); - -UPDATE edges -SET id = id + POWER(10, 8), - source = source + POWER(10, 8), - target = target + POWER(10, 8); - - --- input: 5 <-> 6, forbidden = 20 --- output: 2{1} ---Checking dead end contraction with invalid forbidden vertices -PREPARE q1 AS -SELECT * FROM pgr_contraction( - $$SELECT id, source, target, cost, reverse_cost FROM edges - WHERE id = 100000005$$, - ARRAY[1]::integer[], 1, ARRAY[20]::BIGINT[], true); - -SELECT set_eq('q1', - $$SELECT - 'v'::CHAR AS type, - 100000011::BIGINT AS id, - ARRAY[100000010]::BIGINT[] AS contracted_vertices, - -1::BIGINT AS source, - -1::BIGINT AS target, - -1::FLOAT AS cost$$); - --- Checking dead end contraction with no dead end node --- input: 10->6 6<->7, 7<->11, 10->11 --q1 --- output: -PREPARE q2 AS -SELECT * FROM pgr_contraction( - $$SELECT id, source, target, cost, reverse_cost FROM edges - WHERE id IN (100000002, 100000004, 100000005, 100000008)$$, - ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], true); - -SELECT is_empty('q2'); - --- input: 5 <-> 6 --- outputt: 6{5} ---Checking dead end contraction for single dead end node -PREPARE q3 AS -SELECT * FROM pgr_contraction( - $$SELECT id, source, target, cost, reverse_cost FROM edges - WHERE id = 100000001$$, - ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], true); - -SELECT set_eq('q3', - $$SELECT - 'v'::CHAR AS type, - 100000006::BIGINT AS id, - ARRAY[100000005]::BIGINT[] AS contracted_vertices, - -1::BIGINT AS source, - -1::BIGINT AS target, - -1::FLOAT AS cost$$); - --- Checking dead end contraction for two dead end nodes --- input: 6 <- 10 <- 15 --- output: 15{6, 10} -PREPARE q4 AS -SELECT * FROM pgr_contraction( - $$SELECT id, source, target, cost, reverse_cost FROM edges - WHERE id IN (100000002, 100000003)$$, - ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], true); - -SELECT set_eq('q4', - $$SELECT - 'v'::CHAR AS type, - 100000006::BIGINT AS id, - ARRAY[100000010,100000015]::BIGINT[] AS contracted_vertices, - -1::BIGINT AS source, - -1::BIGINT AS target, - -1::FLOAT AS cost$$); - ---Checking dead end contraction for multiple dead end nodes --- input: 5 <-> 6 <- 10 <- 15 --- output: 6{5, 10, 15} -PREPARE q5 AS -SELECT * 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 -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 ); - -SELECT set_eq('q5', 'sol5'); - --- all table --- 15{14} --- 16{17} --- 10{13} --- 5{7,8} --- 2{1} --- Checking dead end contraction for sample data -PREPARE q6 AS -SELECT * FROM pgr_contraction( - 'SELECT id, source, target, cost, reverse_cost FROM edges', - ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], true); - -PREPARE sol6 AS -SELECT type, id, contracted_vertices, source, target, cost -FROM (VALUES - ('v'::CHAR, 100000004::BIGINT, ARRAY[100000002]::BIGINT[], -1::BIGINT, -1::BIGINT, -1::FLOAT), - ('v', 100000007, ARRAY[100000001,100000003], -1, -1, -1), - ('v', 100000006, ARRAY[100000005], -1, -1, -1), - ('v', 100000008, ARRAY[100000009], -1, -1, -1), - ('v', 100000014, ARRAY[100000013], -1, -1, -1) -) AS t(type, id, contracted_vertices, source, target, cost ); - -SELECT set_eq('q6', 'sol6'); - -SELECT finish(); -ROLLBACK; 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"; diff --git a/tools/testers/contraction_tapfuncs.sql b/tools/testers/contraction_tapfuncs.sql index d66c6e490b9..59194493b4d 100644 --- a/tools/testers/contraction_tapfuncs.sql +++ b/tools/testers/contraction_tapfuncs.sql @@ -24,6 +24,7 @@ vids BIGINT[] = ARRAY[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]; x BIGINT; q TEXT; mainq TEXT; +otherq TEXT; expected TEXT; BEGIN UPDATE edges @@ -66,48 +67,55 @@ BEGIN -1::BIGINT AS target, -1::FLOAT AS cost$$); - q = format(mainq, ARRAY[vids[1], vids[2]], directed); + otherq = $d$ SELECT type, id, unnest(contracted_vertices) FROM pgr_contraction( + $$SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = ANY('%1$s'::BIGINT[]) $$, + ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], '%2$s'::BOOLEAN)$d$; - RETURN QUERY - SELECT set_eq(q, - $$SELECT - 'v'::CHAR AS type, - $$ || vids[10] || $$::BIGINT AS id, - ARRAY[ $$ || vids[5] || $$,$$ || vids[6] || $$]::BIGINT[] AS contracted_vertices, - -1::BIGINT AS source, - -1::BIGINT AS target, - -1::FLOAT AS cost$$); + q = format(otherq, ARRAY[vids[1], vids[2]], directed); + + expected = format($d$ + SELECT type, id, unnest + FROM (VALUES + ('v'::TEXT, %1$s::BIGINT, %2$s::BIGINT), + ('v', %1$s, %3$s) + ) AS t(type, id, unnest)$d$, + vids[10], vids[5], vids[6]) ; + + RETURN QUERY SELECT set_eq(q, expected); - q = format(mainq, ARRAY[vids[1], vids[2], vids[3]], directed); + q = format(otherq, ARRAY[vids[1], vids[2], vids[3]], directed); expected = format($d$ - SELECT type, id, contracted_vertices, source, target, cost + SELECT type, id, unnest FROM (VALUES - ('v'::CHAR, %1$s::BIGINT, '%2$s'::BIGINT[], -1::BIGINT, -1::BIGINT, -1::FLOAT) - ) AS t(type, id, contracted_vertices, source, target, cost )$d$, - vids[6], ARRAY[vids[5], vids[10], vids[15]]) ; + ('v'::TEXT, %1$s::BIGINT, %2$s::BIGINT), + ('v', %1$s, %3$s), + ('v', %1$s, %4$s) + ) AS t(type, id, unnest)$d$, + vids[6], vids[5], vids[10], vids[15]) ; RETURN QUERY SELECT set_eq(q, expected); - q = format($d$ SELECT * FROM pgr_contraction( + q = format($d$ SELECT type, id, unnest(contracted_vertices) FROM pgr_contraction( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, ARRAY[1]::integer[], 1, ARRAY[]::BIGINT[], '%1$s'::BOOLEAN)$d$, directed); expected = format($d$ - SELECT type, id, contracted_vertices, source, target, cost + SELECT type, id, unnest FROM (VALUES - ('v'::CHAR, %1$s::BIGINT, '%2$s'::BIGINT[], -1::BIGINT, -1::BIGINT, -1::FLOAT), - ('v', %3$s, '%4$s'::BIGINT[], -1, -1, -1), - ('v', %5$s, '%6$s'::BIGINT[], -1, -1, -1), - ('v', %7$s, '%8$s'::BIGINT[], -1, -1, -1), - ('v', %9$s, '%10$s'::BIGINT[], -1, -1, -1) - ) AS t(type, id, contracted_vertices, source, target, cost )$d$, - vids[4], ARRAY[vids[2]], - vids[6], ARRAY[vids[5]], - vids[7], ARRAY[vids[1], vids[3]], - vids[8], ARRAY[vids[9]], - vids[14], ARRAY[vids[13]]); + ('v'::CHAR, %1$s::BIGINT, %2$s), + ('v', %3$s, %4$s), + ('v', %5$s, %6$s), + ('v', %5$s, %7$s), + ('v', %8$s, %9$s), + ('v', %10$s, %11$s) + ) AS t(type, id, unnest)$d$, + vids[4], vids[2], + vids[6], vids[5], + vids[7], vids[1], vids[3], + vids[8], vids[9], + vids[14], vids[13]); RETURN QUERY SELECT set_eq(q, expected);