Skip to content

Commit

Permalink
Merge pull request #347 from aryan1010/modifying-drivingdistance
Browse files Browse the repository at this point in the history
Modifying drivingdistance
  • Loading branch information
aryan1010 committed Aug 18, 2023
2 parents 3efc720 + 7aed773 commit 0a07331
Show file tree
Hide file tree
Showing 24 changed files with 1,009 additions and 160 deletions.
59 changes: 16 additions & 43 deletions doc/driving_distance/pgr_drivingDistance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
Boost Graph Inside

.. rubric:: Availability

* Version 3.6.0

* Standarizing output columns to |result-bfs|

* ``pgr_drivingdistance`` (`Single vertex`_) added ``depth`` and ``start_vid`` column.
* ``pgr_drivingdistance`` (`Multiple vertices`_) added ``depth`` column.

* Version 2.1.0:

Expand Down Expand Up @@ -49,7 +56,7 @@ Signatures
| pgr_drivingDistance(`Edges SQL`_, **Root vids**, **distance**, [**options**])
| **options:** [directed, equicost]
| RETURNS SET OF |result-dij-dd|
| RETURNS SET OF |result-bfs|
.. index::
single: drivingDistance(Single vertex)
Expand All @@ -62,11 +69,11 @@ Single Vertex

| pgr_drivingDistance(`Edges SQL`_, **Root vid**, **distance**, [``directed``])
| RETURNS SET OF |result-1-1|
| RETURNS SET OF |result-bfs|
:Example: From vertex :math:`11` for a distance of :math:`3.0`

.. literalinclude:: doc-pgr_drivingDistance.queries
.. literalinclude:: pgr_drivingDistance.queries
:start-after: --q5
:end-before: --q6

Expand All @@ -82,12 +89,12 @@ Multiple Vertices
| pgr_drivingDistance(`Edges SQL`_, **Root vids**, **distance**, [**options**])
| **options:** [directed, equicost]
| RETURNS SET OF |result-dij-dd-m|
| RETURNS SET OF |result-bfs|
:Example: From vertices :math:`\{11, 16\}` for a distance of :math:`3.0` with
equi-cost on a directed graph

.. literalinclude:: doc-pgr_drivingDistance.queries
.. literalinclude:: pgr_drivingDistance.queries
:start-after: --q6
:end-before: --q10

Expand Down Expand Up @@ -142,51 +149,17 @@ Edges SQL
Result Columns
-------------------------------------------------------------------------------

Returns SET OF ``(seq, from_v, node, edge, cost, agg_cost)``

.. list-table::
:width: 81
:widths: auto
:header-rows: 1

* - Parameter
- Type
- Description
* - ``seq``
- ``BIGINT``
- Sequential value starting from :math:`1`.
* - ``[from_v]``
- ``BIGINT``
- Identifier of the root vertex.

* - ``node``
- ``BIGINT``
- Identifier of ``node`` within the limits from ``from_v``.
* - ``edge``
- ``BIGINT``
- Identifier of the ``edge`` used to arrive to ``node``.

- :math:`0` when ``node`` = ``from_v``.

* - ``cost``
- ``FLOAT``
- Cost to traverse ``edge``.
* - ``agg_cost``
- ``FLOAT``
- Aggregate cost from ``from_v`` to ``node``.

Where:

:ANY-INTEGER: SMALLINT, INTEGER, BIGINT
:ANY-NUMERIC: SMALLINT, INTEGER, BIGINT, REAL, FLOAT, NUMERIC
.. include:: BFS-category.rst
:start-after: mst-bfs-dfs-dd-result-columns-start
:end-before: mst-bfs-dfs-dd-result-columns-end

Additional Examples
-------------------------------------------------------------------------------

:Example: From vertices :math:`\{11, 16\}` for a distance of :math:`3.0` on an
undirected graph

.. literalinclude:: doc-pgr_drivingDistance.queries
.. literalinclude:: pgr_drivingDistance.queries
:start-after: --q10
:end-before: --q15

Expand Down
49 changes: 49 additions & 0 deletions doc/src/migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Results can be different because of the changes.

Migrating functions:

:doc:`pgr_drivingDistance` signatures have changed, with the addition of new columns
in the new signatures.

:doc:`pgr_withPointsDD` signatures have changed, with the addition of new columns
in the new signatures. It works mainly for driving cases, therefore the ``driving side``
parameter changed from optional to compulsory, and its valid values differ for
Expand All @@ -43,6 +46,52 @@ Migration of functions that add new columns
.. contents:: Contents
:local:

Migration of ``pgr_drivingdistance``
-------------------------------------------------------------------------------

Starting from `v3.6.0 <https://docs.pgrouting.org/3.6/en/migration.html>`__

Signatures to be migrated:

* ``pgr_drivingdistance`` (`Single vertex`)
* ``pgr_drivingdistance`` (`Multiple vertices`)

:Before Migration:

* Output columns were |result-dij-dd-m|

