Skip to content

Commit

Permalink
changes suggested by vicky
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhinJ committed Aug 20, 2023
1 parent 77fde6f commit 2b38016
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 35 deletions.
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
2 changes: 1 addition & 1 deletion sql/scripts/build-extension-update-files.pl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ 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_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)");
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
15 changes: 2 additions & 13 deletions src/ksp/ksp.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,18 @@ _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);
} else { /* do when there is no more left */
SRF_RETURN_DONE(funcctx);
}
}
}
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
22 changes: 5 additions & 17 deletions src/ksp/withPoints_ksp.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,15 @@ process(
PGR_DBG("Starting processing");
clock_t start_t = clock();

pgr_do_withPointsKsp(
do_pgr_withPointsKsp(
edges,
total_edges,
points,
total_points,
edges_of_points,
total_edges_of_points,
NULL, 0,

&start_pid, 1,
&end_pid, 1,
start_pid,
end_pid,
k,

directed,
Expand Down Expand Up @@ -501,25 +499,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

0 comments on commit 2b38016

Please sign in to comment.