Skip to content

Commit

Permalink
Dijkstra code simplification (#2521)
Browse files Browse the repository at this point in the history
* [dijkstra][C++] pgr_dijkstra.hpp -> dijkstra.hpp & using functions
* Separating Driving distance
  • Loading branch information
cvvergara authored May 29, 2023
1 parent a7e60c7 commit 7586bbf
Show file tree
Hide file tree
Showing 21 changed files with 1,072 additions and 1,193 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pgRouting 3.6.0 Release Notes
duplicate code on Dijkstra.
* `2517 <https://github.com/pgRouting/pgrouting/pull/2517>` Astar code
simplification.
* `2521 <https://github.com/pgRouting/pgrouting/pull/2521>` Dijkstra code
simplification.

**Documentation**

Expand Down
2 changes: 2 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pgRouting 3.6.0 Release Notes
duplicate code on Dijkstra.
* `2517 <https://github.com/pgRouting/pgrouting/pull/2517>` Astar code
simplification.
* `2521 <https://github.com/pgRouting/pgrouting/pull/2521>` Dijkstra code
simplification.

.. rubric:: Documentation

Expand Down
214 changes: 107 additions & 107 deletions docqueries/topology/degree.result
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
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
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
Loading

0 comments on commit 7586bbf

Please sign in to comment.