Skip to content

Commit cec5cf5

Browse files
authored
Merge pull request #327 from AbhinJ/Abhinj-week-8
GSoC 2023: Abhinav Jain week 8
2 parents 44d0125 + deb0d96 commit cec5cf5

File tree

8 files changed

+82
-35
lines changed

8 files changed

+82
-35
lines changed

include/drivers/yen/withPoints_ksp_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern "C" {
6969

7070
Path_rt**, size_t*,
7171
char**, char**, char**);
72-
72+
7373
/*TODO remove on v4*/
7474
int do_pgr_withPointsKsp(
7575
Edge_t *edges, size_t total_edges,

include/yen/pgr_ksp.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3535
#include <algorithm>
3636
#include <set>
3737
#include <limits>
38+
#include <map>
3839

3940
#include "dijkstra/dijkstra.hpp"
4041
#include "cpp_common/pgr_assert.h"
@@ -246,7 +247,7 @@ namespace algorithms {
246247
G &graph,
247248
const std::map<int64_t, std::set<int64_t>> &combinations,
248249
size_t k,
249-
bool heap_paths){
250+
bool heap_paths) {
250251
std::deque<Path> paths;
251252
pgrouting::yen::Pgr_ksp<G> fn_yen;
252253

@@ -267,7 +268,7 @@ namespace algorithms {
267268
return paths;
268269
}
269270

270-
} // namespace algorithms
271+
} // namespace algorithms
271272

272273
} // namespace pgrouting
273274

pgtap/ksp/withPointsKSP/inner_query.pg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
BEGIN;
2121

2222
UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost);
23-
SELECT plan(84);
23+
SELECT plan(168);
2424

25+
SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 2, 3, 2, $$l$$, true)');
26+
SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edge_table$$,', ', 2, 3, 2, $$r$$, true)');
27+
28+
/* TODO Remove on v4*/
2529
-- ONE TO ONE
2630
SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 2, 3, 2, true)');
2731
SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edge_table$$,', ', 2, 3, 2, true)');

pgtap/ksp/withPointsKSP/types_check.pg

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,56 @@ along with this program; if not, write to the Free Software
1818
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
********************************************************************PGR-GNU*/
2020
BEGIN;
21-
SELECT plan(5);
21+
SELECT plan(15);
2222

2323
SELECT has_function('pgr_withpointsksp');
24-
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean']);
25-
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean'],'setof record');
24+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','character','boolean','boolean','boolean']);
25+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','anyarray','integer','character','boolean','boolean','boolean']);
26+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','anyarray','bigint','integer','character','boolean','boolean','boolean']);
27+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','anyarray','anyarray','integer','character','boolean','boolean','boolean']);
28+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','text','integer','character','boolean','boolean','boolean']);
29+
30+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','character','boolean','boolean','boolean'],'setof record');
31+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','bigint','anyarray','integer','character','boolean','boolean','boolean'],'setof record');
32+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','anyarray','bigint','integer','character','boolean','boolean','boolean'],'setof record');
33+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','anyarray','anyarray','integer','character','boolean','boolean','boolean'],'setof record');
34+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','text','integer','character','boolean','boolean','boolean'],'setof record');
2635

