Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 198 additions & 102 deletions docqueries/withPoints/doc-pgr_withPointsKSP.result

Large diffs are not rendered by default.

44 changes: 32 additions & 12 deletions docqueries/withPoints/doc-pgr_withPointsKSP.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ SET extra_float_digits=-3;
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -2, 2);
-1, -2, 2, 'l');
/* --q2 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -2, 2,
driving_side := 'l', details := true);
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, ARRAY[-3, 7], 2, 'B',
directed => false);
/* --q3 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -2, 2,
heap_paths := true, driving_side := 'r', details := true);
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], -3, 1,'r', details:= true);
/* --q4 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], ARRAY[-3, 1], 1, 'l', heap_paths:= true);
/* --q5 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
'SELECT * FROM (VALUES (-1, 10), (6, -3)) AS combinations(source, target)',
2, 'r', details => true);
/* --q6 */
SELECT * FROM pgr_withPointsKSP(
$e$ SELECT * FROM edges $e$,
$p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
Expand All @@ -27,6 +37,16 @@ SELECT * FROM pgr_withPointsKSP(
(SELECT ST_POINT(2.9, 1.8)),
0.5, cap => 2)
$p$,
1, -1, 2,
driving_side := 'r');
/* -- q5 */
1, -1, 2,'r');
/* --q7 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -3, 2, 'l', details := true);
/* --q8 */
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -2, 2, 'r',
heap_paths := true, details := true);
/* --q9 */
4 changes: 2 additions & 2 deletions include/cpp_common/basePath_SSEC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class Path {

void get_pg_ksp_path(
Path_rt **ret_path,
size_t &sequence) const;
size_t &sequence, int routeId) const;

void get_pg_withPointsKSP_path(
void get_pg_nksp_path(
Path_rt **ret_path,
size_t &sequence) const;

Expand Down
4 changes: 4 additions & 0 deletions sql/scripts/build-extension-update-files.pl
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ sub generate_upgrade_script {

# updating to 3.6+
if ($old_mayor == 2 or $old_minor < 6) {
push @commands, drop_special_case_function("pgr_withpointsksp(text, text, bigint, bigint, integer, boolean, boolean, char, boolean)");
push @commands, drop_special_case_function("pgr_astar(text,anyarray,bigint,boolean,integer,double precision,double precision)");
push @commands, drop_special_case_function("pgr_astar(text,bigint,anyarray,boolean,integer,double precision,double precision)");
push @commands, drop_special_case_function("pgr_astar(text,bigint,bigint,boolean,integer,double precision,double precision)");
push @commands, drop_special_case_function("pgr_bdastar(text,bigint,bigint,boolean,integer,numeric,numeric)");
push @commands, drop_special_case_function("pgr_bdastar(text,bigint,anyarray,boolean,integer,numeric,numeric)");
push @commands, drop_special_case_function("pgr_bdastar(text,anyarray,bigint,boolean,integer,numeric,numeric)");
}

}
Expand Down
18 changes: 18 additions & 0 deletions src/common/basePath_SSEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ void Path::get_pg_dd_path(

/* used by ksp */
void Path::get_pg_ksp_path(
Path_rt **ret_path,
size_t &sequence, int routeId) const {
for (unsigned int i = 0; i < path.size(); i++) {
(*ret_path)[sequence].seq = static_cast<int>(i + 1);
(*ret_path)[sequence].start_id = routeId;
(*ret_path)[sequence].end_id = end_id();
(*ret_path)[sequence].node = path[i].node;
(*ret_path)[sequence].edge = path[i].edge;
(*ret_path)[sequence].cost = path[i].cost;
(*ret_path)[sequence].agg_cost = (i == 0)?
0 :
(*ret_path)[sequence-1].agg_cost + path[i-1].cost;
sequence++;
}
}

/* used by new ksp */
void Path::get_pg_nksp_path(
Path_rt **ret_path,
size_t &sequence) const {
for (unsigned int i = 0; i < path.size(); i++) {
Expand Down
13 changes: 1 addition & 12 deletions src/ksp/ksp.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,14 @@ _pgr_ksp(PG_FUNCTION_ARGS) {
nulls[i] = false;
}

int64_t path_id = 1;
if (funcctx->call_cntr != 0) {
if (path[funcctx->call_cntr - 1].edge == -1) {
path_id = path[funcctx->call_cntr - 1].start_id + 1;
} else {
path_id = path[funcctx->call_cntr - 1].start_id;
}
}

values[0] = Int32GetDatum(funcctx->call_cntr + 1);
values[1] = Int32GetDatum(path_id);
values[1] = Int32GetDatum(path[funcctx->call_cntr].start_id + 1);
values[2] = Int32GetDatum(path[funcctx->call_cntr].seq);
values[3] = Int64GetDatum(path[funcctx->call_cntr].node);
values[4] = Int64GetDatum(path[funcctx->call_cntr].edge);
values[5] = Float8GetDatum(path[funcctx->call_cntr].cost);
values[6] = Float8GetDatum(path[funcctx->call_cntr].agg_cost);

path[funcctx->call_cntr].start_id = path_id;

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
Expand Down
4 changes: 3 additions & 1 deletion src/ksp/ksp_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ void do_pgr_ksp(
*return_tuples = pgr_alloc(count, (*return_tuples));

size_t sequence = 0;
int route_id = 0;
for (const auto &path : paths) {
if (path.size() > 0)
path.get_pg_ksp_path(return_tuples, sequence);
path.get_pg_ksp_path(return_tuples, sequence, route_id);
++route_id;
}
}
*return_count = count;
Expand Down
14 changes: 2 additions & 12 deletions src/ksp/withPoints_ksp.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,25 +501,15 @@ PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) {


// postgres starts counting from 1
int64_t path_id = 1;
if (funcctx->call_cntr != 0) {
if (result_tuples[funcctx->call_cntr - 1].edge == -1) {
path_id = result_tuples[funcctx->call_cntr - 1].start_id + 1;
} else {
path_id = result_tuples[funcctx->call_cntr - 1].start_id;
}
}

values[0] = Int32GetDatum(funcctx->call_cntr + 1);
values[1] = Int32GetDatum(path_id);
values[1] = Int32GetDatum((int)
(result_tuples[funcctx->call_cntr].start_id + 1));
values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);

result_tuples[funcctx->call_cntr].start_id = path_id;

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
Expand Down
2 changes: 1 addition & 1 deletion src/ksp/withPoints_ksp_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pgr_do_withPointsKsp(
size_t sequence = 0;
for (const auto &path : paths) {
if (path.size() > 0)
path.get_pg_ksp_path(return_tuples, sequence);
path.get_pg_nksp_path(return_tuples, sequence);
}

if (count != sequence) {
Expand Down