* Depending on the vertices, the column ``start_vid`` might be missing and the depth column is not in any one of them:

* ``pgr_drivingdistance`` (`Single vertex`) does not have ``start_vid`` and ``depth``.
* ``pgr_drivingdistance`` (`Multiple vertices`) does not have ``depth``.

:Migration:

* Be aware of the existance of the additional columns.

* In ``pgr_drivingdistance`` (`Single vertex`)

* ``start_vid`` contains the **start vid** parameter value.
* ``depth`` contains the **depth** parameter value.

.. literalinclude:: migration.queries
:start-after: --drivingdistance1
:end-before: --drivingdistance2

* In ``pgr_drivingdistance`` (`Multiple vertices`)

* ``depth`` contains the **depth** parameter value.

.. literalinclude:: migration.queries
:start-after: --drivingdistance2
:end-before: --drivingdistance3

* If needed filter out the added columns, for example:

.. literalinclude:: migration.queries
:start-after: --drivingdistance3
:end-before: --drivingdistance4

Migration of ``pgr_withPointsDD``
-------------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions doc/src/pgRouting-introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This Release Contributors
Individuals in this release (in alphabetical order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Aryan Gupta,
Ashish Kumar,
Cayetano Benavent,
Daniel Kastl,
Expand Down Expand Up @@ -106,6 +107,7 @@ Akio Takubo,
Andrea Nardelli,
Anthony Tasca,
Anton Patrushev,
Aryan Gupta,
Ashraf Hossain,
Ashish Kumar,
Cayetano Benavent,
Expand Down
2 changes: 1 addition & 1 deletion docqueries/driving_distance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Do not use extensions
SET(LOCAL_FILES
doc-pgr_drivingDistance
pgr_drivingDistance
)

foreach (f ${LOCAL_FILES})
Expand Down
35 changes: 19 additions & 16 deletions docqueries/driving_distance/dijksraDD-issue729.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@ UPDATE edges AS edge_table
SET node_count=count.sum
FROM
(SELECT
from_v,
start_vid,
sum(node) AS sum
FROM
pgr_drivingDistance(
'SELECT id, source, target, ST_Length(geom) AS cost FROM edges',
ARRAY(SELECT DISTINCT source FROM edges),
1,
false)
GROUP BY from_v) AS count
WHERE edges.source=count.from_v
GROUP BY start_vid) AS count
WHERE edge_table.source=count.start_vid
;
ERROR: invalid reference to FROM-clause entry for table "edges"
LINE 14: WHERE edges.source=count.from_v
^
HINT: Perhaps you meant to reference the table alias "edge_table".
UPDATE 16
ALTER TABLE edges
DROP COLUMN IF EXISTS another_column,
ADD COLUMN another_column INTEGER;
ERROR: current transaction is aborted, commands ignored until end of transaction block
NOTICE: column "another_column" of relation "edges" does not exist, skipping
ALTER TABLE
DROP TABLE IF EXISTS network;
ERROR: current transaction is aborted, commands ignored until end of transaction block
NOTICE: table "network" does not exist, skipping
DROP TABLE
CREATE TABLE network AS
SELECT *
from (
Expand All @@ -41,30 +40,34 @@ from (
(3::int, 3::int, 4::int, 100::int),
(4::int, 5::int, 6::int, 100::int)
) as t (id, source,target,cost);
ERROR: current transaction is aborted, commands ignored until end of transaction block
SELECT 4
ALTER TABLE network
DROP COLUMN IF EXISTS node_count,
ADD COLUMN node_count INTEGER;
ERROR: current transaction is aborted, commands ignored until end of transaction block
NOTICE: column "node_count" of relation "network" does not exist, skipping
ALTER TABLE
UPDATE network AS network
SET node_count=count.sum
FROM
(SELECT
from_v,
start_vid,
sum(node) AS sum
FROM
pgr_drivingDistance(
'SELECT id, source, target, cost FROM network',
ARRAY(SELECT DISTINCT source FROM network),
1,
false)
GROUP BY from_v) AS count
WHERE network.source=count.from_v
GROUP BY start_vid) AS count
WHERE network.source=count.start_vid
;
ERROR: current transaction is aborted, commands ignored until end of transaction block
NOTICE:
No return values were found
UPDATE 0
ALTER TABLE network
DROP COLUMN IF EXISTS another_column,
ADD COLUMN another_column INTEGER;
ERROR: current transaction is aborted, commands ignored until end of transaction block
NOTICE: column "another_column" of relation "network" does not exist, skipping
ALTER TABLE
ROLLBACK;
ROLLBACK
12 changes: 6 additions & 6 deletions docqueries/driving_distance/dijksraDD-issue729.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ UPDATE edges AS edge_table
SET node_count=count.sum
FROM
(SELECT
from_v,
start_vid,
sum(node) AS sum
FROM
pgr_drivingDistance(
'SELECT id, source, target, ST_Length(geom) AS cost FROM edges',
ARRAY(SELECT DISTINCT source FROM edges),
1,
false)
GROUP BY from_v) AS count
WHERE edges.source=count.from_v
GROUP BY start_vid) AS count
WHERE edge_table.source=count.start_vid
;

