Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degree update #2518

Merged
merged 12 commits into from
May 21, 2023
1 change: 1 addition & 0 deletions .github/workflows/update-locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
contents: write # for Git to git push
name: Update Locale
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'pgRouting' }}

strategy:
fail-fast: false
Expand Down
26 changes: 25 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
pgRouting 3.5.1 Release Notes
-------------------------------------------------------------------------------

No Changes Yet
To see all issues & pull requests closed by this release see the `Git closed
milestone for 3.5.1
<https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.5.1%22>`_

**Documentation fixes**

Changes on the documentation to the following:

* pgr_degree
* pgr_dijkstra
* pgr_ksp
* Automatic page history links

* using bootstrap_version 2 because 3+ does not do dropdowns


**Build fixes**

* Fix winnie build

**Code fixes**

* Fix clang warnings

* Grouping headers of postgres readers

pgRouting 3.5.0 Release Notes
-------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/dijkstra/pgr_dijkstra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

* Standarizing output columns to |short-generic-result|

* ``pgr_dijkstra`` (`One to One`_) added `start_vid` and `end_vid` columns.
* ``pgr_dijkstra`` (`One to Many`_) added `end_vid` column.
* ``pgr_dijkstra`` (`Many to One`_) added `start_vid` column.
* ``pgr_dijkstra`` (`One to One`_) added ``start_vid`` and ``end_vid`` columns.
* ``pgr_dijkstra`` (`One to Many`_) added ``end_vid`` column.
* ``pgr_dijkstra`` (`Many to One`_) added ``start_vid`` column.

* Version 3.1.0

