diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index eb3cfffa2c5..9d4319ca0b1 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -94,16 +94,16 @@ jobs: cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Release -DWITH_DOC=OFF .. make -j 4 sudo make install - sudo service postgresql start - createdb -p "${PGPORT}" ___pgr___test___ - psql -p "${PGPORT}" -d ___pgr___test___ -c "CREATE EXTENSION pgrouting CASCADE;" - name: Test old version before update with current tests run: | sudo service postgresql start + createdb -p "${PGPORT}" ___pgr___test___ + psql -p "${PGPORT}" -d ___pgr___test___ -c "CREATE EXTENSION pgrouting CASCADE;" psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" DIR=$(git rev-parse --show-toplevel) bash "${DIR}/tools/testers/setup_db.sh" "${PGPORT}" ___pgr___test___ "${PG_RUNNER_USER}" "${{ matrix.old_pgr }}" + psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" pg_prove -Q -f --normalize --directives --recurse -U "${PG_RUNNER_USER}" -d ___pgr___test___ "pgtap" - name: Build current version @@ -118,8 +118,11 @@ jobs: - name: Test old version with currrent tests after installing current run: | sudo service postgresql start - psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" + dropdb -p "${PGPORT}" ___pgr___test___ + createdb -p "${PGPORT}" ___pgr___test___ DIR=$(git rev-parse --show-toplevel) + bash "${DIR}/tools/testers/setup_db.sh" "${PGPORT}" ___pgr___test___ "${PG_RUNNER_USER}" "${{ matrix.old_pgr }}" + psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" pg_prove -Q -f --normalize --directives --recurse -U "${PG_RUNNER_USER}" -d ___pgr___test___ "pgtap" - name: Test old version with current tests after update diff --git a/NEWS.md b/NEWS.md index e4c28d0bd37..51462924607 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,8 @@ * ``pgr_trspviaedges(text,integer[],double precision[],boolean,boolean,text)`` * ``pgr_trspviavertices(text,anyarray,boolean,boolean,text)`` +* ``pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text)`` +* ``pgr_trsp(text,integer,integer,boolean,boolean,text)`` @@ -34,6 +36,10 @@ milestone for 3.7.1 * [#2689](https://github.com/pgRouting/pgrouting/pull/2689) When point is a vertex, the withPoints family do not return results. +**C/C++ code enhancemet** + +* TRSP family + ### pgRouting 3.7.0 Release Notes To see all issues & pull requests closed by this release see the [Git closed diff --git a/configuration.conf b/configuration.conf index 1f63c989983..ba6a958167c 100644 --- a/configuration.conf +++ b/configuration.conf @@ -14,6 +14,7 @@ common | Y | Y | N # Has the command needed to link with prostgresl #---------------------- dijkstra | Y | Y | Y +legacy | Y | N | N allpairs | Y | Y | Y astar | Y | Y | Y driving_distance | Y | Y | Y diff --git a/doc/src/migration.rst b/doc/src/migration.rst index 7dc1d2c1d0b..11fad8ff74c 100644 --- a/doc/src/migration.rst +++ b/doc/src/migration.rst @@ -22,13 +22,7 @@ Results can be different because of the changes. All deprecated functions will be removed on next mayor version 4.0.0 .. contents:: Contents - -Migration of functions -******************************************************************************* - -.. contents:: Migrating functions - :local: - + :depth: 2 Migration of ``pgr_aStar`` ------------------------------------------------------------------------------- @@ -770,200 +764,40 @@ columns: :start-after: --withPointsKSP2 :end-before: --withPointsKSP3 -Migration of turn restrictions -******************************************************************************* - -.. contents:: Contents - :local: - -Migration of restrictions -------------------------------------------------------------------------------- - -Starting from `v3.4.0 `__ - -The structure of the restrictions have changed: - -Old restrictions structure -............................................................................... - -On the deprecated signatures: - -* Column ``rid`` is ignored -* ``via_path`` - - * Must be in reverse order. - * Is of type ``TEXT``. - * When more than one via edge must be separated with ``,``. - -* ``target_id`` - - * Is the last edge of the forbidden path. - * Is of type ``INTEGER``. - -* ``to_cost`` - - * Is of type ``FLOAT``. - -Creation of the old restrictions table - -.. literalinclude:: migration.queries - :start-after: --rest00 - :end-before: --rest01 - -Old restrictions fill up - -.. literalinclude:: migration.queries - :start-after: --rest01 - :end-before: --rest1 - -Old restrictions contents -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. literalinclude:: migration.queries - :start-after: --rest1 - :end-before: --rest2 - -The restriction with ``rid = 2`` is representing :math:`3 \rightarrow 5 -\rightarrow9` - -* :math:`3\rightarrow5` - - * is on column ``via_path`` in reverse order - * is of type ``TEXT`` - -* :math:`9` - - * is on column ``target_id`` - * is of type ``INTEGER`` - - -New restrictions structure -............................................................................... - -* Column ``id`` is ignored -* Column ``path`` - - * Is of type ``ARRAY[ANY-INTEGER]``. - * Contains all the edges involved on the restriction. - * The array has the ordered edges of the restriction. - -* Column ``cost`` - - * Is of type ``ANY-NUMERICAL`` - -.. include:: sampledata.rst - :start-after: the_restrictions_start - :end-before: the_restrictions_end - - -The restriction with ``rid = 2`` represents the path :math:`3 \rightarrow5 -\rightarrow9`. - -* By inspection the path is clear. - -Migration -............................................................................... - -To transform the old restrictions table to the new restrictions structure, - -* Create a new table with the new restrictions structure. - - * In this migration guide ``new_restrictions`` is been used. - -* For this migration pgRouting supplies an auxiliary function for reversal of an - array ``_pgr_array_reverse`` needed for the migration. - - * ``_pgr_array_reverse``: - - * Was created temporally for this migration - * Is not documented. - * Will be removed on the next mayor version 4.0.0 - -.. literalinclude:: migration.queries - :start-after: --rest3 - :end-before: --rest4 - -The migrated table contents: - -.. literalinclude:: migration.queries - :start-after: --rest4 - :end-before: --rest5 - Migration of ``pgr_trsp`` (Vertices) ------------------------------------------------------------------------------- -:doc:`pgr_trsp` signatures have changed and many issues have been fixed in the -new signatures. This section will show how to migrate from the old signatures to -the new replacement functions. This also affects the restrictions. - -Starting from `v3.4.0 `__ - -Signature to be migrated: +Signature: .. parsed-literal:: - pgr_trsp(Edges SQL, source, target, - directed boolean, has_rcost boolean + pgr_trsp(Edges SQL, source, target, directed boolean, has_rcost boolean [,restrict_sql text]); RETURNS SETOF (seq, id1, id2, cost) -* The integral type of the ``Edges SQL`` can only be ``INTEGER``. -* The floating point type of the ``Edges SQL`` can only be ``FLOAT``. -* ``directed`` flag is compulsory. - - * Does not have a default value. - -* Does not autodetect if ``reverse_cost`` column exist. - - * User must be careful to match the existence of the column with the value of - ``has_rcost`` parameter. +:Deprecated: `v3.4.0 `__ +:Removed: `v4.0.0 `__ -* The restrictions inner query is optional. -* The output column names are meaningless - -Migrate by using: +.. contents:: + :local: -* :doc:`pgr_dijkstra` when there are no restrictions, -* :doc:`pgr_trsp` (One to One) when there are restrictions. +.. rubric:: See also +- :doc:`pgr_dijkstra` +- :doc:`pgr_trsp` +- `Migration of restrictions`_ -Migrating ``pgr_trsp`` (Vertices) using ``pgr_dijkstra`` +Use ``pgr_dijkstra`` when there are no restrictions. ............................................................................... -The following query does not have restrictions. - -.. literalinclude:: migration.queries - :start-after: --verticesv1 - :end-before: --verticesv2 - -* A message about deprecation is shown - - * Deprecated functions will be removed on the next mayor version 4.0.0 - Use :doc:`pgr_dijkstra` instead. - .. literalinclude:: migration.queries :start-after: --verticesv2 :end-before: --verticesv3 -* The types casting has been removed. -* :doc:`pgr_dijkstra`: - - * Autodetects if ``reverse_cost`` column is in the edges - SQL. - * Accepts ``ANY-INTEGER`` on integral types - * Accepts ``ANY-NUMERICAL`` on floating point types - * ``directed`` flag has a default value of ``true``. - - * Use the same value that on the original query. - * In this example it is ``true`` which is the default value. - - * The flag has been omitted and the default is been used. - -When the need of using strictly the same (meaningless) names and types of the -function been migrated then: +To get the original column names: .. literalinclude:: migration.queries :start-after: --verticesv3 @@ -972,50 +806,16 @@ function been migrated then: * ``id1`` is the node * ``id2`` is the edge - -Migrating ``pgr_trsp`` (Vertices) using ``pgr_trsp`` +Use ``pgr_trsp`` when there are restrictions. ............................................................................... -The following query has restrictions. - -.. literalinclude:: migration.queries - :start-after: --verticesv4 - :end-before: --verticesv5 - -* A message about deprecation is shown - - * Deprecated functions will be removed on the next mayor version 4.0.0 - -* The restrictions are the last parameter of the function - - * Using the old structure of restrictions - Use :doc:`pgr_trsp` (One to One) instead. .. literalinclude:: migration.queries :start-after: --verticesv5 :end-before: --verticesv6 -* The new structure of restrictions is been used. - - * It is the second parameter. - -* The types casting has been removed. -* :doc:`pgr_trsp`: - - * Autodetects if ``reverse_cost`` column is in the edges - SQL. - * Accepts ``ANY-INTEGER`` on integral types - * Accepts ``ANY-NUMERICAL`` on floating point types - * ``directed`` flag has a default value of ``true``. - - * Use the same value that on the original query. - * In this example it is ``true`` which is the default value. - - * The flag has been omitted and the default is been used. - -When the need of using strictly the same (meaningless) names and types of the -function been migrated then: +To get the original column names: .. literalinclude:: migration.queries :start-after: --verticesv6 @@ -1027,7 +827,7 @@ function been migrated then: Migration of ``pgr_trsp`` (Edges) ------------------------------------------------------------------------------- -Signature to be migrated: +Signature: .. parsed-literal:: @@ -1037,67 +837,28 @@ Signature to be migrated: [,restrict_sql text]); RETURNS SETOF (seq, id1, id2, cost) -* The integral types of the ``sql`` can only be ``INTEGER``. -* The floating point type of the ``sql`` can only be ``FLOAT``. -* ``directed`` flag is compulsory. - - * Does not have a default value. - -* Does not autodetect if ``reverse_cost`` column exist. - - * User must be careful to match the existence of the column with the value of - ``has_rcost`` parameter. +:Deprecated: `v3.4.0 `__ +:Removed: `v4.0.0 `__ -* The restrictions inner query is optional. - -For these migration guide the following points will be used: - -.. literalinclude:: migration.queries - :start-after: --verticesv7 - :end-before: --edgesv1 +.. contents:: + :local: -Migrate by using: +.. rubric:: See also -* :doc:`pgr_withPoints` when there are no restrictions, -* :doc:`pgr_trsp_withPoints` (One to One) when there are restrictions. +- :doc:`pgr_withPoints` +- :doc:`pgr_trsp_withPoints` +- `Migration of restrictions`_ -Migrating ``pgr_trsp`` (Edges) using ``pgr_withPoints`` +Use ``pgr_withPoints`` when there are no restrictions. ............................................................................... -The following query does not have restrictions. - -.. literalinclude:: migration.queries - :start-after: --edgesv1 - :end-before: --edgesv2 - -* A message about deprecation is shown - - * Deprecated functions will be removed on the next mayor version 4.0.0 - -Use :doc:`pgr_withPoints` instead. +Use :doc:`pgr_withPoints` (Ont to One) instead. .. literalinclude:: migration.queries :start-after: --edgesv2 :end-before: --edgesv3 -* The types casting has been removed. -* Do not show details, as the deprecated function does not show details. -* :doc:`pgr_withPoints`: - - * Autodetects if ``reverse_cost`` column is in the edges - SQL. - * Accepts ``ANY-INTEGER`` on integral types - * Accepts ``ANY-NUMERICAL`` on floating point types - * ``directed`` flag has a default value of ``true``. - - * Use the same value that on the original query. - * In this example it is ``true`` which is the default value. - - * The flag has been omitted and the default is been used. - * On the points query do not include the ``side`` column. - -When the need of using strictly the same (meaningless) names and types, and node -values of the function been migrated then: +To get the original column names: .. literalinclude:: migration.queries :start-after: --edgesv3 @@ -1106,52 +867,16 @@ values of the function been migrated then: * ``id1`` is the node * ``id2`` is the edge - -Migrating ``pgr_trsp`` (Edges) using ``pgr_trsp_withPoints`` +Use ``pgr_trsp_withPoints`` when there are restrictions. ............................................................................... -The following query has restrictions. - -.. literalinclude:: migration.queries - :start-after: --edgesv4 - :end-before: --edgesv5 - -* A message about deprecation is shown - - * Deprecated functions will be removed on the next mayor version 4.0.0 - -* The restrictions are the last parameter of the function - - * Using the old structure of restrictions - Use :doc:`pgr_trsp_withPoints` instead. .. literalinclude:: migration.queries :start-after: --edgesv5 :end-before: --edgesv6 -* The new structure of restrictions is been used. - - * It is the second parameter. - -* The types casting has been removed. -* Do not show details, as the deprecated function does not show details. -* :doc:`pgr_trsp_withPoints`: - - * Autodetects if ``reverse_cost`` column is in the edges - SQL. - * Accepts ``ANY-INTEGER`` on integral types - * Accepts ``ANY-NUMERICAL`` on floating point types - * ``directed`` flag has a default value of ``true``. - - * Use the same value that on the original query. - * In this example it is ``true`` which is the default value. - - * The flag has been omitted and the default is been used. - * On the points query do not include the ``side`` column. - -When the need of using strictly the same (meaningless) names and types, and node -values of the function been migrated then: +To get the original column names: .. literalinclude:: migration.queries :start-after: --edgesv6 @@ -1160,88 +885,114 @@ values of the function been migrated then: * ``id1`` is the node * ``id2`` is the edge -Migration of pgr_trspViaVertices +Migration of ``pgr_trspViaVertices`` ------------------------------------------------------------------------------- +Signature: + +.. parsed-literal:: + + pgr_trspViaVertices(sql text, vids integer[], + directed boolean, has_rcost boolean + [, turn_restrict_sql text]); + RETURNS SETOF (seq, id1, id2, id3, cost) + +:Deprecated: `v3.4.0 `__ +:Removed: `v4.0.0 `__ + .. contents:: :local: :depth: 1 -Migrating pgr_trspViaVertices using pgr_dijkstraVia +.. rubric:: See also + +- :doc:`pgr_dijkstraVia` +- :doc:`pgr_trspVia` +- `Migration of restrictions`_ + +Use ``pgr_dijkstraVia`` when there are no restrictions ............................................................................... -Using :doc:`pgr_dijkstraVia`. +Use :doc:`pgr_dijkstraVia` instead. .. literalinclude:: migration.queries :start-after: --viav2 :end-before: --viav3 -When the need of using the same (meaningless) names and and strict types then -convert the result to the deprecated function columns: - -* ``id1`` is the path identifier -* ``id2`` is the node -* ``id3`` is the edge +To get the original column names: .. literalinclude:: migration.queries :start-after: --viav3 :end-before: --viav4 +* ``id1`` is the path identifier +* ``id2`` is the node +* ``id3`` is the edge -Migrating pgr_trspViaVertices using pgr_trspVia +Use ``pgr_trspVia`` when there are restrictions ............................................................................... -Using :doc:`pgr_trspVia`. +Use :doc:`pgr_trspVia` instead. .. literalinclude:: migration.queries :start-after: --viav5 :end-before: --viav6 -When the need of using the same (meaningless) names and and strict types then -convert the result to the deprecated function columns: - -* ``id1`` is the path identifier -* ``id2`` is the node -* ``id3`` is the edge +To get the original column names: .. literalinclude:: migration.queries :start-after: --viav6 :end-before: --viav7 -Migration of pgr_trspViaEdges +* ``id1`` is the path identifier +* ``id2`` is the node +* ``id3`` is the edge + +Migration of ``pgr_trspViaEdges`` ------------------------------------------------------------------------------- +Signature: + +.. parsed-literal:: + + pgr_trspViaEdges(sql text, eids integer[], pcts float8[], + directed boolean, has_rcost boolean + [, turn_restrict_sql text]); + RETURNS SETOF (seq, id1, id2, id3, cost) + +:Deprecated: `v3.4.0 `__ +:Removed: `v4.0.0 `__ + .. contents:: :local: :depth: 1 -In this section this set of points is going to be used: +.. rubric:: See also -.. literalinclude:: migration.queries - :start-after: --edgesvia1 - :end-before: --edgesvia2 +- :doc:`pgr_withPointsVia` +- :doc:`pgr_trspVia_withPoints` +- `Migration of restrictions`_ -Migrating pgr_trspViaEdges using pgr_withPointsVia +Use ``pgr_withPointsVia`` when there are no restrictions ............................................................................... -Using :doc:`pgr_withPointsVia`. +Use :doc:`pgr_withPointsVia` instead. .. literalinclude:: migration.queries :start-after: --edgesvia2 :end-before: --edgesvia3 -When the need of using the same (meaningless) names and and strict types then -convert the result to the deprecated function columns: - -* ``id1`` is the path identifier -* ``id2`` is the node -* ``id3`` is the edge +To get the original column names: .. literalinclude:: migration.queries :start-after: --edgesvia3 :end-before: --edgesvia4 -Migrating pgr_trspViaEdges using pgr_trspVia_withPoints +* ``id1`` is the path identifier +* ``id2`` is the node +* ``id3`` is the edge + +Use ``pgr_trspVia_withPoints`` when there are restrictions ............................................................................... Use :doc:`pgr_trspVia_withPoints` instead. @@ -1250,16 +1001,128 @@ Use :doc:`pgr_trspVia_withPoints` instead. :start-after: --edgesvia5 :end-before: --edgesvia6 -When the need of using the same (meaningless) names and and strict types then -convert the result to the deprecated function columns: +To get the original column names: + +.. literalinclude:: migration.queries + :start-after: --edgesvia6 + :end-before: --edgesvia7 * ``id1`` is the path identifier * ``id2`` is the node * ``id3`` is the edge +Migration of restrictions +------------------------------------------------------------------------------- + +Starting from `v3.4.0 `__ + +The structure of the restrictions have changed: + +Old restrictions structure +............................................................................... + +On the deprecated signatures: + +* Column ``rid`` is ignored +* ``via_path`` + + * Must be in reverse order. + * Is of type ``TEXT``. + * When more than one via edge must be separated with ``,``. + +* ``target_id`` + + * Is the last edge of the forbidden path. + * Is of type ``INTEGER``. + +* ``to_cost`` + + * Is of type ``FLOAT``. + +Creation of the old restrictions table + .. literalinclude:: migration.queries - :start-after: --edgesvia6 - :end-before: --edgesvia7 + :start-after: --rest00 + :end-before: --rest01 + +Old restrictions fill up + +.. literalinclude:: migration.queries + :start-after: --rest01 + :end-before: --rest1 + +Old restrictions contents ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. literalinclude:: migration.queries + :start-after: --rest1 + :end-before: --rest2 + +The restriction with ``rid = 2`` is representing :math:`3 \rightarrow 5 +\rightarrow9` + +* :math:`3\rightarrow5` + + * is on column ``via_path`` in reverse order + * is of type ``TEXT`` + +* :math:`9` + + * is on column ``target_id`` + * is of type ``INTEGER`` + + +New restrictions structure +............................................................................... + +* Column ``id`` is ignored +* Column ``path`` + + * Is of type ``ARRAY[ANY-INTEGER]``. + * Contains all the edges involved on the restriction. + * The array has the ordered edges of the restriction. + +* Column ``cost`` + + * Is of type ``ANY-NUMERICAL`` + +.. include:: sampledata.rst + :start-after: the_restrictions_start + :end-before: the_restrictions_end + + +The restriction with ``rid = 2`` represents the path :math:`3 \rightarrow5 +\rightarrow9`. + +* By inspection the path is clear. + +Migration +............................................................................... + +To transform the old restrictions table to the new restrictions structure, + +* Create a new table with the new restrictions structure. + + * In this migration guide ``new_restrictions`` is been used. + +* For this migration pgRouting supplies an auxiliary function for reversal of an + array ``_pgr_array_reverse`` needed for the migration. + + * ``_pgr_array_reverse``: + + * Was created temporally for this migration + * Is not documented. + * Will be removed on the next mayor version 4.0.0 + +.. literalinclude:: migration.queries + :start-after: --rest3 + :end-before: --rest4 + +The migrated table contents: + +.. literalinclude:: migration.queries + :start-after: --rest4 + :end-before: --rest5 See Also diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 49119a8534e..97f1d49de43 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -43,6 +43,8 @@ pgRouting 4.0.0 Release Notes * ``pgr_trspviaedges(text,integer[],double precision[],boolean,boolean,text)`` * ``pgr_trspviavertices(text,anyarray,boolean,boolean,text)`` +* ``pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text)`` +* ``pgr_trsp(text,integer,integer,boolean,boolean,text)`` @@ -74,6 +76,10 @@ milestone for 3.7.1 * `#2689 `__ When point is a vertex, the withPoints family do not return results. +.. rubric:: C/C++ code enhancemet + +* TRSP family + pgRouting 3.7.0 Release Notes ------------------------------------------------------------------------------- diff --git a/docqueries/src/migration.pg b/docqueries/src/migration.pg index 0cdb905cf84..a124777d8be 100644 --- a/docqueries/src/migration.pg +++ b/docqueries/src/migration.pg @@ -34,11 +34,6 @@ SELECT * FROM new_restrictions; /* --rest5 */ /* --verticesv1 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges WHERE id != 16$$, - 15, 16, - true, true); /* --verticesv2 */ SELECT * FROM pgr_dijkstra( $$SELECT id, source, target, cost, reverse_cost @@ -51,13 +46,6 @@ FROM pgr_dijkstra( FROM edges WHERE id != 16$$, 15, 16); /* --verticesv4 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges WHERE id != 16$$, - 15, 16, - true, true, - $$SELECT to_cost, target_id::INTEGER, via_path - FROM old_restrictions$$); /* --verticesv5 */ SELECT * FROM pgr_trsp( $$SELECT id, source, target, cost, reverse_cost @@ -75,11 +63,6 @@ FROM pgr_trsp( SELECT pid, edge_id, fraction, side FROM pointsOfInterest WHERE pid IN (3, 4); /* --edgesv1 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges$$, - 6, 0.3, 12, 0.6, - true, true); /* --edgesv2 */ SELECT * FROM pgr_withPoints( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, @@ -94,10 +77,6 @@ FROM pgr_withPoints( -1, -2, details => false); /* --edgesv4 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edges$$, - 6, 0.3, 12, 0.6, true, true, - $$SELECT to_cost, target_id::INTEGER, via_path FROM old_restrictions$$); /* --edgesv5 */ SELECT * FROM pgr_trsp_withPoints( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, diff --git a/docqueries/src/migration.result b/docqueries/src/migration.result index 60e3b9ba84b..c6b2a6aaa64 100644 --- a/docqueries/src/migration.result +++ b/docqueries/src/migration.result @@ -65,20 +65,6 @@ SELECT * FROM new_restrictions; /* --rest5 */ /* --verticesv1 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges WHERE id != 16$$, - 15, 16, - true, true); -WARNING: pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | 15 | 3 | 1 - 1 | 10 | 5 | 1 - 2 | 11 | 9 | 1 - 3 | 16 | -1 | 0 -(4 rows) - /* --verticesv2 */ SELECT * FROM pgr_dijkstra( $$SELECT id, source, target, cost, reverse_cost @@ -107,24 +93,6 @@ FROM pgr_dijkstra( (4 rows) /* --verticesv4 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges WHERE id != 16$$, - 15, 16, - true, true, - $$SELECT to_cost, target_id::INTEGER, via_path - FROM old_restrictions$$); -WARNING: pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | 15 | 3 | 1 - 1 | 10 | 5 | 1 - 2 | 11 | 11 | 1 - 3 | 12 | 13 | 1 - 4 | 17 | 15 | 1 - 5 | 16 | -1 | 0 -(6 rows) - /* --verticesv5 */ SELECT * FROM pgr_trsp( $$SELECT id, source, target, cost, reverse_cost @@ -168,21 +136,6 @@ WHERE pid IN (3, 4); (2 rows) /* --edgesv1 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost - FROM edges$$, - 6, 0.3, 12, 0.6, - true, true); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | -1 | 6 | 0.7 - 1 | 3 | 7 | 1 - 2 | 7 | 10 | 1 - 3 | 8 | 12 | 0.6 - 4 | -2 | -1 | 0 -(5 rows) - /* --edgesv2 */ SELECT * FROM pgr_withPoints( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, @@ -215,25 +168,6 @@ FROM pgr_withPoints( (5 rows) /* --edgesv4 */ -SELECT * FROM pgr_trsp( - $$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edges$$, - 6, 0.3, 12, 0.6, true, true, - $$SELECT to_cost, target_id::INTEGER, via_path FROM old_restrictions$$); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | -1 | 6 | 0.7 - 1 | 3 | 7 | 1 - 2 | 7 | 8 | 1 - 3 | 11 | 9 | 1 - 4 | 16 | 16 | 1 - 5 | 15 | 3 | 1 - 6 | 10 | 2 | 1 - 7 | 6 | 4 | 1 - 8 | 7 | 10 | 1 - 9 | 8 | 12 | 0.6 -(10 rows) - /* --edgesv5 */ SELECT * FROM pgr_trsp_withPoints( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, diff --git a/docqueries/trsp/issue693.pg b/docqueries/trsp/issue693.pg deleted file mode 100644 index 0a5521a19eb..00000000000 --- a/docqueries/trsp/issue693.pg +++ /dev/null @@ -1,16 +0,0 @@ --- CopyRight(c) pgRouting developers --- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ - - - CREATE TABLE routing (gid serial, length integer, source integer, target integer, reverse_cost integer); - INSERT INTO routing (length, source, target, reverse_cost) VALUES - (10000, 1, 2, 10000), - (5, 3, 1, 5), - (10, 4, 3, 10), - (10, 2, 4, 10); - - SELECT pgr_trsp( - 'SELECT gid as id, source::int4, target::int4, length::float8 as cost, length::float8 as reverse_cost FROM routing', - 1, 0.1, 1, 0.9, false, true - ); - diff --git a/docqueries/trsp/issue693.result b/docqueries/trsp/issue693.result deleted file mode 100644 index d572a6620fc..00000000000 --- a/docqueries/trsp/issue693.result +++ /dev/null @@ -1,29 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -CREATE TABLE routing (gid serial, length integer, source integer, target integer, reverse_cost integer); -CREATE TABLE -INSERT INTO routing (length, source, target, reverse_cost) VALUES - (10000, 1, 2, 10000), - (5, 3, 1, 5), - (10, 4, 3, 10), - (10, 2, 4, 10); -INSERT 0 4 -SELECT pgr_trsp( - 'SELECT gid as id, source::int4, target::int4, length::float8 as cost, length::float8 as reverse_cost FROM routing', - 1, 0.1, 1, 0.9, false, true - ); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - pgr_trsp ---------------- - (0,-1,1,1000) - (1,1,2,5) - (2,3,3,10) - (3,4,4,10) - (4,2,1,1000) - (5,-2,-1,0) -(6 rows) - -ROLLBACK; -ROLLBACK diff --git a/docqueries/trsp/issue704.pg b/docqueries/trsp/issue704.pg deleted file mode 100644 index 833819fcea1..00000000000 --- a/docqueries/trsp/issue704.pg +++ /dev/null @@ -1,69 +0,0 @@ --- CopyRight(c) pgRouting developers --- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ - - -CREATE TABLE maptest as -SELECT 671222::integer as id, 318255::integer as source, 222698::integer as target, 14.02::float8 as cost, 14.02::float8 as reverse_cost UNION ALL -SELECT 671223, 222698, 36655, 197.16, 197.16 UNION ALL -SELECT 582877, 408918, 5556, 458.09, 458.09 UNION ALL -SELECT 582876, 318255, 408918, 3.89, 3.89 UNION ALL -SELECT 585280, 5556, 454424, 54.84, 54.84; -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - null /* include the turn restrictions */ -) PG ; - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0.0000000001, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - null /* include the turn restrictions */ -) PG ; - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - $$SELECT 100::float AS to_cost, 25::INTEGER AS target_id, '32, 33'::TEXT AS via_path$$ -) PG ; - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0.0000000001, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - $$SELECT 100::float AS to_cost, 25::INTEGER AS target_id, '32, 33'::TEXT AS via_path$$ -) PG ; - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 1, /* end_offset */ - true, /* directed graph? */ - true /* has_reverse_cost? */ -); - diff --git a/docqueries/trsp/issue704.result b/docqueries/trsp/issue704.result deleted file mode 100644 index 09504e35a39..00000000000 --- a/docqueries/trsp/issue704.result +++ /dev/null @@ -1,100 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -CREATE TABLE maptest as -SELECT 671222::integer as id, 318255::integer as source, 222698::integer as target, 14.02::float8 as cost, 14.02::float8 as reverse_cost UNION ALL -SELECT 671223, 222698, 36655, 197.16, 197.16 UNION ALL -SELECT 582877, 408918, 5556, 458.09, 458.09 UNION ALL -SELECT 582876, 318255, 408918, 3.89, 3.89 UNION ALL -SELECT 585280, 5556, 454424, 54.84, 54.84; -SELECT 5 -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - null /* include the turn restrictions */ -) PG ; -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | node | edge | cost ------+--------+--------+---------- - 0 | 408918 | 582877 | 229.0450 - 1 | -2 | -1 | 0.0000 -(2 rows) - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0.0000000001, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - null /* include the turn restrictions */ -) PG ; -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | node | edge | cost ------+------+--------+---------- - 0 | -1 | 582877 | 229.0450 - 1 | -2 | -1 | 0.0000 -(2 rows) - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - $$SELECT 100::float AS to_cost, 25::INTEGER AS target_id, '32, 33'::TEXT AS via_path$$ -) PG ; -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | node | edge | cost ------+------+--------+---------- - 0 | -1 | 582877 | 229.0450 -(1 row) - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0.0000000001, /* ini_offset */ - 582877, /* edge_id of route end */ - 0.5, /* end_offset */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - $$SELECT 100::float AS to_cost, 25::INTEGER AS target_id, '32, 33'::TEXT AS via_path$$ -) PG ; -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | node | edge | cost ------+------+--------+---------- - 0 | -1 | 582877 | 229.0450 -(1 row) - -SELECT seq, id1 AS node, id2 AS edge, cost::numeric(11,4) -FROM pgr_trsp( - 'select * from maptest', - 582877, /* edge_id for start */ - 0, /* ini_offset */ - 582877, /* edge_id of route end */ - 1, /* end_offset */ - true, /* directed graph? */ - true /* has_reverse_cost? */ -); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | node | edge | cost ------+--------+--------+---------- - 0 | 408918 | 582877 | 458.0900 - 1 | 5556 | -1 | 0.0000 -(2 rows) - -ROLLBACK; -ROLLBACK diff --git a/docqueries/trsp/test.conf b/docqueries/trsp/test.conf index dd0d7a0f539..d6640dc5402 100644 --- a/docqueries/trsp/test.conf +++ b/docqueries/trsp/test.conf @@ -4,14 +4,10 @@ 'any' => { 'data' => ['trsp-issue244.data'], 'files' => [qw( - trsp-renumber.pg trsp.pg trsp_withPoints.pg trspVia.pg trspVia_withPoints.pg - trsp-any-02.pg - issue693.pg - issue704.pg )], }, ); diff --git a/docqueries/trsp/trsp-any-02.pg b/docqueries/trsp/trsp-any-02.pg deleted file mode 100644 index 5a41a599a93..00000000000 --- a/docqueries/trsp/trsp-any-02.pg +++ /dev/null @@ -1,29 +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 restrictions2 ( - rid integer NOT NULL, - to_cost double precision, - teid integer, - feid integer, - via text -); - -INSERT INTO restrictions2 (rid, to_cost, teid, feid, via) VALUES -(1,100,7,4,NULL), -(2,4,8,3,'5'), -(3,100,9,16,NULL); - -UPDATE edges SET cost = cost + 0.001 * id * id, reverse_cost = reverse_cost + 0.001 * id * id; - -select * from pgr_trsp( - 'select id::integer, source::integer, target::integer,cost, reverse_cost from edges ORDER BY ID', - 1, /* edge_id for start */ - 0.5, /* midpoint of edge */ - 6, /* edge_id of route end */ - 0.5, /* midpoint of edge */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - /* include the turn restrictions */ - 'select to_cost, teid as target_id, feid||coalesce('',''||via,'''') as via_path from restrictions2'); diff --git a/docqueries/trsp/trsp-any-02.result b/docqueries/trsp/trsp-any-02.result deleted file mode 100644 index 53346e2fde5..00000000000 --- a/docqueries/trsp/trsp-any-02.result +++ /dev/null @@ -1,48 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -SET extra_float_digits=-3; -SET -CREATE TABLE restrictions2 ( - rid integer NOT NULL, - to_cost double precision, - teid integer, - feid integer, - via text -); -CREATE TABLE -INSERT INTO restrictions2 (rid, to_cost, teid, feid, via) VALUES -(1,100,7,4,NULL), -(2,4,8,3,'5'), -(3,100,9,16,NULL); -INSERT 0 3 -UPDATE edges SET cost = cost + 0.001 * id * id, reverse_cost = reverse_cost + 0.001 * id * id; -UPDATE 18 -select * from pgr_trsp( - 'select id::integer, source::integer, target::integer,cost, reverse_cost from edges ORDER BY ID', - 1, /* edge_id for start */ - 0.5, /* midpoint of edge */ - 6, /* edge_id of route end */ - 0.5, /* midpoint of edge */ - true, /* directed graph? */ - true, /* has_reverse_cost? */ - /* include the turn restrictions */ - 'select to_cost, teid as target_id, feid||coalesce('',''||via,'''') as via_path from restrictions2'); -WARNING: pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+-------- - 0 | -1 | 1 | 0.5005 - 1 | 6 | 4 | 1.016 - 2 | 7 | 8 | 1.064 - 3 | 11 | 9 | 1.081 - 4 | 16 | 16 | 1.256 - 5 | 15 | 3 | 1.009 - 6 | 10 | 5 | 1.025 - 7 | 11 | 8 | 1.064 - 8 | 7 | 7 | 1.049 - 9 | 3 | 6 | 0.518 -(10 rows) - -ROLLBACK; -ROLLBACK diff --git a/docqueries/trsp/trsp-renumber.pg b/docqueries/trsp/trsp-renumber.pg deleted file mode 100644 index 3002b64ca89..00000000000 --- a/docqueries/trsp/trsp-renumber.pg +++ /dev/null @@ -1,33 +0,0 @@ --- CopyRight(c) pgRouting developers --- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ - - - -SELECT * FROM pgr_trsp( - 'SELECT id::INTEGER, (source+10)::INTEGER AS source, (target+10)::INTEGER AS target, cost::FLOAT FROM edges', - 11, 27, false, false -); - -SELECT * FROM _pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - $$ SELECT 1 AS id, ARRAY[4,7] AS path, 100 AS cost $$, - 6, 1, false -); - -SELECT * FROM _pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - $$ SELECT * FROM restrictions $$, - 6, 1, false -); - - -SELECT * FROM pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - 6, 1, false, false, - 'SELECT to_cost, target_id::int4, via_path - FROM old_restrictions' -); - - - - diff --git a/docqueries/trsp/trsp-renumber.result b/docqueries/trsp/trsp-renumber.result deleted file mode 100644 index 8a9dcf7a111..00000000000 --- a/docqueries/trsp/trsp-renumber.result +++ /dev/null @@ -1,74 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -SELECT * FROM pgr_trsp( - 'SELECT id::INTEGER, (source+10)::INTEGER AS source, (target+10)::INTEGER AS target, cost::FLOAT FROM edges', - 11, 27, false, false -); -WARNING: pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | 11 | 6 | 1 - 1 | 13 | 7 | 1 - 2 | 17 | 8 | 1 - 3 | 21 | 9 | 1 - 4 | 26 | 15 | 1 - 5 | 27 | -1 | 0 -(6 rows) - -SELECT * FROM _pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - $$ SELECT 1 AS id, ARRAY[4,7] AS path, 100 AS cost $$, - 6, 1, false -); - seq | path_seq | node | edge | cost | agg_cost ------+----------+------+------+------+---------- - 1 | 1 | 6 | 4 | 1 | 0 - 2 | 2 | 7 | 10 | 1 | 1 - 3 | 3 | 8 | 12 | 1 | 2 - 4 | 4 | 12 | 11 | 1 | 3 - 5 | 5 | 11 | 8 | 1 | 4 - 6 | 6 | 7 | 7 | 1 | 5 - 7 | 7 | 3 | 6 | 1 | 6 - 8 | 8 | 1 | -1 | 0 | 7 -(8 rows) - -SELECT * FROM _pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - $$ SELECT * FROM restrictions $$, - 6, 1, false -); - seq | path_seq | node | edge | cost | agg_cost ------+----------+------+------+------+---------- - 1 | 1 | 6 | 4 | 1 | 0 - 2 | 2 | 7 | 10 | 1 | 1 - 3 | 3 | 8 | 12 | 1 | 2 - 4 | 4 | 12 | 11 | 1 | 3 - 5 | 5 | 11 | 8 | 1 | 4 - 6 | 6 | 7 | 7 | 1 | 5 - 7 | 7 | 3 | 6 | 1 | 6 - 8 | 8 | 1 | -1 | 0 | 7 -(8 rows) - -SELECT * FROM pgr_trsp( - 'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges', - 6, 1, false, false, - 'SELECT to_cost, target_id::int4, via_path - FROM old_restrictions' -); -WARNING: pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0 - seq | id1 | id2 | cost ------+-----+-----+------ - 0 | 6 | 4 | 1 - 1 | 7 | 10 | 1 - 2 | 8 | 12 | 1 - 3 | 12 | 11 | 1 - 4 | 11 | 8 | 1 - 5 | 7 | 7 | 1 - 6 | 3 | 6 | 1 - 7 | 1 | -1 | 0 -(8 rows) - -ROLLBACK; -ROLLBACK diff --git a/include/c_types/trsp/trsp.h b/include/c_types/trsp/trsp.h deleted file mode 100644 index ea047b3cd89..00000000000 --- a/include/c_types/trsp/trsp.h +++ /dev/null @@ -1,53 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: trsp.h - -Copyright (c) 2015 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*/ - -#ifndef INCLUDE_C_TYPES_TRSP_TRSP_H_ -#define INCLUDE_C_TYPES_TRSP_TRSP_H_ - -#define MAX_RULE_LENGTH 5 - - -/* for int64_t */ -#ifdef __cplusplus -# include -typedef int64_t int64; -#else -# include -#endif - -struct restrict_t { - int target_id; - double to_cost; - int via[MAX_RULE_LENGTH]; -}; - -struct path_element_tt { - int64_t vertex_id; - int64_t edge_id; - double cost; -}; - - -#endif // INCLUDE_C_TYPES_TRSP_TRSP_H_ diff --git a/include/trsp/GraphDefinition.hpp b/include/trsp/GraphDefinition.hpp deleted file mode 100644 index ea10b83d67e..00000000000 --- a/include/trsp/GraphDefinition.hpp +++ /dev/null @@ -1,162 +0,0 @@ -/*PGR-GNU***************************************************************** -File: GraphDefinition.hpp - -Copyright (c) 2012 pgRouting developers -Mail: project@pgrouting.org - -Copyright 2012 steve ------- - -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*/ - -#ifndef INCLUDE_TRSP_GRAPHDEFINITION_HPP_ -#define INCLUDE_TRSP_GRAPHDEFINITION_HPP_ - -#include - -#include -#include -#include -#include -#include -#include -#include - - -#include "c_types/trsp/trsp.h" - -// using namespace std; - -using Edge_t = struct Edge_rt; -typedef std::vector LongVector; -typedef std::vector VectorOfLongVector; -typedef std::pair PIB; -typedef std::pair PDP; -typedef std::pair > PDVI; - -typedef struct { - int64 ed_ind[2]; - int64 v_pos[2]; -} PARENT_PATH; - -typedef struct Rule { - double cost; - std::vector precedencelist; - Rule(double c, std::vector p) : cost(c), precedencelist(p) { } -}Rule; - -typedef struct { - double startCost, endCost; -} CostHolder; - -typedef std::map > RuleTable; - - - -class GraphEdgeInfo { - public: - int64 m_lEdgeID; - int64 m_lEdgeIndex; - int64 m_sDirection; - double m_dCost; - double m_dReverseCost; - LongVector m_vecStartConnectedEdge; - LongVector m_vecEndConnedtedEdge; - bool m_bIsLeadingRestrictedEdge; - VectorOfLongVector m_vecRestrictedEdge; - - int64 m_lStartNode; - int64 m_lEndNode; -}; - - - - -typedef std::vector GraphEdgeVector; -typedef std::map Long2LongVectorMap; -typedef std::map Long2LongMap; - - - - -class GraphDefinition { - public: - GraphDefinition(void); - ~GraphDefinition(void); - - int my_dijkstra3(Edge_t *edges, size_t edge_count, - int64 start_vertex, int64 end_vertex, - bool directed, bool has_reverse_cost, - path_element_tt **path, size_t *path_count, - char **err_msg); - - int my_dijkstra2(Edge_t *edges, size_t edge_count, - int64 start_vertex, int64 end_vertex, - bool directed, bool has_reverse_cost, - path_element_tt **path, size_t *path_count, - char **err_msg, - std::vector &ruleList); - - int my_dijkstra1(Edge_t *edges, size_t edge_count, - int64 start_edge, double start_part, - int64 end_edge, double end_part, - bool directed, bool has_reverse_cost, - path_element_tt **path, size_t *path_count, - char **err_msg, - std::vector &ruleList); - - bool construct_graph(Edge_t *edges, size_t edge_count, - bool has_reverse_cost, bool directed); - - - private: - double construct_path(int64 ed_id, int64 v_pos); - void explore(int64 cur_node, GraphEdgeInfo& cur_edge, bool isStart, - LongVector &vecIndex, std::priority_queue, std::greater > &que); - double getRestrictionCost(int64 cur_node, GraphEdgeInfo& new_edge, - bool isStart); - bool addEdge(Edge_t edgeIn); - bool connectEdge(GraphEdgeInfo& firstEdge, GraphEdgeInfo& secondEdge, - bool bIsStartNodeSame); - bool get_single_cost(double total_cost, path_element_tt **path, - size_t *path_count); - void init(); - void deleteall(); - - private: - GraphEdgeVector m_vecEdgeVector; - Long2LongMap m_mapEdgeId2Index; - Long2LongVectorMap m_mapNodeId2Edge; - int64 max_node_id; - int64 max_edge_id; - int64 m_lStartEdgeId; - int64 m_lEndEdgeId; - double m_dStartpart; - double m_dEndPart; - bool isStartVirtual; - bool isEndVirtual; - - std::vector m_vecPath; - PARENT_PATH *parent; - CostHolder *m_dCost; - RuleTable m_ruleTable; - bool m_bIsturnRestrictOn; - bool m_bIsGraphConstructed; -}; - -#endif // INCLUDE_TRSP_GRAPHDEFINITION_HPP_ diff --git a/include/trsp/trspHandler.hpp b/include/trsp/trspHandler.hpp index 772f6666972..c601f7ae3b3 100644 --- a/include/trsp/trspHandler.hpp +++ b/include/trsp/trspHandler.hpp @@ -50,7 +50,7 @@ namespace trsp { -class Pgr_trspHandler : public pgrouting::Pgr_messages { +class TrspHandler : public pgrouting::Pgr_messages { /** * Used in the priority queue */ @@ -101,104 +101,54 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { public: - Pgr_trspHandler( + TrspHandler( std::vector &edges, const std::vector &new_edges, const bool directed, const std::vector &ruleList); - Pgr_trspHandler( + + TrspHandler( std::vector &edges, const bool directed, const std::vector &ruleList); - Pgr_trspHandler( - Edge_t *edges, - const size_t edge_count, - const bool directed, - const std::vector &ruleList); - Pgr_trspHandler( - Edge_t *edges, - const size_t edge_count, - const std::vector &new_edges, - const bool directed, - const std::vector &ruleList); - - Pgr_trspHandler(void) = delete; - ~Pgr_trspHandler(void) = default; - - - Path process( - const int64_t start_vertex, - const int64_t end_vertex); - - std::deque process( - const std::map> &combinations); - - std::deque process( - const std::vector sources, - const std::vector targets); + ~TrspHandler(void) = default; + std::deque process(const std::map>&); void clear(); private: - void construct_graph(const std::vector&, const bool); - void construct_graph( - Edge_t *edges, - const size_t edge_count, - const bool directed); + void construct_graph(const std::vector&, const std::vector&, const bool); - void add_point_edges( - const std::vector &new_edges, - const bool directed); - - int initialize_restrictions( - const std::vector &ruleList); + int initialize_restrictions(const std::vector&); void initialize_que(); - Path process_trsp( - size_t edge_count); + Path process(const int64_t, const int64_t); + + Path process_trsp(size_t edge_count); EdgeInfo dijkstra_exploration(); + void explore(int64_t, const EdgeInfo, bool); - void explore( - int64_t cur_node, - const EdgeInfo cur_edge, - bool isStart); + double getRestrictionCost(int64_t, const EdgeInfo&, bool); - double getRestrictionCost( - int64_t cur_node, - const EdgeInfo &new_edge, - bool isStart); - bool addEdge(Edge_t edgeIn, bool); + bool addEdge(Edge_t, bool); - void connectStartEdge( - size_t firstEdge_idx, - size_t secondEdge_idx); + void connectStartEdge(size_t, size_t); - void connectEndEdge( - size_t firstEdge_idx, - size_t secondEdge_idx); + void connectEndEdge(size_t, size_t); - double construct_path(int64_t ed_id, Position pos); + double construct_path(int64_t, Position); - void renumber_edges(Edge_t*, const size_t); - void renumber_edges(Edge_t*, const size_t, std::vector&); void renumber_edges(std::vector&); void renumber_edges(std::vector&, std::vector&); - void add_to_que( - double cost, - size_t e_idx, - bool isStart); + void add_to_que(double, size_t, bool); - double get_tot_cost( - double cost, - size_t edge_idx, - bool isStart); + double get_tot_cost(double, size_t, bool); private: std::vector m_edges; @@ -226,7 +176,7 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { /* * Used in dijkstra_exploration */ - int64_t current_node; + int64_t m_current_node; Path m_path; @@ -238,7 +188,7 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { /* * priority queue */ - std::priority_queue, std::greater > que; + std::priority_queue, std::greater> m_que; }; diff --git a/pgtap/trsp/trsp/compare_dijkstra/blank_restrictions.pg b/pgtap/trsp/trsp/compare_dijkstra/blank_restrictions.pg deleted file mode 100644 index fba5adccfb4..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/blank_restrictions.pg +++ /dev/null @@ -1,75 +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(1296); -SET client_min_messages TO ERROR; - - --- TEST of deprecated signature --- This test does not make sense on new signatures due to the fact that the functions are STRICT (aka no nulls) -create or REPLACE FUNCTION foo(cant INTEGER default 18, flag boolean default true ) -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -dijkstra_sql TEXT; -turnRestricted_sql TEXT; -inner_sql1 TEXT; -inner_sql2 TEXT; -k integer; -directed TEXT; -msg TEXT; -blank TEXT; -BEGIN - directed = 'Undirected'; - blank := quote_literal(''); - IF flag THEN directed = 'Directed'; END IF; - k := 1; - inner_sql1 = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges ORDER BY id'); - inner_sql2 = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost from edges ORDER BY id'); - FOR i IN 1.. cant LOOP - FOR j IN 1..cant LOOP - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost - FROM pgr_dijkstra( ' || inner_sql1 || ', ' || i || ', ' || j || ', ' || flag || ')'; - turnRestricted_sql := 'SELECT * from pgr_trsp( ' || inner_sql1 || ', ' || i || ', ' || j || ', ' || flag || ', true, ' || blank || ')'; - msg := k || ' ' || directed || ', with reverse_cost: from ' || i || ' to ' || j; - RETURN query SELECT set_eq(dijkstra_sql, turnRestricted_sql, msg); - k := k + 1; - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost - FROM pgr_dijkstra( ' || inner_sql2 || ', ' || i || ', ' || j || ', ' || flag || ')'; - turnRestricted_sql := 'SELECT * from pgr_trsp( ' || inner_sql2 || ', ' || i || ', ' || j || ', ' || flag || ', false, ' || blank || ')'; - msg := k || ' ' || directed || ', no reverse_cost: from ' || i || ' to ' || j; - RETURN query SELECT set_eq(dijkstra_sql, turnRestricted_sql, msg); - k := k + 1; - END LOOP; - END LOOP; -END -$BODY$ -language plpgsql; - -SELECT * from foo(18, true); -SELECT * from foo(18, false); - - --- Finish the tests and clean up. -SELECT * FROM finish(); -ROLLBACK; - diff --git a/pgtap/trsp/trsp/compare_dijkstra/directed/related_restrictions.pg b/pgtap/trsp/trsp/compare_dijkstra/directed/related_restrictions.pg deleted file mode 100644 index 8f5775d6396..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/directed/related_restrictions.pg +++ /dev/null @@ -1,33 +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; - -SELECT CASE WHEN min_version('3.4.0') THEN plan(18) ELSE plan(1) END; -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; - -PREPARE with_reverse_cost AS SELECT id, source, target, cost, reverse_cost from edges ORDER BY id; -PREPARE no_reverse_cost AS SELECT id, source, target, cost from edges ORDER BY id; -PREPARE related AS SELECT * FROM restrictions; - -SELECT compare_trsp_dijkstra_new(18, true, 'related'); - -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/compare_dijkstra/directed/unrelated_restrictions.pg b/pgtap/trsp/trsp/compare_dijkstra/directed/unrelated_restrictions.pg deleted file mode 100644 index 46d8f33dd84..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/directed/unrelated_restrictions.pg +++ /dev/null @@ -1,35 +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; - -SELECT CASE WHEN min_version('3.4.0') THEN plan(648) ELSE plan(2) END; -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; - -PREPARE with_reverse_cost AS SELECT id, source, target, cost, reverse_cost from edges ORDER BY id; -PREPARE no_reverse_cost AS SELECT id, source, target, cost from edges ORDER BY id; -PREPARE unrelated1 AS SELECT * FROM restrictions WHERE id > 7; -PREPARE unrelated2 AS SELECT 1 AS id, 100::float AS cost, ARRAY[33, 32, 25] AS path; - -SELECT compare_trsp_dijkstra_new(18, true, 'unrelated1'); -SELECT compare_trsp_dijkstra_new(18, true, 'unrelated2'); - -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_directed.pg b/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_directed.pg deleted file mode 100644 index 95eab2db767..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_directed.pg +++ /dev/null @@ -1,31 +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; - -SELECT plan(612); -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; -SET client_min_messages TO ERROR; - --- TEST of deprecated signature -SELECT compare_trsp_dijkstra(18, true); - -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_undirected.pg b/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_undirected.pg deleted file mode 100644 index ccc6ede82a7..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/no_restrictions_undirected.pg +++ /dev/null @@ -1,31 +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; - -SELECT plan(612); -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; -SET client_min_messages TO ERROR; - --- TEST of deprecated signature -SELECT compare_trsp_dijkstra(18, false); - -SELECT finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/compare_dijkstra/undirected/related_restrictions.pg b/pgtap/trsp/trsp/compare_dijkstra/undirected/related_restrictions.pg deleted file mode 100644 index ebddccf7ebb..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/undirected/related_restrictions.pg +++ /dev/null @@ -1,33 +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; - -SELECT CASE WHEN min_version('3.4.0') THEN plan(18) ELSE plan(1) END; -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; - -PREPARE with_reverse_cost AS SELECT id, source, target, cost, reverse_cost from edges ORDER BY id; -PREPARE no_reverse_cost AS SELECT id, source, target, cost from edges ORDER BY id; -PREPARE related AS SELECT * FROM restrictions; - -SELECT compare_trsp_dijkstra_new(18, false, 'related'); - -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/compare_dijkstra/undirected/unrelated_restrictions.pg b/pgtap/trsp/trsp/compare_dijkstra/undirected/unrelated_restrictions.pg deleted file mode 100644 index b44b2c5d8ce..00000000000 --- a/pgtap/trsp/trsp/compare_dijkstra/undirected/unrelated_restrictions.pg +++ /dev/null @@ -1,35 +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; - -SELECT CASE WHEN min_version('3.4.0') THEN plan(648) ELSE plan(2) END; -SET extra_float_digits = -3; -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; - -PREPARE with_reverse_cost AS SELECT id, source, target, cost, reverse_cost from edges ORDER BY id; -PREPARE no_reverse_cost AS SELECT id, source, target, cost from edges ORDER BY id; -PREPARE unrelated1 AS SELECT * FROM restrictions WHERE id > 7; -PREPARE unrelated2 AS SELECT 1 AS id, 100::float AS cost, ARRAY[33, 32, 25] AS path; - -SELECT compare_trsp_dijkstra_new(18, false, 'unrelated1'); -SELECT compare_trsp_dijkstra_new(18, false, 'unrelated2'); - -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/edge_cases/compare_dijkstra.pg b/pgtap/trsp/trsp/edge_cases/compare_dijkstra.pg index 586ae1e8c94..08f0656cbf4 100644 --- a/pgtap/trsp/trsp/edge_cases/compare_dijkstra.pg +++ b/pgtap/trsp/trsp/edge_cases/compare_dijkstra.pg @@ -1,4 +1,3 @@ - /*PGR-GNU***************************************************************** Copyright (c) 2018 pgRouting developers @@ -18,52 +17,27 @@ 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; -SELECT plan(1); +SET extra_float_digits = -3; UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; -CREATE OR REPLACE FUNCTION do_test() RETURNS SETOF TEXT AS -$BODY$ -BEGIN - - IF min_version('3.4.0') THEN - prepare q1 AS - SELECT seq, node, edge, cost::TEXT FROM pgr_trsp( - 'select id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 1, -- node_id of start - 5, -- node_id of end - true); -- directed graph? - - prepare q2 AS - SELECT seq, node, edge, cost::TEXT FROM pgr_dijkstra( - 'select id, source, target, cost, reverse_cost from edges', - 1, 5); - ELSE +SELECT CASE WHEN min_version('3.4.0') THEN plan(1882) ELSE plan(6) END; - prepare q1 AS - SELECT seq, id1, id2, cost::TEXT FROM pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges', - 1, -- node_id of start - 5, -- node_id of end - true, -- directed graph? - true, -- has_reverse_cost? - null); -- no turn restrictions +PREPARE with_reverse_cost AS SELECT id, source, target, cost, reverse_cost from edges ORDER BY id; +PREPARE no_reverse_cost AS SELECT id, source, target, cost from edges ORDER BY id; +PREPARE related AS SELECT * FROM restrictions; +PREPARE unrelated1 AS SELECT * FROM restrictions WHERE id > 7; +PREPARE unrelated2 AS SELECT 1 AS id, 100::float AS cost, ARRAY[33, 32, 25] AS path; - prepare q2 AS - SELECT seq-1, node::INTEGER, edge::INTEGER, cost::TEXT FROM pgr_dijkstra( - 'select id, source, target, cost, reverse_cost from edges', - 1, 5); - END IF; - RETURN QUERY - SELECT set_eq('q2', 'q1', 'No turn restriction from 1 to 5 returns same as dijkstra'); -END; +SELECT compare_trsp_dijkstra_new(18, true, 'related'); +SELECT compare_trsp_dijkstra_new(18, false, 'related'); -$BODY$ -LANGUAGE plpgSQL; +SELECT compare_trsp_dijkstra_new(18, true, 'unrelated1'); +SELECT compare_trsp_dijkstra_new(18, false, 'unrelated1'); -SELECT do_test(); +SELECT compare_trsp_dijkstra_new(18, true, 'unrelated2'); +SELECT compare_trsp_dijkstra_new(18, false, 'unrelated2'); -SELECT finish(); +SELECT * FROM finish(); ROLLBACK; diff --git a/pgtap/trsp/trsp/edge_cases/compare_dijkstraVia.pg b/pgtap/trsp/trsp/edge_cases/compare_dijkstraVia.pg index e2aa2bf5ebc..600e4a2a14a 100644 --- a/pgtap/trsp/trsp/edge_cases/compare_dijkstraVia.pg +++ b/pgtap/trsp/trsp/edge_cases/compare_dijkstraVia.pg @@ -1,4 +1,3 @@ - /*PGR-GNU***************************************************************** Copyright (c) 2018 pgRouting developers @@ -19,162 +18,98 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ BEGIN; -SELECT plan(7); - +SET extra_float_digits=-3; UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; +SELECT CASE WHEN min_version('3.4.0') THEN plan(6) ELSE plan(1) END; + +PREPARE related_restriction AS SELECT 100.2 AS cost, ARRAY[4,8] AS path; +PREPARE unrelated_restriction AS SELECT 100 AS cost, ARRAY[33, 32, 25] AS path; + CREATE OR REPLACE FUNCTION edge_cases() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF min_version('3.4.0') THEN - - PREPARE q1 AS - SELECT * from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 5, - true); - - PREPARE q2 AS - SELECT * from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 10, - true); - - PREPARE q21 AS - SELECT seq, node, edge, round(cost::numeric, 3) from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 10, - true); - - PREPARE q22 AS - SELECT seq, node, edge, round(cost::numeric, 3) from pgr_dijkstra( - 'SELECT id, source, target, cost, reverse_cost from edges', - 5, 10, true); - - PREPARE q31 AS - SELECT seq-1::INTEGER, node::INTEGER, edge::INTEGER, round(cost::numeric, 3) from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100.2 AS cost, 6 AS target_id, ARRAY[4,8] AS path$$, - 5, 10, - true); - - PREPARE q41 AS - SELECT * from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 5, - FALSE); - - PREPARE q51 AS - SELECT seq, node, edge, cost::text from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 10, - FALSE); - - PREPARE q52 AS - SELECT seq, node, edge, cost::text from pgr_dijkstra( - 'SELECT id, source, target, cost, reverse_cost from edges', - 5, 10, FALSE); - - PREPARE q61 AS - SELECT seq-1::INTEGER, node::INTEGER, edge::INTEGER, cost::TEXT from pgr_trsp( - 'SELECT id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100.2::float AS cost, 6::INTEGER AS target_id, ARRAY[4,8] AS path$$, - 5, 10, - FALSE); - - ELSE - - PREPARE q1 AS - SELECT * from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges', - 5, 5, - true, true); - - PREPARE q2 AS - SELECT * from pgr_trsp( - 'select id::INTEGER, source::BIGINT, target::INTEGER, cost, reverse_cost from edges', - 5, 10, - true, true); - - PREPARE q21 AS - SELECT seq, id1, id2, round(cost::numeric, 3) from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, - true, true); - - PREPARE q22 AS - SELECT seq-1, node::INTEGER, edge::INTEGER, round(cost::numeric, 3) from pgr_dijkstra( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, true); - - PREPARE q31 AS - SELECT seq, id1, id2, round(cost::numeric, 3) from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, - true, true, - 'select 8::INTEGER as target_id, ''4''::TEXT as via_path, 100.2::FLOAT to_cost'); - - PREPARE q41 AS - SELECT * from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 5, - FALSE, true); - - PREPARE q51 AS - SELECT seq, id1, id2, cost::text from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, - FALSE, true); - - PREPARE q52 AS - SELECT seq-1, node::INTEGER, edge::INTEGER, cost::text from pgr_dijkstra( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, FALSE); - - PREPARE q61 AS - SELECT seq, id1, id2, cost::text from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 10, - FALSE, true, - 'select 8::INTEGER as target_id, ''4''::TEXT as via_path, 100.2::FLOAT to_cost'); - + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_signature added on 3.4.0'); + RETURN; END IF; - PREPARE q32 AS - SELECT (row_number() over() -1)::INTEGER, node::INTEGER, - (CASE WHEN edge = -2 THEN -1 ELSE edge END)::INTEGER, round(cost::numeric, 3) + /* Directed */ + PREPARE q1 AS + SELECT * from pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + $$SELECT 100 AS cost, ARRAY[33, 32, 25] AS path$$, + 5, 5, true); + + RETURN QUERY SELECT is_empty('q1', 'Directed: No path from 5 to 5'); + + PREPARE q21 AS + SELECT seq, node, edge, cost from pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + 'unrelated_restriction', + 5, 10, true); + + PREPARE q21_expected AS + SELECT seq, node, edge, cost from pgr_dijkstra( + 'SELECT id, source, target, cost, reverse_cost from edges', + 5, 10, true); + + RETURN QUERY SELECT set_eq('q21','q21_expected','Directed: without retrictions expected the same as pgr_dijkstra'); + + PREPARE q31 AS + SELECT seq-1, node, edge, cost::TEXT FROM pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + 'related_restriction', + 5, 10, true); + + PREPARE q31_expected AS + SELECT (row_number() over() -1), node, CASE WHEN edge = -2 THEN -1 ELSE edge END, cost::TEXT FROM pgr_dijkstraVia( 'select id, source, target, cost, reverse_cost from edges', ARRAY[5, 8, 17, 15, 10], - true) where edge != -1; + true) WHERE edge != -1; - RETURN QUERY SELECT is_empty('q1', '1: Directed: No path from 1 to 1'); - IF NOT min_version('3.4.0') THEN - PERFORM todo(1, 'Function does not accept ANY-INTEGER and ANY-NUMERICAL'); - END IF; - RETURN QUERY SELECT lives_ok('q2', '2: ANY_INTEGER and ANY_NUMERICAL are accepted'); - RETURN QUERY SELECT set_eq('q21','q22','3: Directed: without retrictions returns the same as pgr_dijkstra'); - RETURN QUERY SELECT set_eq('q31','q32','4: Directed: with retrictions returns expected path'); + RETURN QUERY SELECT set_eq('q31','q31_expected','Directed: with retrictions expected the same as pgr_dijkstraVia'); + + /* Undirected */ + PREPARE q41 AS + SELECT * from pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + 'unrelated_restriction', + 5, 5, false); + RETURN QUERY SELECT is_empty('q41', '5: Undirected: No path from 5 to 5'); - PREPARE q62 AS - SELECT (row_number() over() -1)::INTEGER, node::INTEGER, - (CASE WHEN edge = -2 THEN -1 ELSE edge END)::INTEGER, cost::text + PREPARE q51 AS + SELECT seq, node, edge, cost::text from pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + 'unrelated_restriction', + 5, 10, false); + + PREPARE q51_expected AS + SELECT seq, node, edge, cost::text from pgr_dijkstra( + 'SELECT id, source, target, cost, reverse_cost from edges', + 5, 10, false); + + RETURN QUERY SELECT set_eq('q51','q51_expected','6: Undirected: without retrictions returns the same as pgr_dijkstra'); + + PREPARE q61 AS + SELECT seq-1, node, edge, cost::TEXT from pgr_trsp( + 'SELECT id, source, target, cost, reverse_cost from edges', + 'related_restriction', + 5, 10, false); + + PREPARE q61_expected AS + SELECT (row_number() over() -1), node, + (CASE WHEN edge = -2 THEN -1 ELSE edge END), cost::text FROM pgr_dijkstraVia( - 'select id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges', + 'select id, source, target, cost, reverse_cost from edges', ARRAY[5, 6, 10], - FALSE) where edge != -1; + false) WHERE edge != -1; - RETURN QUERY SELECT is_empty('q41', '5: Undirected: No path from 1 to 1'); - RETURN QUERY SELECT set_eq('q51','q52','6: Undirected: without retrictions returns the same as pgr_dijkstra'); - RETURN QUERY SELECT set_eq('q61','q62','7: Undirected: with retrictions returns expected path'); + RETURN QUERY SELECT set_eq('q61','q61_expected','7: Undirected: with retrictions returns expected path'); END; $BODY$ LANGUAGE plpgsql; diff --git a/pgtap/trsp/trsp/edge_cases/directed_compare_dijkstraVia.pg b/pgtap/trsp/trsp/edge_cases/directed_compare_dijkstraVia.pg index f30fb8cf662..cc073cb165c 100644 --- a/pgtap/trsp/trsp/edge_cases/directed_compare_dijkstraVia.pg +++ b/pgtap/trsp/trsp/edge_cases/directed_compare_dijkstraVia.pg @@ -19,88 +19,65 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ BEGIN; -SELECT plan(3); - SET extra_float_digits = -3; UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; +SELECT CASE WHEN min_version('3.4.0') THEN plan(3) ELSE plan(1) END; + +PREPARE related_restriction AS SELECT 100.2 AS cost, ARRAY[5,9] AS path; +PREPARE unrelated_restriction AS SELECT 100 AS cost, ARRAY[33, 32, 25] AS path; -CREATE OR REPLACE FUNCTION edge_case() RETURNS SETOF TEXT AS +CREATE OR REPLACE FUNCTION edge_cases() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF min_version('3.4.0') THEN - PREPARE q1 AS - SELECT * from pgr_trsp( - 'select id, source, target,cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 5, 5, - true); - - PREPARE q2 AS - SELECT seq, node, edge, round(cost::numeric, 12) from pgr_trsp( - 'select id, source, target,cost, reverse_cost from edges', - $$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$, - 10, 15, - true); - - PREPARE e2 AS - SELECT seq, node, edge, round(cost::numeric, 12) from pgr_dijkstra( - 'select id, source, target, cost, reverse_cost from edges', - 10, 15); - - PREPARE q3 AS - SELECT seq-1::INTEGER, node::INTEGER, edge::INTEGER, round(cost::numeric, 12) from pgr_trsp( - 'select id, source, target, cost, reverse_cost from edges', - $$SELECT 1 AS id, 100.2::float AS cost, ARRAY[5,9] AS path$$, - 10, 15, - true); - - ELSE - - PREPARE q1 AS - SELECT * from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 5, 5, - true, true); - - PREPARE q2 AS - SELECT seq, id1, id2, round(cost::numeric, 12) from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER,cost, reverse_cost from edges', - 10, 15, - true, true); - - PREPARE e2 AS - SELECT seq-1, node::INTEGER, edge::INTEGER, round(cost::numeric, 12) from pgr_dijkstra( - 'select id, source, target, cost, reverse_cost from edges', - 10, 15, true); - - PREPARE q3 AS - SELECT seq, id1, id2, round(cost::numeric, 12) from pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges', - 10, 15, - true, true, - 'select 9::INTEGER as target_id, ''5''::TEXT as via_path, 100.2::FLOAT to_cost'); - + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_signature added on 3.4.0'); + RETURN; END IF; - PREPARE e3 AS - SELECT (row_number() over() -1)::INTEGER, node::INTEGER, - (CASE WHEN edge = -2 THEN -1 ELSE edge END)::INTEGER, round(cost::numeric, 12) + PREPARE q1 AS + SELECT * from pgr_trsp( + 'select id, source, target,cost, reverse_cost from edges', + 'unrelated_restriction', + 5, 5, + true); + RETURN QUERY SELECT is_empty('q1', '1: No path from 1 to 1'); + + PREPARE q2 AS + SELECT seq, node, edge, cost from pgr_trsp( + 'select id, source, target,cost, reverse_cost from edges', + 'unrelated_restriction', + 10, 15, + true); + + PREPARE q2_expected AS + SELECT seq, node, edge, cost from pgr_dijkstra( + 'select id, source, target, cost, reverse_cost from edges', + 10, 15); + RETURN QUERY SELECT set_eq('q2','q2_expected','2: without retrictions returns the same as pgr_dijkstra'); + + PREPARE q3 AS + SELECT seq-1, node, edge, cost::TEXT from pgr_trsp( + 'select id, source, target, cost, reverse_cost from edges', + 'related_restriction', + 10, 15, + true); + + PREPARE q3_expected AS + SELECT (row_number() over() -1), node, (CASE WHEN edge = -2 THEN -1 ELSE edge END), cost::TEXT FROM pgr_dijkstraVia( 'select id, source, target, cost, reverse_cost from edges', ARRAY[10, 6, 15], true) where edge != -1; - RETURN QUERY SELECT is_empty('q1', '1: No path from 1 to 1'); - RETURN QUERY SELECT set_eq('q2','e2','2: without retrictions returns the same as pgr_dijkstra'); - RETURN QUERY SELECT set_eq('q3','e3','3: with retrictions returns expected path'); + RETURN QUERY SELECT set_eq('q3','q3_expected','2: without retrictions returns the same as pgr_dijkstraVia'); END; $BODY$ LANGUAGE plpgsql; -SELECT edge_case(); +SELECT edge_cases(); SELECT finish(); ROLLBACK; diff --git a/pgtap/trsp/trsp/edge_cases.pg b/pgtap/trsp/trsp/edge_cases/edge_cases.pg similarity index 100% rename from pgtap/trsp/trsp/edge_cases.pg rename to pgtap/trsp/trsp/edge_cases/edge_cases.pg diff --git a/pgtap/trsp/trsp/edge_cases/emptyset_from_i_to_i.pg b/pgtap/trsp/trsp/edge_cases/emptyset_from_i_to_i.pg index 83674f28cf7..017bdb4dbce 100644 --- a/pgtap/trsp/trsp/edge_cases/emptyset_from_i_to_i.pg +++ b/pgtap/trsp/trsp/edge_cases/emptyset_from_i_to_i.pg @@ -20,10 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT plan(144); +SELECT CASE WHEN min_version('3.4.0') THEN plan(72) ELSE plan(2) END; +PREPARE restriction AS SELECT * FROM restrictions; +PREPARE with_reverse AS SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id; +PREPARE no_reverse AS SELECT id, source, target, cost FROM edges ORDER BY id; -create or REPLACE FUNCTION edge_cases(cant INTEGER default 18, flag boolean default true ) +CREATE OR REPLACE FUNCTION edge_cases(cant INTEGER DEFAULT 18, flag BOOLEAN DEFAULT true ) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -36,138 +39,37 @@ directed TEXT; msg TEXT; parameters TEXT; BEGIN -IF min_version('3.4.0') THEN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_signature added on 3.4.0'); + RETURN; + END IF; + directed = 'Undirected'; IF flag THEN directed = 'Directed'; END IF; + k := 1; - with_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges ORDER BY id'); - no_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost from edges ORDER BY id'); - restrictions_sql = quote_literal('SELECT 100::float AS to_cost, 25::INTEGER AS target_id, ''32, 33''::TEXT AS via_path'); - restrictions_sql = 'NULL::TEXT'; + with_reverse_cost = quote_literal('with_reverse'); + no_reverse_cost = quote_literal('no_reverse'); + restrictions_sql = quote_literal('restriction'); FOR i IN 1.. cant LOOP + parameters = restrictions_sql || ', ' || i || ', ' || i || ', ' || flag; trsp_sql := 'SELECT * from pgr_trsp( ' || with_reverse_cost || ', ' || parameters || ')'; - msg := k || ' ' || directed || ', with reverse_cost and saying we use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || ' is_empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; + msg := k || ' ' || trsp_sql; + EXECUTE trsp_sql; + RETURN query SELECT is_empty(trsp_sql, msg); + k := k + 1; - - trsp_sql := 'SELECT * from pgr_trsp( ' || with_reverse_cost || ', ' || parameters || ')'; - msg := k || ' ' || directed || ', with reverse_cost and saying we dont use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; - - trsp_sql := 'SELECT * from pgr_trsp( ' || no_reverse_cost || ', ' || parameters || ')'; - msg := k || ' ' || directed || ', No reverse_cost and saying we dont use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; - - /* Ignoring has_rcost flag */ - trsp_sql := 'SELECT * from pgr_trsp( ' || no_reverse_cost || ', ' || parameters || ')'; - msg := k || ' ' || directed || ', No reverse_cost and saying we use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - RETURN query SELECT throws_ok(trsp_sql,'XX000',$$Error, reverse_cost is used, but query did't return 'reverse_cost' column$$); - END; - k := k + 1; + trsp_sql := 'SELECT * from pgr_trsp( ' || no_reverse_cost || ', ' || parameters || ')'; + msg := k || ' ' || trsp_sql; + EXECUTE trsp_sql; + RETURN query SELECT is_empty(trsp_sql, msg); + k := k + 1; END LOOP; -ELSE - - directed = 'Undirected'; - IF flag THEN directed = 'Directed'; END IF; - k := 1; - with_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges ORDER BY id'); - no_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost from edges ORDER BY id'); - - FOR i IN 1.. cant LOOP - trsp_sql := 'SELECT * from pgr_trsp( ' || with_reverse_cost || ', ' || i || ', ' || i || ', ' || flag || ', true)'; - msg := k || ' ' || directed || ', with reverse_cost and saying we use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || ' is_empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; - - - trsp_sql := 'SELECT * from pgr_trsp( ' || with_reverse_cost || ', ' || i || ', ' || i || ', ' || flag || ', false)'; - msg := k || ' ' || directed || ', with reverse_cost and saying we dont use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; - - trsp_sql := 'SELECT * from pgr_trsp( ' || no_reverse_cost || ', ' || i || ', ' || i || ', ' || flag || ', false)'; - msg := k || ' ' || directed || ', No reverse_cost and saying we dont use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - IF (i < 18) THEN - RETURN query SELECT throws_ok(trsp_sql,'38001','Error computing path: Path Not Found', msg); - ELSE - RETURN query SELECT throws_ok(trsp_sql,'XX000','Start id was not found.', msg); - END IF; - END; - k := k + 1; - - /* Ignoring has_rcost flag */ - trsp_sql := 'SELECT * from pgr_trsp( ' || no_reverse_cost || ', ' || i || ', ' || i || ', ' || flag || ', true)'; - msg := k || ' ' || directed || ', No reverse_cost and saying we use it: from ' || i || ' to ' || i; - BEGIN - execute trsp_sql; - RETURN query SELECT is_empty(trsp_sql, msg || 'is empty'); - EXCEPTION WHEN OTHERS THEN - RETURN query SELECT throws_ok(trsp_sql,'XX000',$$Error, reverse_cost is used, but query did't return 'reverse_cost' column$$); - END; - k := k + 1; - END LOOP; -END IF; END $BODY$ language plpgsql; @@ -175,8 +77,6 @@ language plpgsql; SELECT * from edge_cases(18, true); SELECT * from edge_cases(18, false); - --- Finish the tests and clean up. SELECT * FROM finish(); ROLLBACK; diff --git a/pgtap/trsp/trsp/edge_cases/issue_244.pg b/pgtap/trsp/trsp/edge_cases/issue_244.pg index e6bc445895c..11fb2c07d7f 100644 --- a/pgtap/trsp/trsp/edge_cases/issue_244.pg +++ b/pgtap/trsp/trsp/edge_cases/issue_244.pg @@ -22,44 +22,35 @@ BEGIN; SELECT plan(1); UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; --- should be a procedure CREATE OR REPLACE FUNCTION edge_cases() -RETURNS void AS +RETURNS SETOF TEXT AS $BODY$ BEGIN - IF min_version('3.4.0') THEN - PREPARE q1 AS - SELECT seq, node, edge, cost::text FROM pgr_trsp( - $$SELECT id, source, target, cost FROM edges$$, - $$SELECT * FROM restrictions WHERE id > 10$$, - 7, 12, false); - PREPARE q2 AS - (SELECT seq, node, edge, cost::text - FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by id',7, 12, FALSE)) - UNION - (SELECT seq, node, edge, cost::text - FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by source',7, 12, FALSE)); - - ELSE - - PREPARE q1 AS - SELECT seq, id1, id2, cost::text - FROM pgr_trsp($$SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edges$$, 7, 12, FALSE, false); - PREPARE q2 AS - (SELECT seq-1, node::INTEGER, edge::INTEGER, cost::text - FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by id',7, 12, FALSE)) - UNION ALL - (SELECT seq-1, node::INTEGER, edge::INTEGER, cost::text - FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by source',7, 12, FALSE)); + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_signature added on 3.4.0'); + RETURN; END IF; + + PREPARE q1 AS + SELECT seq, node, edge, cost::text FROM pgr_trsp( + $$SELECT id, source, target, cost FROM edges$$, + $$SELECT * FROM restrictions WHERE id > 10$$, + 7, 12, false); + PREPARE q2 AS + (SELECT seq, node, edge, cost::text + FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by id',7, 12, FALSE)) + UNION + (SELECT seq, node, edge, cost::text + FROM pgr_dijkstra('SELECT id, source, target, cost FROM edges order by source',7, 12, FALSE)); + + RETURN QUERY SELECT set_eq('q2', 'q1', 'path found'); END; $BODY$ LANGUAGE plpgsql; SELECT edge_cases(); -SELECT set_eq('q2', 'q1', 'path found'); SELECT finish(); ROLLBACK; diff --git a/pgtap/trsp/trsp/edge_cases/no_restrictions_compare_withPoints.pg b/pgtap/trsp/trsp/edge_cases/no_restrictions_compare_withPoints.pg deleted file mode 100644 index 523b185fa7e..00000000000 --- a/pgtap/trsp/trsp/edge_cases/no_restrictions_compare_withPoints.pg +++ /dev/null @@ -1,50 +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; - -SELECT plan(1); -UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; -SET client_min_messages TO ERROR; - -PREPARE q1 AS -SELECT seq, id1, id2, cost::TEXT FROM pgr_trsp( - 'select id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges', - 1, -- edge_id for start - 0.5, -- midpoint of edge - 6, -- edge_id of route end - 0.5, -- midpoint of edge - true, -- directed graph? - true, -- has_reverse_cost? - null); -- no turn restrictions - - -PREPARE q2 AS -SELECT seq-1, node::INTEGER, edge::INTEGER, cost::TEXT FROM pgr_withPoints( - $$SELECT id, source, target, cost, reverse_cost from edges$$, - $$(SELECT 1 AS pid, 1 AS edge_id, 0.5::float AS fraction) - UNION - (SELECT 2, 6, 0.5)$$, - -1, -2); - -SELECT set_eq('q2', 'q1', 'No turn restriction from 1 to 5 returns same as pgr_withPoints'); - --- Finish the tests and clean up. -SELECT * FROM finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/inner_query.pg b/pgtap/trsp/trsp/inner_query.pg index 638c7f92ebe..1add728ef76 100644 --- a/pgtap/trsp/trsp/inner_query.pg +++ b/pgtap/trsp/trsp/inner_query.pg @@ -19,9 +19,9 @@ 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 CASE WHEN min_version('3.4.0') THEN plan(540) ELSE plan(324) END; -SET client_min_messages TO ERROR; +UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; +SELECT CASE WHEN min_version('3.4.0') THEN plan(216) ELSE plan(1) END; + CREATE OR REPLACE FUNCTION inner_query() RETURNS SETOF TEXT AS @@ -32,9 +32,12 @@ DECLARE empty_restriction TEXT; BEGIN - IF min_version('3.4.0') THEN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_signature added on 3.4.0'); + RETURN; + END IF; - unrelated_restriction := '$$SELECT 1 AS id, 100::float AS cost, 25::INTEGER AS target_id, ARRAY[33, 32, 25] AS path$$'; + unrelated_restriction := '$$SELECT 1 AS id, 100 AS cost, ARRAY[33, 32, 25] AS path$$'; empty_restriction := '$$SELECT * FROM restrictions WHERE id > 7$$'; RETURN QUERY SELECT style_dijkstra('pgr_trsp(', ', ' || empty_restriction || ', 6, 16, false)'); @@ -43,27 +46,6 @@ BEGIN RETURN QUERY SELECT style_dijkstra('pgr_trsp(', ', ' || unrelated_restriction || ', 6, 16, false)'); RETURN QUERY SELECT style_dijkstra('pgr_trsp(', ', ' || unrelated_restriction || ', 6, 16, true)'); - END IF; - - restriction := '$$SELECT 100::float AS to_cost, 25::INTEGER AS target_id, ''32, 33''::TEXT AS via_path$$)'; - - - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, true)', TRUE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, true, NULL)', TRUE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, true, ' || restriction, TRUE); - - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, true)', TRUE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, true, NULL)', TRUE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, true, ' || restriction, TRUE); - - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, false)', FALSE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, false, NULL)', FALSE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, false, false, ' || restriction, FALSE); - - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, false)', FALSE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, false, NULL)', FALSE); - RETURN QUERY SELECT style_dijkstra_trsp('pgr_trsp', ', 6, 16, true, false, ' || restriction, FALSE); - END; $BODY$ LANGUAGE plpgsql; diff --git a/pgtap/trsp/trsp/no_crash_test/int_flt.pg b/pgtap/trsp/trsp/no_crash_test/int_flt.pg deleted file mode 100644 index e504cd3539a..00000000000 --- a/pgtap/trsp/trsp/no_crash_test/int_flt.pg +++ /dev/null @@ -1,125 +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(32); -SET client_min_messages TO ERROR; - -PREPARE edges AS -SELECT id, source, target, cost, reverse_cost FROM edges; - -PREPARE null_ret AS -SELECT id FROM vertices WHERE id IN (-1); - -SELECT isnt_empty('edges', 'Should not be empty to tests be meaningful'); -SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); - - -CREATE OR REPLACE FUNCTION test(params TEXT[], subs TEXT[]) -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -mp TEXT[]; -q1 TEXT; -q TEXT; -BEGIN - FOR i IN 0..array_length(params, 1) LOOP - mp := params; - IF i != 0 THEN - mp[i] = subs[i]; - END IF; - - q1 := format($$ - SELECT * FROM pgr_trsp( - %1$L, %2$s, %3$s, %4$s, %5$s, %6$s, %7$s - ) - $$, - mp[1], mp[2], mp[3], mp[4], mp[5], mp[6], mp[7] - ); - - - IF i IN (1) THEN - RETURN query SELECT * FROM throws_ok(q1); - ELSE - RETURN query SELECT * FROM lives_ok(q1, 'should live i ' || i); - IF i IN (0,7) THEN - RETURN query SELECT * FROM isnt_empty(q1, 'should not be empty i' || i); - ELSE - RETURN query SELECT * FROM is_empty(q1, 'should be empty i' || i); - END IF; - END IF; - - - END LOOP; - -END -$BODY$ -LANGUAGE plpgsql VOLATILE; - -CREATE OR REPLACE FUNCTION test_function() -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -params TEXT[]; -subs TEXT[]; -BEGIN - params = ARRAY['SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost::FLOAT, reverse_cost::FLOAT FROM edges', - '1', - '0.5::FLOAT', - '2', - '0.5::FLOAT', - 'true', - 'true' - ]::TEXT[]; - subs = ARRAY[ - NULL, - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL', - 'NULL', - 'NULL' - ]::TEXT[]; - - RETURN query SELECT * FROM test(params, subs); - - - subs = ARRAY[ - NULL, - 'NULL', - 'NULL', - 'NULL', - 'NULL', - 'NULL', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM test(params, subs); - - -END -$BODY$ -LANGUAGE plpgsql VOLATILE; - - -SELECT * FROM test_function(); - -SELECT finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/no_crash_test/int_int.pg b/pgtap/trsp/trsp/no_crash_test/int_int.pg deleted file mode 100644 index 228dc824bab..00000000000 --- a/pgtap/trsp/trsp/no_crash_test/int_int.pg +++ /dev/null @@ -1,294 +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; - --- Test for deprecated signature -UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT CASE WHEN min_version('3.4.0') THEN plan(176) ELSE plan(23) END; -SET client_min_messages TO ERROR; - -PREPARE edges AS -SELECT id, source, target, cost, reverse_cost FROM edges; - -PREPARE null_ret AS -SELECT id FROM vertices WHERE id IN (-1); - -CREATE OR REPLACE FUNCTION test(params TEXT[], subs TEXT[]) -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -mp TEXT[]; -q1 TEXT; -q TEXT; -BEGIN - FOR i IN 0..array_length(params, 1) LOOP - mp := params; - IF i != 0 THEN - mp[i] = subs[i]; - END IF; - - q1 := format($$ - SELECT * FROM pgr_trsp( - %1$L, %2$s, %3$s, %4$s, %5$s - ) - $$, - mp[1], mp[2], mp[3], mp[4], mp[5] - ); - - if i IN (1) THEN - RETURN query SELECT * FROM throws_ok(q1); - ELSE - RETURN query SELECT * FROM lives_ok(q1, 'should live i ' || i); - IF i IN (0,5) THEN - RETURN query SELECT * FROM isnt_empty(q1, 'should not be empty i' || i); - ELSE - RETURN query SELECT * FROM is_empty(q1, 'should be empty i' || i); - END IF; - END IF; - END LOOP; - -END -$BODY$ -LANGUAGE plpgsql VOLATILE; - -CREATE OR REPLACE FUNCTION test_function() -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -params TEXT[]; -subs TEXT[]; -BEGIN - IF min_version('3.4.0') THEN - - -- ONE TO ONE - RETURN QUERY SELECT isnt_empty('edges', 'Should not be empty to tests be meaningful'); - RETURN QUERY SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); - - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT * FROM restrictions$$', - '5', - '6', - 'true' - ]::TEXT[]; - subs = ARRAY[ - 'NULL::TEXT', - 'NULL::TEXT', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL' - ]::TEXT[]; - - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - subs = ARRAY[ - 'NULL::TEXT', - 'NULL', - 'NULL::BIGINT', - 'NULL::BIGINT', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - params = ARRAY[ - '$$edges$$', - '$$SELECT * FROM restrictions$$', - '5', - '6', - 'true' - ]::TEXT[]; - RETURN query SELECT no_crash_test('pgr_trsp', params, subs); - - -- ONE TO MANY - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT * FROM restrictions$$', - '5', - 'ARRAY[6,10]::BIGINT[]', - 'true' - ]::TEXT[]; - subs = ARRAY[ - 'NULL::TEXT', - 'NULL::TEXT', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL::BIGINT[]', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - subs = ARRAY[ - 'NULL::TEXT', - 'NULL', - 'NULL::BIGINT', - 'NULL::BIGINT[]', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - params = ARRAY[ - '$$edges$$', - '$$SELECT * FROM restrictions$$', - '5', - 'ARRAY[6,10]::BIGINT[]', - 'true' - ]::TEXT[]; - RETURN query SELECT no_crash_test('pgr_trsp', params, subs); - - -- MANY TO ONE - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT * FROM restrictions$$', - 'ARRAY[6,10]::BIGINT[]', - '5', - 'true' - ]::TEXT[]; - subs = ARRAY[ - 'NULL::TEXT', - 'NULL::TEXT', - 'NULL::BIGINT[]', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - subs = ARRAY[ - 'NULL::TEXT', - 'NULL', - 'NULL::BIGINT[]', - 'NULL::BIGINT', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - params = ARRAY[ - '$$edges$$', - '$$SELECT * FROM restrictions$$', - 'ARRAY[6,10]::BIGINT[]', - '5', - 'true' - ]::TEXT[]; - RETURN query SELECT no_crash_test('pgr_trsp', params, subs); - - -- MANY TO MANY - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT * FROM restrictions$$', - 'ARRAY[6,10]::BIGINT[]', - 'ARRAY[5,7]::BIGINT[]', - 'true' - ]::TEXT[]; - subs = ARRAY[ - 'NULL::TEXT', - 'NULL::TEXT', - 'NULL::BIGINT[]', - 'NULL::BIGINT[]', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - subs = ARRAY[ - 'NULL::TEXT', - 'NULL', - 'NULL::BIGINT[]', - 'NULL::BIGINT[]', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - params = ARRAY[ - '$$edges$$', - '$$SELECT * FROM restrictions$$', - 'ARRAY[6,10]::BIGINT[]', - 'ARRAY[5,7]::BIGINT[]', - 'true' - ]::TEXT[]; - RETURN query SELECT no_crash_test('pgr_trsp', params, subs); - - -- COMBINATIONS - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT * FROM restrictions$$', - '$$SELECT * FROM (VALUES (6,5), (6,8),(10,5),(10,8)) AS t(source, target)$$', - 'true' - ]::TEXT[]; - subs = ARRAY[ - 'NULL::TEXT', - 'NULL::TEXT', - 'NULL::TEXT', - 'NULL::BOOLEAN' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - subs = ARRAY[ - 'NULL::TEXT', - 'NULL', - 'NULL', - 'NULL::BOOLEAN' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_trsp', params, subs); - - params = ARRAY[ - '$$edges$$', - '$$SELECT * FROM restrictions$$', - '$$SELECT * FROM (VALUES (6,5), (6,8),(10,5),(10,8)) AS t(source, target)$$', - 'true' - ]::TEXT[]; - RETURN query SELECT no_crash_test('pgr_trsp', params, subs); - - ELSE - - params = ARRAY['SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost::FLOAT, reverse_cost::FLOAT FROM edges', - '5', - '6', - 'true', - 'true' - ]::TEXT[]; - subs = ARRAY[ - NULL, - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - '(SELECT id::INTEGER FROM vertices WHERE id IN (-1))', - 'NULL', - 'NULL' - ]::TEXT[]; - - RETURN query SELECT test(params, subs); - - subs = ARRAY[ - NULL, - 'NULL', - 'NULL', - 'NULL', - 'NULL' - ]::TEXT[]; - RETURN query SELECT test(params, subs); - - RETURN QUERY SELECT skip(1, 'pgr_trsp Has some crashes'); - - END IF; - -END -$BODY$ -LANGUAGE plpgsql VOLATILE; - - -SELECT * FROM test_function(); - -SELECT finish(); -ROLLBACK; diff --git a/pgtap/trsp/trsp/types_check.pg b/pgtap/trsp/trsp/types_check.pg index 4e6629ac42a..8cc32c3e1f0 100644 --- a/pgtap/trsp/trsp/types_check.pg +++ b/pgtap/trsp/trsp/types_check.pg @@ -20,31 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; -SELECT CASE WHEN min_version('3.4.0') THEN plan(20) ELSE plan(8) END; +SELECT CASE WHEN min_version('3.4.0') THEN plan(14) ELSE plan(2) END; SELECT has_function('pgr_trsp'); -SELECT has_function('pgr_trsp', ARRAY['text','integer','integer','boolean','boolean','text']); -SELECT has_function('pgr_trsp', ARRAY['text','integer','double precision','integer','double precision','boolean','boolean','text']); - -SELECT function_returns('pgr_trsp', ARRAY['text','integer','integer','boolean','boolean','text'],'setof record'); -SELECT function_returns('pgr_trsp', ARRAY['text','integer','double precision','integer','double precision','boolean','boolean','text'],'setof record'); - -SELECT bag_has( - $$SELECT proargnames from pg_proc where proname = 'pgr_trsp'$$, - $$VALUES - ('{"","","","","","restrictions_sql","seq","id1","id2","cost"}'::TEXT[]), - ('{"","","","","","","","turn_restrict_sql","seq","id1","id2","cost"}'::TEXT[]) - $$, 'old signature names'); - -SELECT bag_has( - $$SELECT proallargtypes from pg_proc where proname = 'pgr_trsp'$$, - $$VALUES - ('{25,23,23,16,16,25,23,23,23,701}'::OID[]), - ('{25,23,701,23,701,16,16,25,23,23,23,701}'::OID[]) - $$, 'old signature types'); - - SELECT types_check_general('pgr_trsp'); SELECT finish(); diff --git a/sql/sigs/pgrouting--4.0.sig b/sql/sigs/pgrouting--4.0.sig index 8573079813c..1b15732c3dc 100644 --- a/sql/sigs/pgrouting--4.0.sig +++ b/sql/sigs/pgrouting--4.0.sig @@ -270,16 +270,9 @@ _pgr_topologicalsort(text) pgr_topologicalsort(text) _pgr_transitiveclosure(text) pgr_transitiveclosure(text) -_pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) -pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) -pgr_trsp(text,integer,integer,boolean,boolean,text) -_pgr_trsp(text,text,anyarray,anyarray,boolean) pgr_trsp(text,text,anyarray,anyarray,boolean) -_pgr_trsp(text,text,anyarray,bigint,boolean) pgr_trsp(text,text,anyarray,bigint,boolean) -_pgr_trsp(text,text,bigint,anyarray,boolean) pgr_trsp(text,text,bigint,anyarray,boolean) -_pgr_trsp(text,text,bigint,bigint,boolean) pgr_trsp(text,text,bigint,bigint,boolean) pgr_trsp(text,text,text,boolean) _pgr_trspv4(text,text,anyarray,anyarray,boolean) @@ -336,6 +329,3 @@ _pgr_withpoints(text,text,text,boolean,character,boolean,boolean) _pgr_withpointsvia(text,bigint[],double precision[],boolean) _pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean) pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean) -_trsp(text,text,anyarray,anyarray,boolean) -_v4trsp(text,text,anyarray,anyarray,boolean) -_v4trsp(text,text,text,boolean) diff --git a/sql/trsp/CMakeLists.txt b/sql/trsp/CMakeLists.txt index 8b305483b08..42a1b61871b 100644 --- a/sql/trsp/CMakeLists.txt +++ b/sql/trsp/CMakeLists.txt @@ -2,9 +2,7 @@ SET(LOCAL_FILES _trsp.sql trsp.sql - _trsp_deprecated.sql _array_reverse.sql - trsp_deprecated.sql trsp_withPoints.sql _trsp_withPoints.sql diff --git a/sql/trsp/_trsp.sql b/sql/trsp/_trsp.sql index 4bafa32838b..980a8aa4ae4 100644 --- a/sql/trsp/_trsp.sql +++ b/sql/trsp/_trsp.sql @@ -24,17 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ --------------- --------------- --- trsp --------------- --------------- - - --------------- --- _trsp --------------- - --v3.6 CREATE FUNCTION _pgr_trspv4( TEXT, -- edges SQL @@ -80,77 +69,3 @@ IS 'pgRouting internal function'; COMMENT ON FUNCTION _pgr_trspv4(TEXT, TEXT, TEXT, BOOLEAN) IS 'pgRouting internal function'; ---v2.6 -CREATE FUNCTION _trsp( - TEXT, -- edges SQL - TEXT, -- restrictions SQL - ANYARRAY, - ANYARRAY, - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) -RETURNS SETOF RECORD AS -'MODULE_PATHNAME' -LANGUAGE 'c' VOLATILE; - ---v3.4 -CREATE FUNCTION _v4trsp( - TEXT, -- edges SQL - TEXT, -- restrictions SQL - ANYARRAY, - ANYARRAY, - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) -RETURNS SETOF RECORD AS -$BODY$ - SELECT seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_trspv4( $1, $2, $3, $4, $5); -$BODY$ -LANGUAGE SQL VOLATILE STRICT; - ---v3.4 -CREATE FUNCTION _v4trsp( - TEXT, -- edges SQL - TEXT, -- restrictions SQL - TEXT, -- combinations SQL - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) -RETURNS SETOF RECORD AS -$BODY$ - SELECT seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_trspv4( $1, $2, $3, $4); -$BODY$ -LANGUAGE SQL VOLATILE STRICT; - --- COMMENTS -COMMENT ON FUNCTION _trsp(TEXT, TEXT, ANYARRAY, ANYARRAY, BOOLEAN) -IS 'pgRouting internal function deprecated on v3.4.0'; - -COMMENT ON FUNCTION _v4trsp(TEXT, TEXT, ANYARRAY, ANYARRAY, BOOLEAN) -IS 'pgRouting internal function deprecated on v3.6.0'; - -COMMENT ON FUNCTION _v4trsp(TEXT, TEXT, TEXT, BOOLEAN) -IS 'pgRouting internal function deprecated on v3.6.0'; diff --git a/sql/trsp/_trsp_deprecated.sql b/sql/trsp/_trsp_deprecated.sql deleted file mode 100644 index fd81e5e3828..00000000000 --- a/sql/trsp/_trsp_deprecated.sql +++ /dev/null @@ -1,53 +0,0 @@ -/*PGR-GNU***************************************************************** -File: _trsp_deprecated.sql - -Copyright (c) 2015 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*/ --------------- --- _pgr_trsp --------------- - - ---v2.6 -CREATE FUNCTION _pgr_trsp( - sql text, - source_eid integer, - source_pos float8, - target_eid integer, - target_pos float8, - directed boolean, - has_reverse_cost boolean, - turn_restrict_sql text DEFAULT null, - - OUT seq INTEGER, - OUT id1 INTEGER, - OUT id2 INTEGER, - OUT cost FLOAT -) -RETURNS SETOF record -AS 'MODULE_PATHNAME' -LANGUAGE 'c' IMMUTABLE; - --- COMMENTS - - -COMMENT ON FUNCTION _pgr_trsp(TEXT, INTEGER, FLOAT, INTEGER, FLOAT, BOOLEAN, BOOLEAN, TEXT) -IS 'pgRouting internal function deprecated on v3.4.0'; diff --git a/sql/trsp/trsp.sql b/sql/trsp/trsp.sql index 80ced402021..bea963e3777 100644 --- a/sql/trsp/trsp.sql +++ b/sql/trsp/trsp.sql @@ -257,140 +257,3 @@ IS 'pgr_trsp(combinations) - Documentation: - ${PROJECT_DOC_LINK}/pgr_trsp.html '; - - --- ONE to ONE ---v2.6 -CREATE FUNCTION _pgr_trsp( - TEXT, -- edges_sql - TEXT, -- restrictions_sql - BIGINT, -- start_vid - BIGINT, -- end_vid - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) - -RETURNS SETOF RECORD AS -$BODY$ - SELECT a.seq, a.path_seq, a.node, a.edge, a.cost, a.agg_cost - FROM _trsp( - _pgr_get_statement($1), - _pgr_get_statement($2), - ARRAY[$3]::BIGINT[], - ARRAY[$4]::BIGINT[], - directed) AS a; -$BODY$ -LANGUAGE sql VOLATILE STRICT -COST 100 -ROWS 1000; - - --- ONE to MANY ---v2.6 -CREATE FUNCTION _pgr_trsp( - TEXT, -- edges_sql - TEXT, -- restrictions_sql - BIGINT, -- start_vid - ANYARRAY, -- end_vids - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) - -RETURNS SETOF RECORD AS -$BODY$ - SELECT a.seq, a.path_seq, a.end_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _trsp( - _pgr_get_statement($1), - _pgr_get_statement($2), - ARRAY[$3]::BIGINT[], - $4::bigint[], - directed) AS a; -$BODY$ -LANGUAGE sql VOLATILE STRICT -COST 100 -ROWS 1000; - - --- MANY to ONE ---v2.6 -CREATE FUNCTION _pgr_trsp( - TEXT, -- edges_sql - TEXT, -- restrictions_sql - ANYARRAY, -- start_vids - BIGINT, -- end_vid - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT start_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) - -RETURNS SETOF RECORD AS -$BODY$ - SELECT a.seq, a.path_seq, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _trsp( - _pgr_get_statement($1), - _pgr_get_statement($2), - $3::bigint[], - ARRAY[$4]::BIGINT[], - $5) AS a; -$BODY$ -LANGUAGE sql VOLATILE STRICT -COST 100 -ROWS 1000; - - --- MANY to MANY ---v2.6 -CREATE FUNCTION _pgr_trsp( - TEXT, -- edges_sql - TEXT, -- restrictions_sql - ANYARRAY, -- start_vids - ANYARRAY, -- end_vids - directed BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) - -RETURNS SETOF RECORD AS -$BODY$ - SELECT a.seq, a.path_seq, a.start_vid, a.end_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _trsp( - _pgr_get_statement($1), - _pgr_get_statement($2), - $3::bigint[], - $4::bigint[], - $5) AS a; -$BODY$ -LANGUAGE sql VOLATILE STRICT -COST 100 -ROWS 1000; - - --- COMMENTS - -COMMENT ON FUNCTION _pgr_trsp(TEXT, TEXT, BIGINT, BIGINT, BOOLEAN) IS 'pgRouting internal function deprecated on v3.4.0'; -COMMENT ON FUNCTION _pgr_trsp(TEXT, TEXT, BIGINT, ANYARRAY, BOOLEAN) IS 'pgRouting internal function deprecated on v3.4.0'; -COMMENT ON FUNCTION _pgr_trsp(TEXT, TEXT, ANYARRAY, BIGINT, BOOLEAN) IS 'pgRouting internal function deprecated on v3.4.0'; -COMMENT ON FUNCTION _pgr_trsp(TEXT, TEXT, ANYARRAY, ANYARRAY, BOOLEAN) IS 'pgRouting internal function deprecated on v3.4.0'; - diff --git a/sql/trsp/trsp_deprecated.sql b/sql/trsp/trsp_deprecated.sql deleted file mode 100644 index 011b9373345..00000000000 --- a/sql/trsp/trsp_deprecated.sql +++ /dev/null @@ -1,271 +0,0 @@ -/*PGR-GNU***************************************************************** -File: trsp_deprecated.sql - -Copyright (c) 2015 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*/ -/* pgr_trsp VERTEX - - - if size of restrictions_sql is Zero or no restrictions_sql are given - then call to pgr_dijkstra is made - - - because it reads the data wrong, when there is a reverse_cost column: - - put all data costs in one cost column and - - a call is made to trsp without only the positive values -*/ ---v3.0 -CREATE FUNCTION pgr_trsp( - TEXT, -- edges SQL (required) - INTEGER, -- from_vid (required) - INTEGER, -- to_vid (required) - BOOLEAN, -- directed (required) - BOOLEAN, -- has_rcost (required) - - restrictions_sql TEXT DEFAULT NULL, - - OUT seq INTEGER, - OUT id1 INTEGER, - OUT id2 INTEGER, - OUT cost FLOAT -) -RETURNS SETOF record AS -$BODY$ -DECLARE - edges_sql TEXT := $1; - start_vid INTEGER := $2; - end_vid INTEGER := $3; - directed BOOLEAN := $4; - has_rcost BOOLEAN := $5; - -has_reverse BOOLEAN; -new_sql TEXT; -restrictions_query TEXT; -trsp_sql TEXT; -BEGIN - RAISE WARNING 'pgr_trsp(text,integer,integer,boolean,boolean) deprecated signature on v3.4.0'; - has_reverse =_pgr_parameter_check('dijkstra', edges_sql, false); - - new_sql := edges_sql; - IF (has_reverse != has_rcost) THEN -- user contradiction - IF (has_reverse) THEN -- it has reverse_cost but user don't want it. - -- to be on the safe side because it reads the data wrong, sending only postitive values - new_sql := - 'WITH old_sql AS (' || edges_sql || ')' || - ' SELECT id, source, target, cost FROM old_sql'; - ELSE -- it does not have reverse_cost but user wants it - RAISE EXCEPTION 'Error, reverse_cost is used, but query did''t return ''reverse_cost'' column' - USING ERRCODE := 'XX000'; - END IF; - END IF; - - IF (restrictions_sql IS NULL OR length(restrictions_sql) = 0) THEN - -- no restrictions then its a dijkstra - RETURN query SELECT a.seq - 1 AS seq, node::INTEGER AS id1, edge::INTEGER AS id2, a.cost - FROM pgr_dijkstra(new_sql, start_vid, end_vid, directed) a; - RETURN; - END IF; - - - restrictions_query = $$ - WITH old_restrictions AS ( $$ || - $6 || $$ - ) - SELECT ROW_NUMBER() OVER() AS id, - _pgr_array_reverse(array_prepend(target_id, string_to_array(via_path::text, ',')::INTEGER[])) AS path, - to_cost AS cost - FROM old_restrictions; - $$; - - - - RETURN query - SELECT (a.seq - 1)::INTEGER, a.node::INTEGER, a.edge::INTEGER, a.cost - FROM _pgr_trsp(new_sql, restrictions_query, start_vid, end_vid, directed) AS a; - IF NOT FOUND THEN - RAISE EXCEPTION 'Error computing path: Path Not Found'; - END IF; - -END -$BODY$ -LANGUAGE plpgsql VOLATILE -COST 100 -ROWS 1000; - - -/* - Wrapper change on v2.6 - - without restrictions - - call pgr_dijkstra when both end points have a fraction IN (0,1) - - call pgr_withPoints when at least one fraction NOT IN (0,1) - - - with restrictions - - calls original trsp code -*/ ---v3.0 -CREATE FUNCTION pgr_trsp( - TEXT, -- sql (required) - INTEGER, -- source_eid (required) - FLOAT, -- source_pos (required) - INTEGER, -- target_eid (required) - FLOAT, -- target_pos (required) - BOOLEAN, -- directed (required) - BOOLEAN, -- has_reverse_cost (required) - - turn_restrict_sql text DEFAULT null, - - OUT seq INTEGER, - OUT id1 INTEGER, - OUT id2 INTEGER, - OUT cost FLOAT -) -RETURNS SETOF record AS -$BODY$ -DECLARE - sql TEXT := $1; - source_eid INTEGER := $2; - source_pos FLOAT := $3; - target_eid INTEGER := $4; - target_pos FLOAT := $5; - directed BOOLEAN := $6; - has_reverse_cost BOOLEAN := $7; - -has_reverse BOOLEAN; -new_sql TEXT; -trsp_sql TEXT; -source_sql TEXT; -target_sql TEXT; -union_sql TEXT; -union_sql1 TEXT; -union_sql2 TEXT; -final_sql TEXT; - -BEGIN - IF $2 IS NULL OR $3 IS NULL OR $4 IS NULL OR $5 IS NULL OR $6 IS NULL THEN - RETURN; - END IF; - RAISE WARNING 'pgr_trsp(text,integer,float,integer,float,boolean,boolean) deprecated signature on v3.4.0'; - has_reverse =_pgr_parameter_check('dijkstra', sql, false); - - new_sql := sql; - IF (has_reverse != has_reverse_cost) THEN -- user contradiction - IF (has_reverse) THEN - -- it has reverse_cost but user don't want it. - -- to be on the safe side because it reads the data wrong, sending only postitive values - new_sql := - 'WITH old_sql AS (' || sql || ')' || - ' SELECT id, source, target, cost FROM old_sql'; - ELSE -- it does not have reverse_cost but user wants it - RAISE EXCEPTION 'Error, reverse_cost is used, but query did''t return ''reverse_cost'' column' - USING ERRCODE := 'XX000'; - END IF; - END IF; - - IF (turn_restrict_sql IS NULL OR length(turn_restrict_sql) = 0) THEN - -- no restrictions then its a withPoints or dijkstra - IF source_pos = 0 THEN - source_sql = '(SELECT source FROM (' || sql || ') b WHERE id = ' || source_eid || ')'; - ELSE IF source_pos = 1 THEN - source_sql = '(SELECT target FROM (' || sql || ') b WHERE id = ' || source_eid || ')'; - ELSE - source_sql = '-1'; - union_sql1 = '(SELECT 1 as pid, ' || source_eid || ' as edge_id, ' || source_pos || '::float8 as fraction)'; - END IF; - END IF; - -- raise notice 'source_sql %', source_sql; - -- raise notice 'union_sql1 %', union_sql1; - - - IF target_pos = 0 THEN - target_sql = '(SELECT source FROM (' || sql || ') c WHERE id = ' || target_eid || ')'; - ELSE IF target_pos = 1 THEN - target_sql = '(SELECT target FROM (' || sql || ') c WHERE id = ' || target_eid || ')'; - ELSE - target_sql = '-2'; - union_sql2 = ' (SELECT 2 as pid, ' || target_eid || ' as edge_id, ' || target_pos || '::float8 as fraction)'; - END IF; - END IF; - - -- raise notice 'target_sql %', target_sql; - -- raise notice 'union_sql2 %', union_sql2; - - IF union_sql1 IS NOT NULL AND union_sql2 IS NOT NULL THEN - union_sql = union_sql1 || ' UNION ' || union_sql2; - ELSE IF union_sql1 IS NOT NULL AND union_sql2 IS NULL THEN - union_sql = union_sql1; - ELSE IF union_sql1 IS NULL AND union_sql2 IS NOT NULL THEN - union_sql = union_sql2; - END IF; - END IF; - END IF; - - IF union_sql IS NULL THEN - -- no points then its a dijkstra - final_sql = 'WITH final_sql AS ( - SELECT a.seq-1 AS seq, node::INTEGER AS id1, edge::INTEGER AS id2, cost FROM pgr_dijkstra($$' || new_sql || '$$ - ,' || source_sql || ' - ,' || target_sql || ' - , directed := ' || directed || ' - ) a ) - SELECT seq, id1, id2, cost FROM final_sql ORDER BY seq'; - ELSE - -- points then its a withPoints - final_sql = 'WITH final_sql AS ( - SELECT a.seq-1 AS seq, node::INTEGER AS id1, edge::INTEGER AS id2, cost FROM pgr_withpoints($$' || new_sql || '$$ - , $$' || union_sql || '$$ - ,' || source_sql || ' - ,' || target_sql || ' - , directed := ' || directed || ' - ) a ) - SELECT seq, CASE WHEN seq = 0 AND ' || source_pos || '=0 THEN id1 - WHEN seq = 0 AND ' || source_pos || '!=0 THEN -1 - WHEN id2 = -1 AND ' || target_pos || '=0 THEN id1 - WHEN id2 = -1 AND ' || target_pos || '!=0 THEN id1 - ELSE id1 END AS id1, id2, cost FROM final_sql ORDER BY seq'; - END IF; - - - -- raise notice 'final_sql %', final_sql; - RETURN QUERY EXECUTE final_sql; - RETURN; - - END IF; - - -- with restrictions calls the original code - RETURN query - SELECT a.seq, a.id1, a.id2, a.cost - FROM _pgr_trsp(new_sql, source_eid, source_pos, target_eid, target_pos, directed, has_reverse_cost, turn_restrict_sql) AS a; - RETURN; - -END -$BODY$ -LANGUAGE plpgsql VOLATILE -COST 100 -ROWS 1000; - --- COMMENTS - -COMMENT ON FUNCTION pgr_trsp(TEXT, INTEGER, INTEGER, BOOLEAN, BOOLEAN, TEXT) -IS 'pgr_trsp deprecated signature on v3.4.0 -- Documentation: ${PROJECT_DOC_LINK}/pgr_trsp.html'; - - -COMMENT ON FUNCTION pgr_trsp(TEXT, INTEGER, FLOAT, INTEGER, FLOAT, BOOLEAN, BOOLEAN, TEXT) -IS 'pgr_trsp deprecated signature on v3.4.0 -- Documentation: ${PROJECT_DOC_LINK}/pgr_trsp_withPoints.html'; diff --git a/src/legacy/CMakeLists.txt b/src/legacy/CMakeLists.txt new file mode 100644 index 00000000000..bf5805b4fb7 --- /dev/null +++ b/src/legacy/CMakeLists.txt @@ -0,0 +1,3 @@ +ADD_LIBRARY(legacy OBJECT + legacy.c +) diff --git a/src/legacy/legacy.c b/src/legacy/legacy.c new file mode 100644 index 00000000000..452da3e011e --- /dev/null +++ b/src/legacy/legacy.c @@ -0,0 +1,57 @@ +/*PGR-GNU***************************************************************** +File: legacy.c + +Copyright (c) 2017 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2018-2020 Regina Obe +------ + +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*/ + +/****************************************************************************** + * This file is to hold functions we no longer use, + * but we need to keep because they were used at one time behind SQL API functions. + * This is to ease pg_upgrade upgrades + * + * All functions in this file should throw an error telling the user to upgrade + * the install + * + *****************************************************************************/ + +#include "postgres.h" +#include "utils/builtins.h" + +#define PGROUTING_DEPRECATE(version, funcname) \ + Datum funcname(PG_FUNCTION_ARGS); \ + PG_FUNCTION_INFO_V1(funcname); \ + Datum funcname(__attribute__((unused)) PG_FUNCTION_ARGS) \ + { \ + ereport(ERROR, (\ + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \ + errmsg("A stored procedure tried to use deprecated C internal function '%s'", \ + __func__), \ + errdetail("Library function '%s' was deprecated in pgRouting %s", \ + __func__, version), \ + errhint("Consider upgrade pgRouting"))); \ + PG_RETURN_POINTER(NULL); \ + } + +PGROUTING_DEPRECATE("4.0.0", _pgr_trsp) +PGROUTING_DEPRECATE("4.0.0", _v4trsp) +PGROUTING_DEPRECATE("4.0.0", _trsp) + diff --git a/src/trsp/CMakeLists.txt b/src/trsp/CMakeLists.txt index 981520e675e..10e32d46616 100644 --- a/src/trsp/CMakeLists.txt +++ b/src/trsp/CMakeLists.txt @@ -1,8 +1,5 @@ add_library(trsp OBJECT # keeping these for backwards compatibility - trsp_deprecated.c - trsp_deprecated_driver.cpp - GraphDefinition.cpp edgeInfo.cpp trspHandler.cpp diff --git a/src/trsp/GraphDefinition.cpp b/src/trsp/GraphDefinition.cpp deleted file mode 100644 index 8c3847ac3e7..00000000000 --- a/src/trsp/GraphDefinition.cpp +++ /dev/null @@ -1,663 +0,0 @@ -/*PGR-GNU***************************************************************** -File: GraphDefinition.cpp - -Copyright (c) 2015 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*/ - -#include "trsp/GraphDefinition.hpp" - -#include -#include -#include -#include - -#include "c_types/edge_rt.h" - -// ------------------------------------------------------------------------- -GraphDefinition::GraphDefinition(void) { - m_lStartEdgeId = -1; - m_lEndEdgeId = 0; - m_dStartpart = 0.0; - m_dEndPart = 0.0; - m_dCost = NULL; - m_bIsturnRestrictOn = false; - m_bIsGraphConstructed = false; - parent = NULL; - init(); -} - -// ------------------------------------------------------------------------- -GraphDefinition::~GraphDefinition(void) { -} - - -// ------------------------------------------------------------------------- -void GraphDefinition::init() { - max_edge_id = 0; - max_node_id = 0; - isStartVirtual = false; - isEndVirtual = false; -} - - -// ------------------------------------------------------------------------- -void GraphDefinition::deleteall() { - std::vector::iterator it; - for (it = m_vecEdgeVector.begin(); it != m_vecEdgeVector.end(); ++it) { - delete *it; - } - m_vecEdgeVector.clear(); - - delete [] parent; - delete [] m_dCost; -} - - -// ------------------------------------------------------------------------- -double GraphDefinition::construct_path(int64 ed_id, int64 v_pos) { - if (parent[ed_id].ed_ind[v_pos] == -1) { - path_element_tt pelement; - GraphEdgeInfo* cur_edge = m_vecEdgeVector[static_cast(ed_id)]; - if (v_pos == 0) { - pelement.vertex_id = cur_edge->m_lStartNode; - pelement.cost = cur_edge->m_dCost; - } else { - pelement.vertex_id = cur_edge->m_lEndNode; - pelement.cost = cur_edge->m_dReverseCost; - } - pelement.edge_id = cur_edge->m_lEdgeID; - - m_vecPath.push_back(pelement); - return pelement.cost; - } - double ret = construct_path(parent[ed_id].ed_ind[v_pos], - parent[ed_id].v_pos[v_pos]); - path_element_tt pelement; - GraphEdgeInfo* cur_edge = m_vecEdgeVector[static_cast(ed_id)]; - if (v_pos == 0) { - pelement.vertex_id = cur_edge->m_lStartNode; - pelement.cost = m_dCost[ed_id].endCost - ret; // cur_edge.m_dCost; - ret = m_dCost[ed_id].endCost; - } else { - pelement.vertex_id = cur_edge->m_lEndNode; - pelement.cost = m_dCost[ed_id].startCost - ret; - ret = m_dCost[ed_id].startCost; - } - pelement.edge_id = cur_edge->m_lEdgeID; - - m_vecPath.push_back(pelement); - - return ret; -} - - -// ------------------------------------------------------------------------- -double GraphDefinition::getRestrictionCost( - int64 edge_ind, - GraphEdgeInfo& new_edge, - bool isStart) { - double cost = 0.0; - int64 edge_id = new_edge.m_lEdgeID; - if (m_ruleTable.find(edge_id) == m_ruleTable.end()) { - return(0.0); - } - std::vector vecRules = m_ruleTable[edge_id]; - int64 st_edge_ind = edge_ind; - for (const auto &rule : vecRules) { - bool flag = true; - int64 v_pos = (isStart?0:1); - edge_ind = st_edge_ind; - for (auto const &precedence : rule.precedencelist) { - if (edge_ind == -1) { - flag = false; - break; - } - if (precedence != m_vecEdgeVector[static_cast(edge_ind)]->m_lEdgeID) { - flag = false; - break; - } - auto parent_ind = parent[static_cast(edge_ind)].ed_ind[static_cast(v_pos)]; - v_pos = parent[edge_ind].v_pos[v_pos]; - edge_ind = parent_ind; - } - if (flag) - cost += rule.cost; - } - return cost; -} - - -// ------------------------------------------------------------------------- -void GraphDefinition::explore( - int64 cur_node, - GraphEdgeInfo& cur_edge, - bool isStart, - LongVector &vecIndex, - std::priority_queue, - std::greater > &que) { - double totalCost; - for (const auto &index : vecIndex) { - auto new_edge = m_vecEdgeVector[static_cast(index)]; - double extCost = 0.0; - if (m_bIsturnRestrictOn) { - extCost = getRestrictionCost(cur_edge.m_lEdgeIndex, - *new_edge, isStart); - } - if (new_edge->m_lStartNode == cur_node) { - if (new_edge->m_dCost >= 0.0) { - if (isStart) - totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + - new_edge->m_dCost + extCost; - else - totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + - new_edge->m_dCost + extCost; - if (totalCost < m_dCost[index].endCost) { - m_dCost[index].endCost = totalCost; - parent[new_edge->m_lEdgeIndex].v_pos[0] = (isStart?0:1); - parent[new_edge->m_lEdgeIndex].ed_ind[0] = - cur_edge.m_lEdgeIndex; - que.push(std::make_pair(totalCost, - std::make_pair(new_edge->m_lEdgeIndex, true))); - } - } - } else { - if (new_edge->m_dReverseCost >= 0.0) { - if (isStart) - totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + - new_edge->m_dReverseCost + extCost; - else - totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + - new_edge->m_dReverseCost + extCost; - if (totalCost < m_dCost[index].startCost) { - m_dCost[index].startCost = totalCost; - parent[new_edge->m_lEdgeIndex].v_pos[1] = (isStart?0:1); - parent[new_edge->m_lEdgeIndex].ed_ind[1] = - cur_edge.m_lEdgeIndex; - que.push(std::make_pair(totalCost, - std::make_pair(new_edge->m_lEdgeIndex, false))); - } - } - } - } -} - - - - -// ------------------------------------------------------------------------- -int GraphDefinition::my_dijkstra1( - Edge_t *edges, size_t edge_count, - int64 start_edge_id, double start_part, - int64 end_edge_id, double end_part, - bool directed, bool has_reverse_cost, - - path_element_tt **path, - size_t *path_count, - char **err_msg, - std::vector &ruleList) { - if (!m_bIsGraphConstructed) { - init(); - construct_graph(edges, edge_count, has_reverse_cost, directed); - m_bIsGraphConstructed = true; - } - GraphEdgeInfo* start_edge_info = - m_vecEdgeVector[static_cast(m_mapEdgeId2Index[static_cast(start_edge_id)])]; - Edge_t start_edge; - int64 start_vertex, end_vertex; - m_dStartpart = start_part; - m_dEndPart = end_part; - m_lStartEdgeId = start_edge_id; - m_lEndEdgeId = end_edge_id; - - if (start_part == 0.0) { - start_vertex = start_edge_info->m_lStartNode; - } else if (start_part == 1.0) { - start_vertex = start_edge_info->m_lEndNode; - } else { - isStartVirtual = true; - m_lStartEdgeId = start_edge_id; - start_vertex = max_node_id + 1; - max_node_id++; - start_edge.id = max_edge_id + 1; - max_edge_id++; - start_edge.source = start_vertex; - start_edge.reverse_cost = -1.0; - if (start_edge_info->m_dCost >= 0.0) { - start_edge.target = start_edge_info->m_lEndNode; - start_edge.cost = (1.0 - start_part) * start_edge_info->m_dCost; - addEdge(start_edge); - edge_count++; - } - if (start_edge_info->m_dReverseCost >= 0.0) { - start_edge.id = max_edge_id + 1; - max_edge_id++; - start_edge.target = start_edge_info->m_lStartNode; - start_edge.cost = start_part * start_edge_info->m_dReverseCost; - addEdge(start_edge); - edge_count++; - } - } - - GraphEdgeInfo* end_edge_info = - m_vecEdgeVector[static_cast(m_mapEdgeId2Index[static_cast(end_edge_id)])]; - Edge_t end_edge; - - if (end_part == 0.0) { - end_vertex = end_edge_info->m_lStartNode; - } else if (end_part == 1.0) { - end_vertex = end_edge_info->m_lEndNode; - } else { - isEndVirtual = true; - m_lEndEdgeId = end_edge_id; - end_vertex = max_node_id + 1; - max_node_id++; - end_edge.id = max_edge_id + 1; - max_edge_id++; - end_edge.target = end_vertex; - end_edge.reverse_cost = -1.0; - if (end_edge_info->m_dCost >= 0.0) { - end_edge.source = end_edge_info->m_lStartNode; - end_edge.cost = end_part * end_edge_info->m_dCost; - addEdge(end_edge); - edge_count++; - } - if (end_edge_info->m_dReverseCost >= 0.0) { - end_edge.source = end_edge_info->m_lEndNode; - end_edge.id = max_edge_id + 1; - end_edge.cost = (1.0 - end_part) * end_edge_info->m_dReverseCost; - addEdge(end_edge); - edge_count++; - } - } - - return(my_dijkstra2( - edges, edge_count, - start_vertex, end_vertex, - directed, has_reverse_cost, - - path, path_count, err_msg, - - ruleList)); -} - - -// ------------------------------------------------------------------------- -int GraphDefinition:: my_dijkstra2( - Edge_t *edges, size_t edge_count, - int64 start_vertex, int64 end_vertex, - bool directed, bool has_reverse_cost, - - path_element_tt **path, size_t *path_count, - char **err_msg, - std::vector &ruleList) { - m_ruleTable.clear(); - LongVector vecsource; - for (const auto &rule : ruleList) { - size_t j; - size_t seq_cnt = rule.second.size(); - std::vector temp_precedencelist; - temp_precedencelist.clear(); - for (j = 1; j < seq_cnt; j++) { - temp_precedencelist.push_back(rule.second[j]); - } - int64 dest_edge_id = rule.second[0]; - if (m_ruleTable.find(dest_edge_id) != m_ruleTable.end()) { - m_ruleTable[dest_edge_id].push_back(Rule(rule.first, - temp_precedencelist)); - } else { - std::vector temprules; - temprules.clear(); - temprules.push_back(Rule(rule.first, temp_precedencelist)); - m_ruleTable.insert(std::make_pair(dest_edge_id, temprules)); - } - - if (isStartVirtual) { - if (seq_cnt == 2 && rule.second[1] == m_lStartEdgeId) { - vecsource = m_mapNodeId2Edge[start_vertex]; - for (const auto &source : vecsource) { - temp_precedencelist.clear(); - temp_precedencelist.push_back( - m_vecEdgeVector[static_cast(source)]->m_lEdgeID); - m_ruleTable[dest_edge_id].push_back(Rule(rule.first, - temp_precedencelist)); - } - } - } - } - if (isEndVirtual) { - if (m_ruleTable.find(m_lEndEdgeId) != m_ruleTable.end()) { - std::vector tmpRules = m_ruleTable[m_lEndEdgeId]; - vecsource = m_mapNodeId2Edge[end_vertex]; - for (const auto &source : vecsource) { - m_ruleTable.insert(std::make_pair( - m_vecEdgeVector[static_cast(source)]->m_lEdgeID, tmpRules)); - } - } - } - m_bIsturnRestrictOn = true; - return(my_dijkstra3( - edges, edge_count, - start_vertex, end_vertex, - directed, has_reverse_cost, - path, path_count, err_msg)); -} - -// ------------------------------------------------------------------------- -int GraphDefinition:: my_dijkstra3( - Edge_t *edges, size_t edge_count, - int64 start_vertex, int64 end_vertex, - bool directed, bool has_reverse_cost, - path_element_tt **path, size_t *path_count, char **err_msg - ) { - if (!m_bIsGraphConstructed) { - init(); - construct_graph(edges, edge_count, has_reverse_cost, directed); - m_bIsGraphConstructed = true; - } - - std::priority_queue, std::greater > que; - parent = new PARENT_PATH[edge_count + 1]; - m_dCost = new CostHolder[edge_count + 1]; - m_vecPath.clear(); - - unsigned int i; - for (i = 0; i <= edge_count; i++) { - m_dCost[i].startCost = 1e15; - m_dCost[i].endCost = 1e15; - } - - if (m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end()) { - *err_msg = const_cast("Source Not Found"); - deleteall(); - return -1; - } - - if (m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end()) { - *err_msg = const_cast("Destination Not Found"); - deleteall(); - return -1; - } - - LongVector vecsource = m_mapNodeId2Edge[start_vertex]; - GraphEdgeInfo* cur_edge = NULL; - - for (const auto &source : vecsource) { - cur_edge = m_vecEdgeVector[static_cast(source)]; - if (cur_edge->m_lStartNode == start_vertex) { - if (cur_edge->m_dCost >= 0.0) { - m_dCost[cur_edge->m_lEdgeIndex].endCost = cur_edge->m_dCost; - parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1; - parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1; - que.push(std::make_pair(cur_edge->m_dCost, - std::make_pair(cur_edge->m_lEdgeIndex, true))); - } - } else { - if (cur_edge->m_dReverseCost >= 0.0) { - m_dCost[cur_edge->m_lEdgeIndex].startCost = - cur_edge->m_dReverseCost; - parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1; - parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1; - que.push(std::make_pair(cur_edge->m_dReverseCost, - std::make_pair(cur_edge->m_lEdgeIndex, false))); - } - } - } - int64 cur_node = -1; - - while (!que.empty()) { - PDP cur_pos = que.top(); - que.pop(); - int64 cured_index = cur_pos.second.first; - cur_edge = m_vecEdgeVector[static_cast(cured_index)]; - - if (cur_pos.second.second) { // explore edges connected to end node - cur_node = cur_edge->m_lEndNode; - if (cur_edge->m_dCost < 0.0) - continue; - if (cur_node == end_vertex) - break; - explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge, - que); - } else { // explore edges connected to start node - cur_node = cur_edge->m_lStartNode; - if (cur_edge->m_dReverseCost < 0.0) - continue; - if (cur_node == end_vertex) - break; - explore(cur_node, *cur_edge, false, - cur_edge->m_vecStartConnectedEdge, que); - } - } - if (cur_node != end_vertex) { - if (m_lStartEdgeId == m_lEndEdgeId) { - if (get_single_cost(1000.0, path, path_count)) { - return 0; - } - } - *err_msg = const_cast("Path Not Found"); - deleteall(); - return -1; - } else { - double total_cost; - if (cur_node == cur_edge->m_lStartNode) { - total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost; - construct_path(cur_edge->m_lEdgeIndex, 1); - } else { - total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost; - construct_path(cur_edge->m_lEdgeIndex, 0); - } - path_element_tt pelement; - pelement.vertex_id = end_vertex; - pelement.edge_id = -1; - pelement.cost = 0.0; - m_vecPath.push_back(pelement); - - if (m_lStartEdgeId == m_lEndEdgeId) { - if (get_single_cost(total_cost, path, path_count)) { - return 0; - } - } - - *path = reinterpret_cast( - malloc(sizeof(path_element_tt) * (m_vecPath.size() + 1))); - *path_count = m_vecPath.size(); - - for (size_t i = 0; i < *path_count; i++) { - (*path)[i].vertex_id = m_vecPath[i].vertex_id; - (*path)[i].edge_id = m_vecPath[i].edge_id; - (*path)[i].cost = m_vecPath[i].cost; - } - if (isStartVirtual) { - (*path)[0].vertex_id = -1; - (*path)[0].edge_id = m_lStartEdgeId; - } - if (isEndVirtual) { - *path_count = *path_count - 1; - (*path)[*path_count - 1].edge_id = m_lEndEdgeId; - } - } - deleteall(); - return 0; -} - -// ------------------------------------------------------------------------- -bool GraphDefinition::get_single_cost(double total_cost, path_element_tt **path, - size_t *path_count) { - GraphEdgeInfo* start_edge_info = - m_vecEdgeVector[static_cast(m_mapEdgeId2Index[m_lStartEdgeId])]; - if (m_dEndPart >= m_dStartpart) { - if (start_edge_info->m_dCost >= 0.0 && start_edge_info->m_dCost * - (m_dEndPart - m_dStartpart) <= total_cost) { - *path = reinterpret_cast(malloc( - sizeof(path_element_tt) * (1))); - *path_count = 1; - (*path)[0].vertex_id = -1; - (*path)[0].edge_id = m_lStartEdgeId; - (*path)[0].cost = start_edge_info->m_dCost * - (m_dEndPart - m_dStartpart); - - return true; - } - } else { - if (start_edge_info->m_dReverseCost >= 0.0 && - start_edge_info->m_dReverseCost * (m_dStartpart - m_dEndPart) <= - total_cost) { - *path = reinterpret_cast(malloc( - sizeof(path_element_tt) * (1))); - *path_count = 1; - (*path)[0].vertex_id = -1; - (*path)[0].edge_id = m_lStartEdgeId; - (*path)[0].cost = start_edge_info->m_dReverseCost * - (m_dStartpart - m_dEndPart); - - return true; - } - } - return false; -} - - -// ------------------------------------------------------------------------- -bool GraphDefinition::construct_graph(Edge_t* edges, size_t edge_count, - bool has_reverse_cost, bool directed) { - for (size_t i = 0; i < edge_count; i++) { - if (!has_reverse_cost) { - if (directed) { - edges[i].reverse_cost = -1.0; - } else { - edges[i].reverse_cost = edges[i].cost; - } - } - addEdge(edges[i]); - } - m_bIsGraphConstructed = true; - return true; -} - - -// ------------------------------------------------------------------------- -bool GraphDefinition::connectEdge(GraphEdgeInfo& firstEdge, - GraphEdgeInfo& secondEdge, bool bIsStartNodeSame) { - if (bIsStartNodeSame) { - if (firstEdge.m_dReverseCost >= 0.0) - firstEdge.m_vecStartConnectedEdge.push_back( - secondEdge.m_lEdgeIndex); - if (firstEdge.m_lStartNode == secondEdge.m_lStartNode) { - if (secondEdge.m_dReverseCost >= 0.0) - secondEdge.m_vecStartConnectedEdge.push_back( - firstEdge.m_lEdgeIndex); - } else { - if (secondEdge.m_dCost >= 0.0) - secondEdge.m_vecEndConnedtedEdge.push_back( - firstEdge.m_lEdgeIndex); - } - } else { - if (firstEdge.m_dCost >= 0.0) - firstEdge.m_vecEndConnedtedEdge.push_back(secondEdge.m_lEdgeIndex); - if (firstEdge.m_lEndNode == secondEdge.m_lStartNode) { - if (secondEdge.m_dReverseCost >= 0.0) - secondEdge.m_vecStartConnectedEdge.push_back( - firstEdge.m_lEdgeIndex); - } else { - if (secondEdge.m_dCost >= 0.0) - secondEdge.m_vecEndConnedtedEdge.push_back( - firstEdge.m_lEdgeIndex); - } - } - return true; -} - - -// ------------------------------------------------------------------------- -bool GraphDefinition::addEdge(Edge_t edgeIn) { - // int64 lTest; - Long2LongMap::iterator itMap = m_mapEdgeId2Index.find(edgeIn.id); - if (itMap != m_mapEdgeId2Index.end()) - return false; - - - GraphEdgeInfo* newEdge = new GraphEdgeInfo(); - newEdge->m_vecStartConnectedEdge.clear(); - newEdge->m_vecEndConnedtedEdge.clear(); - newEdge->m_vecRestrictedEdge.clear(); - newEdge->m_lEdgeID = edgeIn.id; - newEdge->m_lEdgeIndex = static_cast(m_vecEdgeVector.size()); - newEdge->m_lStartNode = edgeIn.source; - newEdge->m_lEndNode = edgeIn.target; - newEdge->m_dCost = edgeIn.cost; - newEdge->m_dReverseCost = edgeIn.reverse_cost; - - if (edgeIn.id > max_edge_id) { - max_edge_id = edgeIn.id; - } - - if (newEdge->m_lStartNode > max_node_id) { - max_node_id = newEdge->m_lStartNode; - } - if (newEdge->m_lEndNode > max_node_id) { - max_node_id = newEdge->m_lEndNode; - } - - // Searching the start node for connectivity - Long2LongVectorMap::iterator itNodeMap = m_mapNodeId2Edge.find( - edgeIn.source); - if (itNodeMap != m_mapNodeId2Edge.end()) { - // Connect current edge with existing edge with start node - // connectEdge( - int64 lEdgeCount = static_cast(itNodeMap->second.size()); - int64 lEdgeIndex; - for (lEdgeIndex = 0; lEdgeIndex < lEdgeCount; lEdgeIndex++) { - int64 lEdge = itNodeMap->second.at(static_cast(lEdgeIndex)); - connectEdge(*newEdge, *m_vecEdgeVector[static_cast(lEdge)], true); - } - } - - - // Searching the end node for connectivity - itNodeMap = m_mapNodeId2Edge.find(edgeIn.target); - if (itNodeMap != m_mapNodeId2Edge.end()) { - // Connect current edge with existing edge with end node - // connectEdge( - int64 lEdgeCount = static_cast(itNodeMap->second.size()); - int64 lEdgeIndex; - for (lEdgeIndex = 0; lEdgeIndex < lEdgeCount; lEdgeIndex++) { - int64 lEdge = itNodeMap->second.at(static_cast(lEdgeIndex)); - connectEdge(*newEdge, *m_vecEdgeVector[static_cast(lEdge)], false); - } - } - - - - // Add this node and edge into the data structure - m_mapNodeId2Edge[edgeIn.source].push_back(newEdge->m_lEdgeIndex); - m_mapNodeId2Edge[edgeIn.target].push_back(newEdge->m_lEdgeIndex); - - - // Adding edge to the list - m_mapEdgeId2Index.insert(std::make_pair(newEdge->m_lEdgeID, - m_vecEdgeVector.size())); - m_vecEdgeVector.push_back(newEdge); - - // - - - return true; -} diff --git a/src/trsp/trsp.c b/src/trsp/trsp.c index 8a221bd575a..35741501863 100644 --- a/src/trsp/trsp.c +++ b/src/trsp/trsp.c @@ -1,10 +1,10 @@ /*PGR-GNU***************************************************************** -File: new_trsp.c +File: trsp.c Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org Copyright (c) 2017 Vicky Vergara -Mail: vicky at georepublic.de +Mail: vicky at erosion.dev ------ @@ -37,12 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_trspv4(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_trspv4); -PGDLLEXPORT Datum _trsp(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_trsp); - -PGDLLEXPORT Datum _v4trsp(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_v4trsp); - static void process( @@ -183,183 +177,3 @@ _pgr_trspv4(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } } - - -PGDLLEXPORT Datum -_v4trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - size_t result_count = 0; - Path_rt *result_tuples = NULL; - - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - funcctx = SRF_FIRSTCALL_INIT(); - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - if (PG_NARGS() == 5) { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - NULL, - PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_ARRAYTYPE_P(3), - PG_GETARG_BOOL(4), - &result_tuples, &result_count); - } else /* (PG_NARGS() == 4) */ { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - text_to_cstring(PG_GETARG_TEXT_P(2)), - NULL, - NULL, - PG_GETARG_BOOL(3), - &result_tuples, &result_count); - } - - funcctx->max_calls = result_count; - funcctx->user_fctx = result_tuples; - - if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("function returning record called in context " - "that cannot accept type record"))); - } - - funcctx->tuple_desc = tuple_desc; - MemoryContextSwitchTo(oldcontext); - } - - funcctx = SRF_PERCALL_SETUP(); - - tuple_desc = funcctx->tuple_desc; - result_tuples = (Path_rt *) funcctx->user_fctx; - - if (funcctx->call_cntr < funcctx->max_calls) { - HeapTuple tuple; - Datum result; - Datum *values; - bool* nulls; - size_t call_cntr = funcctx->call_cntr; - - size_t numb = 8; - values = palloc(numb * sizeof(Datum)); - nulls = palloc(numb * sizeof(bool)); - - size_t i; - for (i = 0; i < numb; ++i) { - nulls[i] = false; - } - - int64_t path_seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; - - values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum((int32_t)path_seq); - values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[call_cntr].node); - values[5] = Int64GetDatum(result_tuples[call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - - result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : path_seq + 1; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - result = HeapTupleGetDatum(tuple); - - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { - SRF_RETURN_DONE(funcctx); - } -} - -PGDLLEXPORT Datum -_trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - size_t result_count = 0; - Path_rt *result_tuples = NULL; - - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - funcctx = SRF_FIRSTCALL_INIT(); - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - NULL, - PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_ARRAYTYPE_P(3), - PG_GETARG_BOOL(4), - &result_tuples, &result_count); - - funcctx->max_calls = result_count; - funcctx->user_fctx = result_tuples; - - if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("function returning record called in context " - "that cannot accept type record"))); - } - - funcctx->tuple_desc = tuple_desc; - MemoryContextSwitchTo(oldcontext); - } - - funcctx = SRF_PERCALL_SETUP(); - - tuple_desc = funcctx->tuple_desc; - result_tuples = (Path_rt *) funcctx->user_fctx; - - if (funcctx->call_cntr < funcctx->max_calls) { - HeapTuple tuple; - Datum result; - Datum *values; - bool* nulls; - size_t call_cntr = funcctx->call_cntr; - - - size_t numb = 8; - values = palloc(numb * sizeof(Datum)); - nulls = palloc(numb * sizeof(bool)); - - size_t i; - for (i = 0; i < numb; ++i) { - nulls[i] = false; - } - - int64_t path_seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; - - values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum((int32_t)path_seq); - values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[call_cntr].node); - values[5] = Int64GetDatum(result_tuples[call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - - result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : path_seq + 1; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - result = HeapTupleGetDatum(tuple); - - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { - SRF_RETURN_DONE(funcctx); - } -} diff --git a/src/trsp/trspHandler.cpp b/src/trsp/trspHandler.cpp index 29963e5407b..b14f472b954 100644 --- a/src/trsp/trspHandler.cpp +++ b/src/trsp/trspHandler.cpp @@ -42,8 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace trsp { -// ------------------------------------------------------------------------- -Pgr_trspHandler::Pgr_trspHandler( +TrspHandler::TrspHandler( std::vector &edges, const bool directed, const std::vector &ruleList) : @@ -55,29 +54,10 @@ Pgr_trspHandler::Pgr_trspHandler( m_idx_to_id[id.second] = id.first; } - construct_graph(edges, directed); + construct_graph(edges, std::vector(), directed); } -Pgr_trspHandler::Pgr_trspHandler( - Edge_t *edges, - const size_t edge_count, - const bool directed, - const std::vector &ruleList) : - m_ruleTable() { - initialize_restrictions(ruleList); - - renumber_edges(edges, edge_count); - for (const auto& id : m_id_to_idx) { - m_idx_to_id[id.second] = id.first; - } - - construct_graph( - edges, - edge_count, - directed); -} - -Pgr_trspHandler::Pgr_trspHandler( +TrspHandler::TrspHandler( std::vector &edges, const std::vector &new_edges, const bool directed, @@ -92,44 +72,14 @@ Pgr_trspHandler::Pgr_trspHandler( m_idx_to_id[id.second] = id.first; } - construct_graph( - edges, - directed); - add_point_edges( - point_edges, - directed); -} - -Pgr_trspHandler::Pgr_trspHandler( - Edge_t *edges, - const size_t edge_count, - const std::vector &new_edges, - const bool directed, - const std::vector &ruleList) : - m_ruleTable() { - initialize_restrictions(ruleList); - - auto point_edges = new_edges; - renumber_edges(edges, edge_count, point_edges); - - for (const auto& id : m_id_to_idx) { - m_idx_to_id[id.second] = id.first; - } - - construct_graph( - edges, - edge_count, - directed); - add_point_edges( - point_edges, - directed); + construct_graph(edges, point_edges, directed); } // ------------------------------------------------------------------------- void -Pgr_trspHandler::renumber_edges(std::vector &edges) { +TrspHandler::renumber_edges(std::vector &edges) { int64_t idx(0); for (auto &e : edges) { if (m_id_to_idx.find(e.source) == m_id_to_idx.end()) { @@ -145,27 +95,9 @@ Pgr_trspHandler::renumber_edges(std::vector &edges) { } } -void -Pgr_trspHandler::renumber_edges( - Edge_t *edges, - size_t total_edges) { - int64_t idx(0); - for (size_t i = 0; i < total_edges; ++i) { - if (m_id_to_idx.find(edges[i].source) == m_id_to_idx.end()) { - m_id_to_idx[edges[i].source] = idx; - ++idx; - } - if (m_id_to_idx.find(edges[i].target) == m_id_to_idx.end()) { - m_id_to_idx[edges[i].target] = idx; - ++idx; - } - edges[i].source = m_id_to_idx.at(edges[i].source); - edges[i].target = m_id_to_idx.at(edges[i].target); - } -} void -Pgr_trspHandler::renumber_edges( +TrspHandler::renumber_edges( std::vector &edges, std::vector &new_edges) { int64_t idx(0); @@ -195,42 +127,10 @@ Pgr_trspHandler::renumber_edges( } } -void -Pgr_trspHandler::renumber_edges( - Edge_t *edges, - size_t total_edges, - std::vector& new_edges) { - int64_t idx(0); - for (size_t i = 0; i < total_edges; ++i) { - if (m_id_to_idx.find(edges[i].source) == m_id_to_idx.end()) { - m_id_to_idx[edges[i].source] = idx; - ++idx; - } - if (m_id_to_idx.find(edges[i].target) == m_id_to_idx.end()) { - m_id_to_idx[edges[i].target] = idx; - ++idx; - } - edges[i].source = m_id_to_idx.at(edges[i].source); - edges[i].target = m_id_to_idx.at(edges[i].target); - } - for (auto &e : new_edges) { - if (m_id_to_idx.find(e.source) == m_id_to_idx.end()) { - m_id_to_idx[e.source] = idx; - ++idx; - } - if (m_id_to_idx.find(e.target) == m_id_to_idx.end()) { - m_id_to_idx[e.target] = idx; - ++idx; - } - e.source = m_id_to_idx.at(e.source); - e.target = m_id_to_idx.at(e.target); - } -} - // ------------------------------------------------------------------------- -void Pgr_trspHandler::clear() { +void TrspHandler::clear() { m_parent.clear(); m_dCost.clear(); m_path.clear(); @@ -238,7 +138,7 @@ void Pgr_trspHandler::clear() { // ------------------------------------------------------------------------- -double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) { +double TrspHandler::construct_path(int64_t ed_id, Position pos) { if (pos == ILLEGAL) return (std::numeric_limits::max)(); pgassert(pos != ILLEGAL); @@ -282,7 +182,7 @@ double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) { // ------------------------------------------------------------------------- -double Pgr_trspHandler::getRestrictionCost( +double TrspHandler::getRestrictionCost( int64_t edge_ind, const EdgeInfo &edge, bool isStart) { @@ -315,7 +215,7 @@ double Pgr_trspHandler::getRestrictionCost( } -double Pgr_trspHandler::get_tot_cost( +double TrspHandler::get_tot_cost( double cost, size_t edge_idx, bool isStart) { @@ -329,7 +229,7 @@ double Pgr_trspHandler::get_tot_cost( // ------------------------------------------------------------------------- -void Pgr_trspHandler::explore( +void TrspHandler::explore( int64_t cur_node, const EdgeInfo cur_edge, bool isStart) { @@ -380,7 +280,7 @@ void Pgr_trspHandler::explore( // ------------------------------------------------------------------------- -int Pgr_trspHandler::initialize_restrictions( +int TrspHandler::initialize_restrictions( const std::vector &ruleList) { for (const auto &rule : ruleList) { auto dest_edge_id = rule.dest_id(); @@ -402,7 +302,7 @@ int Pgr_trspHandler::initialize_restrictions( * */ Path -Pgr_trspHandler::process( +TrspHandler::process( const int64_t start_vertex, const int64_t end_vertex) { if (m_id_to_idx.find(start_vertex) == m_id_to_idx.end() @@ -438,7 +338,7 @@ Pgr_trspHandler::process( * */ std::deque -Pgr_trspHandler::process( +TrspHandler::process( const std::map> &combinations ) { std::deque paths; @@ -451,77 +351,40 @@ Pgr_trspHandler::process( return paths; } -/** process - * - * does many to many processisng - * - */ -std::deque -Pgr_trspHandler::process( - const std::vector sources, - const std::vector targets) { - std::deque paths; - for (const auto &s : sources) { - for (const auto &t : targets) { - paths.push_back(process(s, t)); - } - } - - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.start_id() < e2.start_id(); - }); - return paths; -} - - -void Pgr_trspHandler::add_to_que( - double cost, - size_t e_idx, - bool isStart) { - que.push(std::make_pair(cost, - std::make_pair(e_idx, isStart))); -} - - // ------------------------------------------------------------------------- +void TrspHandler::add_to_que(double cost, size_t e_idx, bool isStart) { + m_que.push(std::make_pair(cost, std::make_pair(e_idx, isStart))); +} -void Pgr_trspHandler::initialize_que() { +void TrspHandler::initialize_que() { /* * For each adjacent edge to the start_vertex */ for (const auto source : m_adjacency[m_start_vertex]) { EdgeInfo &cur_edge = m_edges[source]; - if (cur_edge.startNode() == m_start_vertex - && cur_edge.cost() >= 0.0) { + if (cur_edge.startNode() == m_start_vertex && cur_edge.cost() >= 0.0) { m_dCost[cur_edge.idx()].endCost = cur_edge.cost(); m_parent[cur_edge.idx()].v_pos[0] = ILLEGAL; add_to_que(cur_edge.cost(), cur_edge.idx(), true); } - if (cur_edge.endNode() == m_start_vertex - && cur_edge.r_cost() >= 0.0) { - m_dCost[cur_edge.idx()].startCost = - cur_edge.r_cost(); + if (cur_edge.endNode() == m_start_vertex && cur_edge.r_cost() >= 0.0) { + m_dCost[cur_edge.idx()].startCost = cur_edge.r_cost(); m_parent[cur_edge.idx()].v_pos[1] = ILLEGAL; add_to_que(cur_edge.r_cost(), cur_edge.idx(), false); } } } -EdgeInfo Pgr_trspHandler::dijkstra_exploration() { +EdgeInfo TrspHandler::dijkstra_exploration() { EdgeInfo cur_edge; - pgassert(current_node == m_start_vertex); + pgassert(m_current_node == m_start_vertex); - while (!que.empty()) { - auto cur_pos = que.top(); - que.pop(); + while (!m_que.empty()) { + auto cur_pos = m_que.top(); + m_que.pop(); auto cure_idxex = cur_pos.second.first; cur_edge = m_edges[static_cast(cure_idxex)]; @@ -530,18 +393,18 @@ EdgeInfo Pgr_trspHandler::dijkstra_exploration() { /* * explore edges connected to end node */ - current_node = cur_edge.endNode(); + m_current_node = cur_edge.endNode(); if (cur_edge.cost() < 0.0) continue; - if (current_node == m_end_vertex) break; - explore(current_node, cur_edge, false); + if (m_current_node == m_end_vertex) break; + explore(m_current_node, cur_edge, false); } else { /* * explore edges connected to start node */ - current_node = cur_edge.startNode(); + m_current_node = cur_edge.startNode(); if (cur_edge.r_cost() < 0.0) continue; - if (current_node == m_end_vertex) break; - explore(current_node, cur_edge, true); + if (m_current_node == m_end_vertex) break; + explore(m_current_node, cur_edge, true); } } return cur_edge; @@ -551,7 +414,7 @@ EdgeInfo Pgr_trspHandler::dijkstra_exploration() { Path -Pgr_trspHandler::process_trsp( +TrspHandler::process_trsp( size_t edge_count) { pgassert(m_path.start_id() == m_start_vertex); pgassert(m_path.end_id() == m_end_vertex); @@ -562,25 +425,21 @@ Pgr_trspHandler::process_trsp( initialize_que(); - current_node = m_start_vertex; + m_current_node = m_start_vertex; pgassert(m_path.start_id() == m_start_vertex); auto cur_edge = dijkstra_exploration(); pgassert(m_path.start_id() == m_start_vertex); - if (current_node != m_end_vertex) { + if (m_current_node != m_end_vertex) { Path result(m_start_vertex, m_end_vertex); return result.renumber_vertices(m_idx_to_id);; } pgassert(m_path.start_id() == m_start_vertex); - if (current_node == cur_edge.startNode()) { - construct_path(static_cast(cur_edge.idx()), C_EDGE); - } else { - construct_path(static_cast(cur_edge.idx()), RC_EDGE); - } + construct_path(static_cast(cur_edge.idx()), m_current_node == cur_edge.startNode()? C_EDGE : RC_EDGE); Path_t pelement = {}; pelement.node = m_end_vertex; @@ -593,41 +452,23 @@ Pgr_trspHandler::process_trsp( } - - - -// ------------------------------------------------------------------------- -void Pgr_trspHandler::construct_graph( +void TrspHandler::construct_graph( const std::vector &edges, + const std::vector &new_edges, const bool directed) { for (const auto &e : edges) { addEdge(e, directed); } - m_mapEdgeId2Index.clear(); -} - -void Pgr_trspHandler::construct_graph( - Edge_t* edges, - const size_t edge_count, - const bool directed) { - for (size_t i = 0; i < edge_count; i++) { - addEdge(edges[i], directed); + for (const auto &e : new_edges) { + addEdge(e, directed); } m_mapEdgeId2Index.clear(); } -void Pgr_trspHandler::add_point_edges( - const std::vector &new_edges, - const bool directed) { - for (auto current_edge : new_edges) { - addEdge(current_edge, directed); - } - m_mapEdgeId2Index.clear(); -} // ------------------------------------------------------------------------- -void Pgr_trspHandler::connectStartEdge( +void TrspHandler::connectStartEdge( size_t firstEdge_idx, size_t secondEdge_idx) { EdgeInfo &firstEdge = m_edges[firstEdge_idx]; @@ -650,7 +491,7 @@ void Pgr_trspHandler::connectStartEdge( // ------------------------------------------------------------------------- -void Pgr_trspHandler::connectEndEdge( +void TrspHandler::connectEndEdge( size_t firstEdge_idx, size_t secondEdge_idx) { EdgeInfo &firstEdge = m_edges[firstEdge_idx]; @@ -673,7 +514,7 @@ void Pgr_trspHandler::connectEndEdge( // ------------------------------------------------------------------------- -bool Pgr_trspHandler::addEdge(Edge_t edgeIn, bool directed) { +bool TrspHandler::addEdge(Edge_t edgeIn, bool directed) { /* * making all "cost" > 0 */ @@ -682,33 +523,33 @@ bool Pgr_trspHandler::addEdge(Edge_t edgeIn, bool directed) { std::swap(edgeIn.source, edgeIn.target); } - if (!directed) { - if (edgeIn.reverse_cost < 0) { - edgeIn.reverse_cost = edgeIn.cost; - } + /* This gives a value to reverse_cost when:" + * graph is undirected + * reverse_cost is negative + */ + if (!directed && edgeIn.reverse_cost < 0) { + edgeIn.reverse_cost = edgeIn.cost; } - /* * the index of this new edge in the edges container is * m_edges.size() */ EdgeInfo edge(edgeIn, m_edges.size()); - + /* + * Add to the set of edges + */ m_edges.push_back(edge); - EdgeInfo &newEdge = m_edges[m_edges.size()-1]; - - /* * Searching the start node for connectivity */ auto itNodeMap = m_adjacency.find(edgeIn.source); if (itNodeMap != m_adjacency.end()) { - for (const auto e_idx : itNodeMap->second) { + for (const auto &e_idx : itNodeMap->second) { connectStartEdge(edge.idx(), e_idx); } } @@ -719,7 +560,7 @@ bool Pgr_trspHandler::addEdge(Edge_t edgeIn, bool directed) { */ itNodeMap = m_adjacency.find(edgeIn.target); if (itNodeMap != m_adjacency.end()) { - for (const auto e_idx : itNodeMap->second) { + for (const auto &e_idx : itNodeMap->second) { connectEndEdge(edge.idx(), e_idx); } } diff --git a/src/trsp/trspVia_driver.cpp b/src/trsp/trspVia_driver.cpp index 9c5a0cf39b2..a80124bbfd3 100644 --- a/src/trsp/trspVia_driver.cpp +++ b/src/trsp/trspVia_driver.cpp @@ -239,7 +239,7 @@ pgr_do_trspVia( auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { - pgrouting::trsp::Pgr_trspHandler gdef(edges, directed, ruleList); + pgrouting::trsp::TrspHandler gdef(edges, directed, ruleList); auto new_paths = gdef.process(new_combinations); paths.insert(paths.end(), new_paths.begin(), new_paths.end()); } diff --git a/src/trsp/trspVia_withPoints_driver.cpp b/src/trsp/trspVia_withPoints_driver.cpp index 5c057cb13f7..a0bdabd0757 100644 --- a/src/trsp/trspVia_withPoints_driver.cpp +++ b/src/trsp/trspVia_withPoints_driver.cpp @@ -261,7 +261,7 @@ pgr_do_trspVia_withPoints( auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { - pgrouting::trsp::Pgr_trspHandler gdef( + pgrouting::trsp::TrspHandler gdef( edges, pg_graph.new_edges(), directed, diff --git a/src/trsp/trsp_deprecated.c b/src/trsp/trsp_deprecated.c deleted file mode 100644 index 00f450914ca..00000000000 --- a/src/trsp/trsp_deprecated.c +++ /dev/null @@ -1,453 +0,0 @@ -/*PGR-GNU***************************************************************** -File: trsp_deprecated.c - -Generated with Template by: -Copyright (c) 2013 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*/ - - -#include "c_common/postgres_connection.h" -#include "catalog/pg_type.h" - -#include "c_common/debug_macro.h" -#include "c_common/e_report.h" -#include "c_types/trsp/trsp.h" -#include "c_types/edge_rt.h" -#include "c_common/trsp_pgget.h" -#include "drivers/trsp/trsp_deprecated_driver.h" - -typedef struct restrict_t restrict_t; -typedef struct Edge_rt Edge_t; -typedef struct path_element_tt path_element_tt; - -PGDLLEXPORT Datum _pgr_trsp(PG_FUNCTION_ARGS); - - -typedef struct edge_columns { - int id; - int source; - int target; - int cost; - int reverse_cost; -} edge_columns_t; - -typedef struct restrict_columns { - int target_id; - int via_path; - int to_cost; -} restrict_columns_t; - - -/* - * This function fetches the resturction columns from an SPITupleTable.. - * -*/ -static int -fetch_restrict_columns(SPITupleTable *tuptable, - restrict_columns_t *restrict_columns) { - restrict_columns->target_id = SPI_fnumber(tuptable->tupdesc, "target_id"); - restrict_columns->via_path = SPI_fnumber(tuptable->tupdesc, "via_path"); - restrict_columns->to_cost = SPI_fnumber(tuptable->tupdesc, "to_cost"); - if (restrict_columns->target_id == SPI_ERROR_NOATTRIBUTE || - restrict_columns->via_path == SPI_ERROR_NOATTRIBUTE || - restrict_columns->to_cost == SPI_ERROR_NOATTRIBUTE) { - elog(ERROR, "Error, restriction query must return columns " - "'target_id', 'via_path' and 'to_cost'"); - return -1; - } - - if (SPI_gettypeid(tuptable->tupdesc, - restrict_columns->target_id) != INT4OID || - SPI_gettypeid(tuptable->tupdesc, restrict_columns->via_path) != TEXTOID || - SPI_gettypeid(tuptable->tupdesc, restrict_columns->to_cost) != FLOAT8OID) { - elog(ERROR, "Error, restriction columns 'target_id' must be of type int4," - "'via_path' must be of type text, 'to_cost' must be of type float8"); - return -1; - } - - return 0; -} - - -/* - * To fetch a edge from Tuple. - * - */ - -static void -fetch_restrict(HeapTuple *tuple, TupleDesc *tupdesc, - restrict_columns_t *restrict_columns, restrict_t *rest) { - Datum binval; - bool isnull; - int t; - - for (t = 0; t < MAX_RULE_LENGTH; ++t) - rest->via[t] = -1; - - binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->target_id, - &isnull); - if (isnull) - elog(ERROR, "target_id contains a null value"); - rest->target_id = DatumGetInt32(binval); - - binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->to_cost, &isnull); - if (isnull) - elog(ERROR, "to_cost contains a null value"); - rest->to_cost = DatumGetFloat8(binval); - char *str = SPI_getvalue(*tuple, *tupdesc, restrict_columns->via_path); - - // PGR_DBG("restriction: %f, %i, %s", rest->to_cost, rest->target_id, str); - - if (str != NULL) { - int ci = 0; - char* pch = (char *)strtok(str, " ,"); - - while (pch != NULL && ci < MAX_RULE_LENGTH) { - rest->via[ci] = atoi(pch); - // PGR_DBG(" rest->via[%i]=%i", ci, rest->via[ci]); - ci++; - pch = (char *)strtok(NULL, " ,"); - } - } -} - - - -static int compute_trsp( - char* edges_sql, - int dovertex, - int64_t start_id, - double start_pos, - int64_t end_id, - double end_pos, - bool directed, - bool has_reverse_cost, - char* restrict_sql, - path_element_tt **path, - size_t *path_count) { - pgr_SPI_connect(); - char* err_msg = NULL; - - SPIPlanPtr SPIplan; - Portal SPIportal; - - Edge_t *edges = NULL; - size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); - pgr_throw_error(err_msg, edges_sql); - - // defining min and max vertex id - int64_t v_max_id = 0; - int64_t v_min_id = INT_MAX; - - size_t z; - for (z = 0; z < total_tuples; z++) { - PGR_DBG("id %ld source %ld target %ld cost %f rev %f", - edges[z].id, edges[z].source, edges[z].target, edges[z].cost, edges[z].reverse_cost); - if (edges[z].source < v_min_id) - v_min_id = edges[z].source; - - if (edges[z].source > v_max_id) - v_max_id = edges[z].source; - - if (edges[z].target < v_min_id) - v_min_id = edges[z].target; - - if (edges[z].target > v_max_id) - v_max_id = edges[z].target; - } - - // :::::::::::::::::::::::::::::::::::: - // :: reducing vertex id (renumbering) - // :::::::::::::::::::::::::::::::::::: - /* track if start and end are both in edge tuples */ - int s_count = 0; - int t_count = 0; - for (z = 0; z < total_tuples; z++) { - // check if edges[] contains source and target - if (dovertex) { - if (edges[z].source == start_id || edges[z].target == start_id) - ++s_count; - if (edges[z].source == end_id || edges[z].target == end_id) - ++t_count; - } else { - if (edges[z].id == start_id) - ++s_count; - if (edges[z].id == end_id) - ++t_count; - } - - edges[z].source -= v_min_id; - edges[z].target -= v_min_id; - } - - PGR_DBG("Min vertex id: %ld , Max vid: %ld", v_min_id, v_max_id); - PGR_DBG("Total %ld edge tuples", total_tuples); - - if (s_count == 0) { - elog(ERROR, "Start id was not found."); - return -1; - } - - if (t_count == 0) { - elog(ERROR, "Target id was not found."); - return -1; - } - - if (dovertex) { - start_id -= v_min_id; - end_id -= v_min_id; - } - - PGR_DBG("Fetching restriction tuples\n"); - restrict_t *restricts = NULL; - uint64_t total_restrict_tuples = 0; - restrict_columns_t restrict_columns = {.target_id = -1, .via_path = -1, - .to_cost = -1}; - - int ret = -1; - - if (restrict_sql == NULL) { - PGR_DBG("Sql for restrictions is null."); - } else { - int64 TUPLIMIT = 1000; - - SPIplan = SPI_prepare(restrict_sql, 0, NULL); - if (SPIplan == NULL) { - elog(ERROR, "turn_restrict_shortest_path: " - "couldn't create query plan via SPI"); - return -1; - } - - if ((SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true)) \ - == NULL) { - elog(ERROR, "turn_restrict_shortest_path:" - " SPI_cursor_open('%s') returns NULL", restrict_sql); - return -1; - } - - bool moredata = true; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, TUPLIMIT); - - if (restrict_columns.target_id == -1) { - if (fetch_restrict_columns(SPI_tuptable, &restrict_columns) \ - == -1) { - PGR_DBG("fetch_restrict_columns failed!"); - pgr_SPI_finish(); - return -1; - } - } - - /* Suppress the -Wconversion warning temporarily */ - uint64_t ntuples = SPI_processed; - - total_restrict_tuples += ntuples; - - if (ntuples > 0) { - if (!restricts) - restricts = palloc(total_restrict_tuples * sizeof(restrict_t)); - else - restricts = repalloc(restricts, - total_restrict_tuples * sizeof(restrict_t)); - - if (restricts == NULL) { - pgr_SPI_finish(); - elog(ERROR, "Out of memory"); - return -1; - } - - uint32_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_restrict(&tuple, &tupdesc, &restrict_columns, - &restricts[total_restrict_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - SPI_cursor_close(SPIportal); - } - - PGR_DBG("Total %ld restriction tuples", total_restrict_tuples); - - PGR_DBG("Calling trsp_edge_wrapper\n"); - ret = trsp_edge_wrapper(edges, total_tuples, - restricts, total_restrict_tuples, - start_id, start_pos, end_id, end_pos, - directed, has_reverse_cost, - path, path_count, &err_msg); - - PGR_DBG("Message received from inside:"); - PGR_DBG("%s", err_msg); - - - // :::::::::::::::::::::::::::::::: - // :: restoring original vertex id - // :::::::::::::::::::::::::::::::: - for (z = 0; z < *path_count; z++) { - if (z || (*path)[z].vertex_id != -1) - (*path)[z].vertex_id += v_min_id; - } - - PGR_DBG("ret = %i\n", ret); - - PGR_DBG("*path_count = %ld\n", *path_count); - - if (ret < 0) { - ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED), - errmsg("Error computing path: %s", err_msg))); - } - - pgr_SPI_finish(); - return 0; -} - - -PG_FUNCTION_INFO_V1(_pgr_trsp); -PGDLLEXPORT Datum -_pgr_trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - path_element_tt *path; - - // stuff done only on the first call of the function - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - size_t path_count = 0; - int i; - double s_pos; - double e_pos; - char * sql; - - // create a function context for cross-call persistence - funcctx = SRF_FIRSTCALL_INIT(); - - // switch to memory context appropriate for multiple function calls - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - // verify that the first 5 args are not NULL - for (i = 0; i < 7; i++) { - if (i == 2 || i == 4) continue; - if (PG_ARGISNULL(i)) { - elog(ERROR, "turn_restrict_shortest_path(): " - "Argument %i may not be NULL", i+1); - } - } - - if (PG_ARGISNULL(2)) { - s_pos = 0.5; - } else { - s_pos = PG_GETARG_FLOAT8(2); - if (s_pos < 0.0) s_pos = 0.5; - if (s_pos > 1.0) s_pos = 0.5; - } - - if (PG_ARGISNULL(4)) { - e_pos = 0.5; - } else { - e_pos = PG_GETARG_FLOAT8(4); - if (e_pos < 0.0) e_pos = 0.5; - if (e_pos > 1.0) e_pos = 0.5; - } - - if (PG_ARGISNULL(7)) { - sql = NULL; - } else { - sql = text_to_cstring(PG_GETARG_TEXT_P(7)); - } - - PGR_DBG("Calling compute_trsp"); - - compute_trsp(text_to_cstring(PG_GETARG_TEXT_P(0)), - 0, // sdo edge - PG_GETARG_INT32(1), - s_pos, - PG_GETARG_INT32(3), - e_pos, - PG_GETARG_BOOL(5), - PG_GETARG_BOOL(6), - sql, - &path, &path_count); - - // total number of tuples to be returned - funcctx->max_calls = path_count; - - funcctx->user_fctx = path; - if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("function returning record called in context " - "that cannot accept type record"))); - } - - funcctx->tuple_desc = tuple_desc; - - MemoryContextSwitchTo(oldcontext); - } - - // stuff done on every call of the function - funcctx = SRF_PERCALL_SETUP(); - - tuple_desc = funcctx->tuple_desc; - path = (path_element_tt*) funcctx->user_fctx; - - if (funcctx->call_cntr < funcctx->max_calls) { - // do when there is more left to send - HeapTuple tuple; - Datum result; - Datum *values; - bool* nulls; - - values = palloc(4 * sizeof(Datum)); - nulls = palloc(4 * sizeof(char)); - - values[0] = Int64GetDatum((int64_t)funcctx->call_cntr); - nulls[0] = false; - values[1] = Int32GetDatum((int32_t)path[funcctx->call_cntr].vertex_id); - nulls[1] = false; - values[2] = Int32GetDatum((int32_t)path[funcctx->call_cntr].edge_id); - nulls[2] = false; - values[3] = Float8GetDatum(path[funcctx->call_cntr].cost); - nulls[3] = false; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - // make the tuple into a datum - result = HeapTupleGetDatum(tuple); - - // clean up (this is not really necessary) - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { // do when there is no more left - PGR_DBG("Going to free path"); - if (path) free(path); - SRF_RETURN_DONE(funcctx); - } -} diff --git a/src/trsp/trsp_deprecated_driver.cpp b/src/trsp/trsp_deprecated_driver.cpp deleted file mode 100644 index 342a5cf2f04..00000000000 --- a/src/trsp/trsp_deprecated_driver.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*PGR-GNU***************************************************************** -File: trsp_deprecated_driver.cpp - -Generated with Template by: -Copyright (c) 2015 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*/ - -#include "drivers/trsp/trsp_deprecated_driver.h" - -#ifdef __MINGW32__ -#include -#include -#endif - -#include -#include -#include "trsp/GraphDefinition.hpp" - - -int trsp_edge_wrapper( - Edge_t *edges, - size_t edge_count, - restrict_t *restricts, - size_t restrict_count, - int64_t start_edge, - double start_pos, - int64_t end_edge, - double end_pos, - bool directed, - bool has_reverse_cost, - path_element_tt **path, - size_t *path_count, - char **err_msg - ) { - try { - std::vector ruleTable; - - size_t i, j; - ruleTable.clear(); - for (i = 0; i < restrict_count; i++) { - std::vector seq; - seq.clear(); - seq.push_back(restricts[i].target_id); - for (j = 0; j < MAX_RULE_LENGTH && restricts[i].via[j] >- 1; j++) { - seq.push_back(restricts[i].via[j]); - } - ruleTable.push_back(make_pair(restricts[i].to_cost, seq)); - } - - GraphDefinition gdef; - auto res = gdef.my_dijkstra1(edges, edge_count, start_edge, start_pos, - end_edge, end_pos, directed, has_reverse_cost, path, path_count, - err_msg, ruleTable); - - - if (res < 0) - return res; - else - return EXIT_SUCCESS; - } - catch(std::exception& e) { - *err_msg = const_cast(e.what()); - return -1; - } - catch(...) { - *err_msg = const_cast("Caught unknown exception!"); - return -1; - } -} diff --git a/src/trsp/trsp_driver.cpp b/src/trsp/trsp_driver.cpp index c9b289565cc..56a1bf8c8e8 100644 --- a/src/trsp/trsp_driver.cpp +++ b/src/trsp/trsp_driver.cpp @@ -202,7 +202,7 @@ pgr_do_trsp( auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { - pgrouting::trsp::Pgr_trspHandler gdef( + pgrouting::trsp::TrspHandler gdef( edges, directed, ruleList); diff --git a/src/trsp/trsp_withPoints_driver.cpp b/src/trsp/trsp_withPoints_driver.cpp index 0bcc7453b55..ba5b7a63ff2 100644 --- a/src/trsp/trsp_withPoints_driver.cpp +++ b/src/trsp/trsp_withPoints_driver.cpp @@ -230,7 +230,7 @@ pgr_do_trsp_withPoints( auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { - pgrouting::trsp::Pgr_trspHandler gdef( + pgrouting::trsp::TrspHandler gdef( edges, pg_graph.new_edges(), directed, diff --git a/tools/testers/trsp_tests.sql b/tools/testers/trsp_tests.sql index 3a26bf96fd8..5471449f0ce 100644 --- a/tools/testers/trsp_tests.sql +++ b/tools/testers/trsp_tests.sql @@ -1,4 +1,3 @@ - CREATE OR REPLACE FUNCTION compare_trsp_dijkstra_new(cant INTEGER, flag boolean, restrictions_sql TEXT) RETURNS SETOF TEXT AS $BODY$ @@ -7,6 +6,7 @@ DECLARE dijkstra_sql TEXT; trsp_sql TEXT; directed TEXT; + params TEXT; msg TEXT; BEGIN IF NOT min_version('3.4.0') THEN @@ -17,103 +17,52 @@ BEGIN directed = 'Undirected'; IF flag THEN directed = 'Directed'; END IF; - FOR i IN 1.. cant BY 2 LOOP + FOR i IN 1..cant BY 2 LOOP FOR j IN 1..cant LOOP - -- For related restrictions only when source and target are equal it is garanteed that the results are the same as - -- dijkstra - IF (restrictions_sql = 'related') THEN CONTINUE WHEN i != j; END IF; - - dijkstra_sql := 'SELECT seq, node, edge, cost::text FROM pgr_dijkstra($$with_reverse_cost$$, ' - || i || ', ' || j || ', ' || flag || ')'; - trsp_sql := 'SELECT seq, node, edge, cost::text from pgr_trsp($$with_reverse_cost$$, $$' || restrictions_sql ||'$$, ' - || i || ', ' || j || ', ' || flag || ')'; - msg := restrictions_sql || '-' || k || '-1 ' || directed || ', with reverse_cost from ' || i || ' to ' || j; - RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); - - dijkstra_sql := 'SELECT seq, node, edge, cost::text FROM pgr_dijkstra($$no_reverse_cost$$, ' - || i || ', ' || j || ', ' || flag || ')'; - trsp_sql := 'SELECT seq, node, edge, cost::text from pgr_trsp($$no_reverse_cost$$, $$' || restrictions_sql ||'$$, ' - || i || ', ' || j || ', ' || flag || ')'; - msg := restrictions_sql || '-' || k || '-2 ' || directed || ', NO reverse_cost from ' || i || ' to ' || j; - RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); - - k := k + 1; - - END LOOP; - END LOOP; -END -$BODY$ -language plpgsql; + params = ' ' || i || ', ' || j || ', ' || flag; -CREATE OR REPLACE FUNCTION compare_trsp_dijkstra(cant INTEGER default 18, flag boolean default true ) -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -dijkstra_sql TEXT; -trsp_sql TEXT; -with_reverse_cost TEXT; -no_reverse_cost TEXT; -k integer; -directed TEXT; -msg TEXT; -BEGIN - -- TEST of deprecated signature - directed = 'Undirected'; - IF flag THEN directed = 'Directed'; END IF; - - k := 1; - with_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edges ORDER BY id'); - no_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost from edges ORDER BY id'); - FOR i IN 1.. cant BY 2 LOOP - FOR j IN 1..cant LOOP - - -- this special case is tested on the other test - CONTINUE WHEN i = j; - - -- test when there is reverse cost and its marked as being used - -- VS dijkstra autodetected has reverse cost - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost::text - FROM pgr_dijkstra( ' || with_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ')'; - trsp_sql := 'SELECT seq, id1, id2, cost::text from pgr_trsp( ' || with_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ', TRUE)'; - msg := k || '-1 ' || directed || ', with reverse_cost, marked as being used: from ' || i || ' to ' || j; - - RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); - - -- test when there is reverse cost and its marked NOT being used - -- autodetected is found - -- VS dijkstra autodetected - -- Flag is ignored - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost::text - FROM pgr_dijkstra( ' || with_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ')'; - trsp_sql := 'SELECT seq, id1, id2, cost::text from pgr_trsp( ' || with_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ', FALSE)'; - msg := k || '-2 ' || directed || ', with reverse_cost, marked as NOT being used: from ' || i || ' to ' || j; - IF NOT min_version('4.0.1') THEN PERFORM todo(1, 'has_rcost flag should be ignored'); END IF; - RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); + -- skipping results comparable with pgr_dijkstraVia + IF (restrictions_sql = 'related' AND flag = true) THEN CONTINUE WHEN + i IN (1,3,5,6,7) AND j IN (12,17); + END IF; + IF (restrictions_sql = 'related' AND flag = false) THEN CONTINUE WHEN + (i=1 AND j IN (8,9,12,17)) OR + (i=3 AND j IN (8,9,12,17)) OR + (i IN (5,6) AND j IN (1,3)) OR + (i=7 AND j IN (12,17)); + END IF; - -- test when there is NO reverse cost and its marked NOT being used - -- VS dijkstra autodetected DOES NOT have reverse cost - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost::text - FROM pgr_dijkstra( ' || no_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ')'; - trsp_sql := 'SELECT seq, id1, id2, cost::text from pgr_trsp( ' || no_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ', FALSE)'; - msg := k || '-3 ' || directed || ', NO reverse_cost, marked as NOT being used: from ' || i || ' to ' || j; - RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); - -- test when there is NO reverse cost and its marked AS being used - -- Uncomparable with dijkstra because dijstra uses what is given as input - trsp_sql := 'SELECT seq, id1, id2, cost::text from pgr_trsp( ' || no_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ', TRUE)'; - dijkstra_sql := 'SELECT seq-1, node::integer, edge::integer, cost::text - FROM pgr_dijkstra( ' || no_reverse_cost || ', ' || i || ', ' || j || ', ' || flag || ')'; - msg := k || '-4 ' || directed || ', NO reverse_cost, marked as NOT being used: from ' || i || ' to ' || j; + IF (restrictions_sql = 'related' AND ( + (flag = false AND (i IN (10,15) AND J IN (1,3))) OR + (flag = true AND ( + (i IN (5,6,10,15) AND J IN (1,3)) OR + (i IN (5,6,7,8,9,11) AND J IN (10,15)) OR + (i IN (10) AND J IN (15)) + )) + )) + THEN + k := k + 1; + ELSE + dijkstra_sql := 'SELECT seq, node, edge FROM pgr_dijkstra($$with_reverse_cost$$, ' || params || ')'; + trsp_sql := 'SELECT seq, node, edge FROM pgr_trsp($$with_reverse_cost$$, $$' || restrictions_sql ||'$$, ' || params || ')'; + msg := restrictions_sql || '-' || params || '-reverse_cost ' || dijkstra_sql || '; ' || trsp_sql; + RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); + END IF; - -- TODO should be fixed - IF NOT min_version('4.0.1') THEN - RETURN QUERY SELECT skip(1, 'has_rcost flag should be ignored, Currently No compare can be done'); + IF (restrictions_sql = 'related' AND flag = false AND + ((i IN (1,3,5,6,7,8,9,10,11,12) AND J = 15) OR (i IN (5,6) AND J IN (12,17))) + ) + THEN + k := k + 1; ELSE + dijkstra_sql := 'SELECT seq, node, edge FROM pgr_dijkstra($$no_reverse_cost$$, ' || params || ')'; + trsp_sql := 'SELECT seq, node, edge from pgr_trsp($$no_reverse_cost$$, $$' || restrictions_sql ||'$$, ' || params || ')'; + msg := restrictions_sql || '-' || params || '-no_reverse_cost ' || dijkstra_sql || '; ' || trsp_sql; RETURN QUERY SELECT set_eq(trsp_sql, dijkstra_sql, msg); END IF; - k := k + 1; END LOOP; END LOOP;