ALTER TABLE edges
Expand All @@ -46,16 +46,16 @@ UPDATE network AS network
SET node_count=count.sum
FROM
(SELECT
from_v,
start_vid,
sum(node) AS sum
FROM
pgr_drivingDistance(
'SELECT id, source, target, cost FROM network',
ARRAY(SELECT DISTINCT source FROM network),
1,
false)
GROUP BY from_v) AS count
WHERE network.source=count.from_v
GROUP BY start_vid) AS count
WHERE network.source=count.start_vid
;

ALTER TABLE network
Expand Down
80 changes: 80 additions & 0 deletions docqueries/driving_distance/pgr_drivingDistance.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
/* --q5 */
SELECT * FROM pgr_drivingDistance(
'SELECT id, source, target, cost, reverse_cost FROM edges',
11, 3.0);
seq | depth | start_vid | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+----------
1 | 0 | 11 | 11 | -1 | 0 | 0
2 | 1 | 11 | 7 | 8 | 1 | 1
3 | 1 | 11 | 12 | 11 | 1 | 1
4 | 1 | 11 | 16 | 9 | 1 | 1
5 | 2 | 11 | 3 | 7 | 1 | 2
6 | 2 | 11 | 6 | 4 | 1 | 2
7 | 2 | 11 | 8 | 10 | 1 | 2
8 | 2 | 11 | 15 | 16 | 1 | 2
9 | 2 | 11 | 17 | 15 | 1 | 2
10 | 3 | 11 | 1 | 6 | 1 | 3
11 | 3 | 11 | 5 | 1 | 1 | 3
12 | 3 | 11 | 9 | 14 | 1 | 3
13 | 3 | 11 | 10 | 3 | 1 | 3
(13 rows)

/* --q6 */
SELECT * FROM pgr_drivingDistance(
'SELECT id, source, target, cost, reverse_cost FROM edges',
array[11, 16], 3.0, equicost => true);
seq | depth | start_vid | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+----------
1 | 0 | 11 | 11 | -1 | 0 | 0
2 | 1 | 11 | 7 | 8 | 1 | 1
3 | 1 | 11 | 12 | 11 | 1 | 1
4 | 2 | 11 | 3 | 7 | 1 | 2
5 | 2 | 11 | 6 | 4 | 1 | 2
6 | 2 | 11 | 8 | 10 | 1 | 2
7 | 3 | 11 | 1 | 6 | 1 | 3
8 | 3 | 11 | 5 | 1 | 1 | 3
9 | 3 | 11 | 9 | 14 | 1 | 3
10 | 0 | 16 | 16 | -1 | 0 | 0
11 | 1 | 16 | 15 | 16 | 1 | 1
12 | 1 | 16 | 17 | 15 | 1 | 1
13 | 2 | 16 | 10 | 3 | 1 | 2
(13 rows)

/* --q10 */
SELECT * FROM pgr_drivingDistance(
'SELECT id, source, target, cost, reverse_cost FROM edges',
array[11, 16], 3.0, directed => false);
seq | depth | start_vid | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+----------
1 | 0 | 11 | 11 | -1 | 0 | 0
2 | 1 | 11 | 7 | 8 | 1 | 1
3 | 1 | 11 | 10 | 5 | 1 | 1
4 | 1 | 11 | 12 | 11 | 1 | 1
5 | 1 | 11 | 16 | 9 | 1 | 1
6 | 2 | 11 | 3 | 7 | 1 | 2
7 | 2 | 11 | 6 | 2 | 1 | 2
8 | 2 | 11 | 8 | 10 | 1 | 2
9 | 2 | 11 | 15 | 3 | 1 | 2
10 | 2 | 11 | 17 | 15 | 1 | 2
11 | 3 | 11 | 1 | 6 | 1 | 3
12 | 3 | 11 | 5 | 1 | 1 | 3
13 | 3 | 11 | 9 | 14 | 1 | 3
14 | 0 | 16 | 16 | -1 | 0 | 0
15 | 1 | 16 | 11 | 9 | 1 | 1
16 | 1 | 16 | 15 | 16 | 1 | 1
17 | 1 | 16 | 17 | 15 | 1 | 1
18 | 2 | 16 | 7 | 8 | 1 | 2
19 | 2 | 16 | 10 | 5 | 1 | 2
20 | 2 | 16 | 12 | 13 | 1 | 2
21 | 3 | 16 | 3 | 7 | 1 | 3
22 | 3 | 16 | 6 | 4 | 1 | 3
23 | 3 | 16 | 8 | 10 | 1 | 3
(23 rows)

/* --q15 */
ROLLBACK;
ROLLBACK
Loading

0 comments on commit 0a07331

Please sign in to comment.