Expand Down
26 changes: 25 additions & 1 deletion doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,31 @@ To see the full list of changes check the list of `Git commits
pgRouting 3.5.1 Release Notes
-------------------------------------------------------------------------------

No Changes Yet
To see all issues & pull requests closed by this release see the `Git closed
milestone for 3.5.1
<https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.5.1%22>`_

.. rubric:: Documentation fixes

Changes on the documentation to the following:

* pgr_degree
* pgr_dijkstra
* pgr_ksp
* Automatic page history links

* using bootstrap_version 2 because 3+ does not do dropdowns


.. rubric:: Build fixes

* Fix winnie build

.. rubric:: Code fixes

* Fix clang warnings

* Grouping headers of postgres readers

pgRouting 3.5.0 Release Notes
-------------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion doc/topology/pgr_degree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
``pgr_degree`` -- Proposed
===============================================================================

``pgr_degree`` — Calculates the vertices degree
``pgr_degree`` — For each vertex in an undirected graph, return the count of edges incident to the vertex.


.. include:: proposed.rst
Expand Down Expand Up @@ -49,6 +49,10 @@ Signatures

:Example: Extracting the vertex information

pgr_degree can utilize output from `pgr_extractVertices` or can have `pgr_extractVertices` embedded in the call.
For decent size networks, it is best to prep your vertices table before hand and use that vertices table
for pgr_degree calls.

.. literalinclude:: degree.queries
:start-after: -- q1
:end-before: -- q2
Expand Down Expand Up @@ -171,6 +175,10 @@ development needs.

Degree from an existing table
...............................................................................
If you have a vertices table already built using ``pgr_extractVertices``
and want the degree of the whole graph rather than a subset, you can forgo using pgr_degree
and work with the ``in_edges`` and ``out_edges`` columns directly.


.. include:: pgRouting-concepts.rst
:start-after: degree_from_table_start
Expand Down
2 changes: 1 addition & 1 deletion doc/topology/topology-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ have special permissions given by the administrators to use them.

These proposed functions do not modify the database.

- :doc:`pgr_degree` - Calculates the degree of the vertices of a graph.
- :doc:`pgr_degree` - Returns a set of vertices and corresponding count of incidet edges to the vertex.
- :doc:`pgr_extractVertices` - Extracts vertex information based on the edge
table information.

Expand Down
207 changes: 107 additions & 100 deletions docqueries/topology/degree.result
Original file line number Diff line number Diff line change
@@ -1,100 +1,107 @@
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
/* -- q1 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$);
node | degree
------+--------
1 | 1
2 | 1
3 | 2
4 | 1
5 | 1
6 | 3
7 | 4
8 | 3
9 | 1
10 | 3
11 | 4
12 | 3
13 | 1
14 | 1
15 | 2
16 | 3
17 | 2
(17 rows)

/* -- q2 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges WHERE id < 17$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$);
node | degree
------+--------
1 | 1
2 | 0
3 | 2
4 | 0
5 | 1
6 | 3
7 | 4
8 | 3
9 | 1
10 | 3
11 | 4
12 | 3
13 | 0
14 | 0
15 | 2
16 | 3
17 | 2
(17 rows)

/* -- q3 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges WHERE id < 17$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$,
dryrun => true);
NOTICE:
WITH

-- a sub set of edges of the graph goes here
g_edges AS (
SELECT id FROM edges WHERE id < 17
),

-- sub set of vertices of the graph goes here
all_vertices AS (
SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')
),

g_vertices AS (
SELECT id,
unnest(
coalesce(in_edges::BIGINT[], '{}'::BIGINT[])
||
coalesce(out_edges::BIGINT[], '{}'::BIGINT[])) AS eid
FROM all_vertices
),

totals AS (
SELECT v.id, count(*)
FROM g_vertices AS v
JOIN g_edges AS e ON (e.id = eid) GROUP BY v.id
)

SELECT id::BIGINT, coalesce(count, 0)::BIGINT FROM all_vertices LEFT JOIN totals USING (id)
;
node | degree
------+--------
(0 rows)

/* -- q4 */
ROLLBACK;
ROLLBACK
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
/* -- q1 */
DROP TABLE IF EXISTS tmp_edges_vertices_pgr;
NOTICE: table "tmp_edges_vertices_pgr" does not exist, skipping
DROP TABLE
CREATE TEMP TABLE tmp_edges_vertices_pgr AS
SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges');
SELECT 17
SELECT * FROM pgr_degree(
$$SELECT id FROM edges$$,
$$SELECT id, in_edges, out_edges
FROM tmp_edges_vertices_pgr$$);
node | degree
------+--------
1 | 1
2 | 1
3 | 2
4 | 1
5 | 1
6 | 3
7 | 4
8 | 3
9 | 1
10 | 3
11 | 4
12 | 3
13 | 1
14 | 1
15 | 2
16 | 3
17 | 2
(17 rows)

/* -- q2 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges WHERE id < 17$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$);
node | degree
------+--------
1 | 1
2 | 0
3 | 2
4 | 0
5 | 1
6 | 3
7 | 4
8 | 3
9 | 1
10 | 3
11 | 4
12 | 3
13 | 0
14 | 0
15 | 2
16 | 3
17 | 2
(17 rows)

/* -- q3 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges WHERE id < 17$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$,
dryrun => true);
NOTICE:
WITH

-- a sub set of edges of the graph goes here
g_edges AS (
SELECT id FROM edges WHERE id < 17
),

-- sub set of vertices of the graph goes here
all_vertices AS (
SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')
),

g_vertices AS (
SELECT id,
unnest(
coalesce(in_edges::BIGINT[], '{}'::BIGINT[])
||
coalesce(out_edges::BIGINT[], '{}'::BIGINT[])) AS eid
FROM all_vertices
),

totals AS (
SELECT v.id, count(*)
FROM g_vertices AS v
JOIN g_edges AS e ON (e.id = eid) GROUP BY v.id
)

SELECT id::BIGINT, coalesce(count, 0)::BIGINT FROM all_vertices LEFT JOIN totals USING (id)
;
node | degree
------+--------
(0 rows)

/* -- q4 */
ROLLBACK;
ROLLBACK
Expand Down
6 changes: 5 additions & 1 deletion docqueries/topology/degree.test.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
-- CopyRight(c) pgRouting developers
-- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/
/* -- q1 */
DROP TABLE IF EXISTS tmp_edges_vertices_pgr;
CREATE TEMP TABLE tmp_edges_vertices_pgr AS
SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges');
SELECT * FROM pgr_degree(
$$SELECT id FROM edges$$,
$$SELECT id, in_edges, out_edges
FROM pgr_extractVertices('SELECT id, geom FROM edges')$$);
FROM tmp_edges_vertices_pgr$$);
/* -- q2 */
SELECT * FROM pgr_degree(
$$SELECT id FROM edges WHERE id < 17$$,
Expand Down
Loading