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

GSoC 2023: Yige Huang Week 3 #303

Merged
merged 12 commits into from
Jun 18, 2023
37 changes: 29 additions & 8 deletions docqueries/withPoints/doc-pgr_withPointsDD.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ SELECT * FROM pgr_withPointsDD(
-1, 3.3,
driving_side => 'r',
details => true);
seq | start_vid | node | edge | cost | agg_cost
-----+-----------+------+------+------+----------
1 | -1 | -1 | -1 | 0 | 0
2 | -1 | 5 | 1 | 0.4 | 0.4
3 | -1 | 6 | 1 | 1 | 1.4
4 | -1 | -6 | 4 | 0.7 | 2.1
5 | -1 | 7 | 4 | 0.3 | 2.4
seq | node | edge | cost | agg_cost
-----+------+------+------+----------
1 | -1 | -1 | 0 | 0
2 | 5 | 1 | 0.4 | 0.4
3 | 6 | 1 | 1 | 1.4
4 | -6 | 4 | 0.7 | 2.1
5 | 7 | 4 | 0.3 | 2.4
(5 rows)

/* -- q3 */
Expand All @@ -44,6 +44,27 @@ SELECT * FROM pgr_withPointsDD(
(12 rows)

/* -- q4 */
SELECT * FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 3.3,
driving_side => 'b',
details => true);
seq | node | edge | cost | agg_cost
-----+------+------+------+----------
1 | -1 | -1 | 0 | 0
2 | 5 | 1 | 0.4 | 0.4
3 | 6 | 1 | 0.6 | 0.6
4 | -6 | 4 | 0.7 | 1.3
5 | 7 | 4 | 0.3 | 1.6
6 | 3 | 7 | 1 | 2.6
7 | 8 | 10 | 1 | 2.6
8 | 11 | 8 | 1 | 2.6
9 | -3 | 12 | 0.6 | 3.2
10 | -4 | 6 | 0.7 | 3.3
(10 rows)