27-
SELECT set_eq(
28-
$$SELECT proargnames from pg_proc WHERE proname = 'pgr_withpointsksp'$$,
29-
$$SELECT '{"","","","","","directed","heap_paths","driving_side","details","seq","path_id","path_seq","node","edge","cost","agg_cost"}'::TEXT[] $$
30-
);
36+
/*Remove last 1 row on v4*/
37+
SELECT CASE WHEN min_version('3.6.0')
38+
THEN collect_tap(
39+
set_eq(
40+
$$SELECT proargnames from pg_proc WHERE proname = 'pgr_withpointsksp'$$,
41+
$$VALUES
42+
('{"","","","","","","directed","heap_paths","details","seq","path_id","path_seq","start_vid","end_vid","node","edge","cost","agg_cost"}'::TEXT[]),
43+
('{"","","","","","directed","heap_paths","details","seq","path_id","path_seq","start_vid","end_vid","node","edge","cost","agg_cost"}'::TEXT[]),
44+
('{"","","","","","directed","heap_paths","driving_side","details","seq","path_id","path_seq","node","edge","cost","agg_cost"}'::TEXT[])
45+
$$),
46+
set_eq(
47+
$$SELECT proallargtypes FROM pg_proc WHERE proname = 'pgr_withpointsksp'$$,
48+
$$VALUES
49+
('{25,25,20,20,23,1042,16,16,16,23,23,23,20,20,20,20,701,701}'::OID[]),
50+
('{25,25,20,2277,23,1042,16,16,16,23,23,23,20,20,20,20,701,701}'::OID[]),
51+
('{25,25,2277,20,23,1042,16,16,16,23,23,23,20,20,20,20,701,701}'::OID[]),
52+
('{25,25,2277,2277,23,1042,16,16,16,23,23,23,20,20,20,20,701,701}'::OID[]),
53+
('{25,25,25,23,1042,16,16,16,23,23,23,20,20,20,20,701,701}'::OID[]),
54+
('{25,25,20,20,23,16,16,1042,16,23,23,23,20,20,701,701}'::OID[])
55+
$$)
56+
)
57+
ELSE collect_tap(
58+
set_eq(
59+
$$SELECT proargnames from pg_proc WHERE proname = 'pgr_withpointsksp'$$,
60+
$$SELECT '{"","","","","","directed","heap_paths","driving_side","details","seq","path_id","path_seq","node","edge","cost","agg_cost"}'::TEXT[] $$
61+
),
62+
set_eq(
63+
$$SELECT proallargtypes FROM pg_proc WHERE proname = 'pgr_withpointsksp'$$,
64+
$$SELECT '{25,25,20,20,23,16,16,1042,16,23,23,23,20,20,701,701}'::OID[] $$
65+
)
66+
)END;
3167

32-
SELECT set_eq(
33-
$$SELECT proallargtypes FROM pg_proc WHERE proname = 'pgr_withpointsksp'$$,
34-
$$SELECT '{25,25,20,20,23,16,16,1042,16,23,23,23,20,20,701,701}'::OID[] $$
35-
);
68+
/* TODO remove on v4*/
69+
SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean']);
70+
SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean'],'setof record');
3671

3772
SELECT finish();
3873
ROLLBACK;

sql/ksp/withPointsKSP.sql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ CREATE FUNCTION pgr_withPointsKSP(
4242
OUT seq INTEGER,
4343
OUT path_id INTEGER,
4444
OUT path_seq INTEGER,
45-
OUT start_vid INTEGER,
46-
OUT end_vid INTEGER,
45+
OUT start_vid BIGINT,
46+
OUT end_vid BIGINT,
4747
OUT node BIGINT,
4848
OUT edge BIGINT,
4949
OUT cost FLOAT,
@@ -74,8 +74,8 @@ CREATE FUNCTION pgr_withPointsKSP(
7474
OUT seq INTEGER,
7575
OUT path_id INTEGER,
7676
OUT path_seq INTEGER,
77-
OUT start_vid INTEGER,
78-
OUT end_vid INTEGER,
77+
OUT start_vid BIGINT,
78+
OUT end_vid BIGINT,
7979
OUT node BIGINT,
8080
OUT edge BIGINT,
8181
OUT cost FLOAT,
@@ -106,8 +106,8 @@ CREATE FUNCTION pgr_withPointsKSP(
106106
OUT seq INTEGER,
107107
OUT path_id INTEGER,
108108
OUT path_seq INTEGER,
109-
OUT start_vid INTEGER,
110-
OUT end_vid INTEGER,
109+
OUT start_vid BIGINT,
110+
OUT end_vid BIGINT,
111111
OUT node BIGINT,
112112
OUT edge BIGINT,
113113
OUT cost FLOAT,
@@ -138,8 +138,8 @@ CREATE FUNCTION pgr_withPointsKSP(
138138
OUT seq INTEGER,
139139
OUT path_id INTEGER,
140140
OUT path_seq INTEGER,
141-
OUT start_vid INTEGER,
142-
OUT end_vid INTEGER,
141+
OUT start_vid BIGINT,
142+
OUT end_vid BIGINT,
143143
OUT node BIGINT,
144144
OUT edge BIGINT,
145145
OUT cost FLOAT,
@@ -169,8 +169,8 @@ CREATE FUNCTION pgr_withPointsKSP(
169169
OUT seq INTEGER,
170170
OUT path_id INTEGER,
171171
OUT path_seq INTEGER,
172-
OUT start_vid INTEGER,
173-
OUT end_vid INTEGER,
172+
OUT start_vid BIGINT,
173+
OUT end_vid BIGINT,
174174
OUT node BIGINT,
175175
OUT edge BIGINT,
176176
OUT cost FLOAT,
@@ -290,8 +290,8 @@ RETURNS SETOF RECORD AS
290290
$BODY$
291291
BEGIN
292292
RAISE WARNING 'pgr_withPointsKSP(text,text,bigint,bigint,integer,boolean,boolean,char,boolean) deprecated on v3.6.0';
293-
SELECT *
294-
FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), $3, $4, $5, $6, $7, $8, $9);
293+
RETURN QUERY
294+
SELECT * FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), $3, $4, $5, $6, $7, $8, $9);
295295
END
296296
$BODY$
297297
LANGUAGE plpgsql VOLATILE STRICT

sql/sigs/pgrouting--3.6.sig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ _pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double prec
291291
pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean)
292292
_pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean)
293293
pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean)
294+
_pgr_v4withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean)
295+
_pgr_v4withpointsksp(text,text,text,integer,character,boolean,boolean,boolean)
294296
pgr_version()
295297
_pgr_versionless(text,text)
296298
_pgr_vrponedepot(text,text,text,integer)
@@ -304,8 +306,13 @@ pgr_withpointscost(text,text,text,boolean,character)
304306
_pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean)
305307
pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean)
306308
pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean)
309+
pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean)
310+
pgr_withpointsksp(text,text,anyarray,bigint,integer,character,boolean,boolean,boolean)
311+
pgr_withpointsksp(text,text,bigint,anyarray,integer,character,boolean,boolean,boolean)
307312
_pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)
308313
pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)
314+
pgr_withpointsksp(text,text,bigint,bigint,integer,character,boolean,boolean,boolean)
315+
pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean)
309316
pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean)
310317
_pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean,boolean,boolean)
311318
pgr_withpoints(text,text,anyarray,bigint,boolean,character,boolean)