/* -- q5 */
SELECT * FROM pgr_withPointsDD(
$e$ SELECT * FROM edges $e$,
$p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
Expand Down Expand Up @@ -80,6 +101,6 @@ SELECT * FROM pgr_withPointsDD(
21 | -2 | 17 | 13 | 1 | 2.1
(21 rows)

/* -- q5 */
/* -- q6 */
ROLLBACK;
ROLLBACK
9 changes: 8 additions & 1 deletion docqueries/withPoints/doc-pgr_withPointsDD.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ SELECT * FROM pgr_withPointsDD(
driving_side => 'l',
equicost => true);
/* -- q4 */
SELECT * FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 3.3,
driving_side => 'b',
details => true);
/* -- q5 */
SELECT * FROM pgr_withPointsDD(
$e$ SELECT * FROM edges $e$,
$p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
Expand All @@ -27,4 +34,4 @@ SELECT * FROM pgr_withPointsDD(
ARRAY[-1, -2], 2.3,
driving_side => 'r',
details => true);
/* -- q5 */
/* -- q6 */
79 changes: 79 additions & 0 deletions include/drivers/driving_distance/v6withPoints_dd_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*PGR-GNU*****************************************************************
File: withPoints_driver.h

Copyright (c) 2015 pgRouting developers
Mail: project@pgrouting.org

Function's developer:
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail: vicky at erosion.dev

Copyright (c) 2023 Yige Huang
Mail: square1ge at gmail.com

------

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_DRIVERS_DRIVING_DISTANCE_V6WITHPOINTS_DD_DRIVER_H_
#define INCLUDE_DRIVERS_DRIVING_DISTANCE_V6WITHPOINTS_DD_DRIVER_H_
#pragma once

/* for size-t */
#ifdef __cplusplus
# include <cstddef>
# include <cstdint>
using Point_on_edge_t = struct Point_on_edge_t;
using Edge_t = struct Edge_t;
using Path_rt = struct Path_rt;
#else
# include <stddef.h>
# include <stdint.h>
typedef struct Point_on_edge_t Point_on_edge_t;
typedef struct Edge_t Edge_t;
typedef struct Path_rt Path_rt;
#endif

#ifdef __cplusplus
extern "C" {
#endif

char estimate_drivingSide_dd(
char,
bool,
char**);


void do_withPointsDD(
Edge_t*, size_t,
Point_on_edge_t*, size_t,
Edge_t*, size_t,

int64_t*, size_t,
double, char,

bool, bool, bool,

Path_rt**, size_t*,
char**, char**, char **);


#ifdef __cplusplus
}
#endif

#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_V6WITHPOINTS_DD_DRIVER_H_
29 changes: 12 additions & 17 deletions include/drivers/driving_distance/withPoints_dd_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Mail: project@pgrouting.org

Function's developer:
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail:
Mail: vicky at erosion.dev

------

Expand Down Expand Up @@ -51,22 +51,17 @@ extern "C" {


void do_pgr_many_withPointsDD(
Edge_t *edges, size_t total_edges,
Point_on_edge_t *points_p, size_t total_points,
Edge_t *edges_of_points, size_t total_edges_of_points,

int64_t *start_pids_arr, size_t s_len,
double distance,

bool directed,
char driving_side,
bool details,
bool equiCost,

Path_rt **return_tuples, size_t *return_count,
char** log_msg,
char** notice_msg,
char ** err_msg);
Edge_t*, size_t,
Point_on_edge_t*, size_t,
Edge_t*, size_t,

int64_t*, size_t,
double,

bool, char, bool, bool,

Path_rt**, size_t*,
char**, char**, char **);


#ifdef __cplusplus
Expand Down
81 changes: 65 additions & 16 deletions pgtap/withPoints/withPointsDD/edge_cases/issue_979.pg
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,53 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

BEGIN;

SELECT PLAN(4);
SELECT PLAN(6);


---
--- DIRECTED GRAPH
---
-------- both driving sides

PREPARE q1 AS
SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 6.8, driving_side := 'b', details := false)
ORDER BY seq;


SELECT
node::BIGINT, edge::BIGINT, round(cost, 12) AS cost, round(agg_cost, 12) AS agg_cost
INTO test1
FROM
(VALUES
( -1 , -1 , 0 , 0),
( 1 , 1 , 0.4 , 0.4),
( 2 , 1 , 0.6 , 0.6),
( 5 , 4 , 1 , 1.6),
( 6 , 8 , 1 , 2.6),
( 8 , 7 , 1 , 2.6),
( 10 , 10 , 1 , 2.6),
( 7 , 6 , 1 , 3.6),
( 9 , 9 , 1 , 3.6),
( 11 , 11 , 1 , 3.6),
( 13 , 14 , 1 , 3.6),
( 4 , 16 , 1 , 4.6),
( 12 , 13 , 1 , 4.6),
( 3 , 3 , 1 , 5.6)
) AS t (node, edge, cost, agg_cost);


SELECT set_eq('q1',
$$SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test1$$,
'Should be aggregating individual costs: both driving sides, DIR');



-------- right driving side

PREPARE q1 AS
PREPARE q2 AS
SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
Expand All @@ -39,7 +75,7 @@ SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12

SELECT
node::BIGINT, edge::BIGINT, cost::FLOAT, agg_cost::FLOAT
INTO test1
INTO test2
FROM
(VALUES
( -1 , -1 , 0 , 0),
Expand All @@ -59,13 +95,13 @@ FROM
) AS t (node, edge, cost, agg_cost);


SELECT set_eq('q1',
$$SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test1$$,
SELECT set_eq('q2',
$$SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test2$$,
'Should be aggregating individual costs: right driving side, DIR');

-------- left driving side

PREPARE q2 AS
PREPARE q3 AS
SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
Expand All @@ -75,7 +111,7 @@ ORDER BY seq;

SELECT
node::BIGINT, edge::BIGINT, cost::FLOAT, agg_cost::FLOAT
INTO test2
INTO test3
FROM
(VALUES
(-1 , -1 , 0 , 0),
Expand All @@ -95,8 +131,8 @@ FROM
) AS t (node, edge, cost, agg_cost);


SELECT set_eq('q2',
$$SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test2$$,
SELECT set_eq('q3',
$$SELECT node, edge, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test3$$,
'Should be aggregating individual costs: left driving side, DIR');

---
Expand All @@ -106,7 +142,7 @@ SELECT set_eq('q2',
-- all results on udirected graph are "allegedly" equal
SELECT
node::BIGINT, cost::FLOAT, agg_cost::FLOAT
INTO test3
INTO test4
FROM
(VALUES
( -1 , 0 , 0),
Expand All @@ -125,31 +161,44 @@ FROM
( 12 , 1 , 4.6)
) AS t (node, cost, agg_cost);

-------- both driving sides

PREPARE q4 AS
SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 6.8, driving_side := 'b', details := false, directed:=false);

SELECT set_eq('q4',
$$SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test4$$,
'Should be aggregating individual costs: both driving sides, UNDI');



-------- right driving side

PREPARE q4 AS
PREPARE q5 AS
SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 6.8, driving_side := 'r', details := false, directed:=false);


SELECT set_eq('q4',
$$SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test3$$,
SELECT set_eq('q5',
$$SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test4$$,
'Should be aggregating individual costs: right driving side, UNDI');

-------- left driving side

PREPARE q5 AS
PREPARE q6 AS
SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM pgr_withPointsDD(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 6.8, driving_side := 'l', details := false, directed:=false);


SELECT set_eq('q5',
$$SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test3$$,
SELECT set_eq('q6',
$$SELECT node, round(cost::numeric, 12) AS cost, round(agg_cost::numeric, 12) AS agg_cost FROM test4$$,
'Should be aggregating individual costs: left driving side, UNDI');

SELECT * FROM finish();
Expand Down