src/ksp/withPoints_ksp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ processv4(
7474
size_t k = (size_t)p_k;
7575

7676
driving_side[0] = (char) tolower(driving_side[0]);
77-
if(!((driving_side[0] == 'r')
78-
|| (driving_side[0] == 'l') || (driving_side[0] == 'b'))){
77+
if (!((driving_side[0] == 'r')
78+
|| (driving_side[0] == 'l') || (driving_side[0] == 'b'))) {
7979
elog(ERROR, "Driving side is not selected or Invalid Values");
8080
return;
8181
}
@@ -207,7 +207,7 @@ PGDLLEXPORT Datum _pgr_v4withpointsksp(PG_FUNCTION_ARGS) {
207207
funcctx = SRF_FIRSTCALL_INIT();
208208
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
209209

210-
if(PG_NARGS() == 9){
210+
if (PG_NARGS() == 9) {
211211
processv4(
212212
text_to_cstring(PG_GETARG_TEXT_P(0)),
213213
text_to_cstring(PG_GETARG_TEXT_P(1)),
@@ -221,7 +221,7 @@ PGDLLEXPORT Datum _pgr_v4withpointsksp(PG_FUNCTION_ARGS) {
221221
PG_GETARG_BOOL(8),
222222
&result_tuples,
223223
&result_count);
224-
} else/* (PG_NARGS() == 8) */{
224+
} else /* (PG_NARGS() == 8) */ {
225225
processv4(
226226
text_to_cstring(PG_GETARG_TEXT_P(0)),
227227
text_to_cstring(PG_GETARG_TEXT_P(1)),
@@ -281,8 +281,8 @@ PGDLLEXPORT Datum _pgr_v4withpointsksp(PG_FUNCTION_ARGS) {
281281
values[0] = Int32GetDatum(funcctx->call_cntr + 1);
282282
values[1] = Int32GetDatum(path_id);
283283
values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
284-
values[3] = Int32GetDatum(result_tuples[funcctx->call_cntr].start_id);
285-
values[4] = Int32GetDatum(result_tuples[funcctx->call_cntr].end_id);
284+
values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
285+
values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id);
286286
values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
287287
values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
288288
values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
@@ -516,4 +516,4 @@ PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) {
516516
} else {
517517
SRF_RETURN_DONE(funcctx);
518518
}
519-
}
519+
}

src/ksp/withPoints_ksp_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,4 @@ do_pgr_withPointsKsp(
348348
*log_msg = pgr_msg(log.str().c_str());
349349
}
350350
return 1000;
351-
}
351+
}

0 commit comments

Comments
 (0)