diff --git a/.gitignore b/.gitignore index 3b0eb5ae1c..d85d4bbc81 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ build fix_typos code_linter src/version/version.h - +run.sh +taptest.sh .DS_Store .vagrant .directory diff --git a/doc/src/pgRouting-introduction.rst b/doc/src/pgRouting-introduction.rst index 4c5dcc5b1d..bbe9f9c2c1 100644 --- a/doc/src/pgRouting-introduction.rst +++ b/doc/src/pgRouting-introduction.rst @@ -66,6 +66,7 @@ This Release Contributors Individuals in this release (in alphabetical order) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Aniket Agarwal Ashish Kumar, Cayetano Benavent, Daniel Kastl, diff --git a/include/c_types/path_rt.h b/include/c_types/path_rt.h index b92d79e7ca..af46edcccb 100644 --- a/include/c_types/path_rt.h +++ b/include/c_types/path_rt.h @@ -35,6 +35,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #endif struct Path_rt { + /*Added route_id*/ + int16_t route_id; int seq; int64_t start_id; int64_t end_id; diff --git a/include/drivers/yen/ksp_driver.h b/include/drivers/yen/ksp_driver.h index 9b63b34f24..704ed16759 100644 --- a/include/drivers/yen/ksp_driver.h +++ b/include/drivers/yen/ksp_driver.h @@ -4,6 +4,9 @@ File: ksp_driver.h Copyright (c) 2015 Celia Virginia Vergara Castillo Mail: vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +Mail: aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -32,11 +35,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # include using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; +using II_t_rt = struct II_t_rt; #else # include # include typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; +typedef struct II_t_rt II_t_rt; #endif @@ -47,13 +52,23 @@ extern "C" { void do_pgr_ksp( Edge_t *data_edges, size_t total_edges, - int64_t start_vid, - int64_t end_vid, + + II_t_rt *combinations, + size_t total_combinations, + + int64_t *start_vids, + size_t size_start_vids, + int64_t *end_vids, + size_t size_end_vids, + size_t K, + bool directed, bool heap_paths, + Path_rt **return_tuples, size_t *return_count, + char ** log_msg, char ** notice_msg, char ** err_msg); diff --git a/include/yen/pgr_ksp.hpp b/include/yen/pgr_ksp.hpp index 32fb1d01e8..a4ab96d606 100644 --- a/include/yen/pgr_ksp.hpp +++ b/include/yen/pgr_ksp.hpp @@ -4,6 +4,9 @@ File: pgr_ksp.hpp Copyright (c) 2015 Celia Virginia Vergara Castillo Mail: vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +Mail: aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -26,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_YEN_PGR_KSP_HPP_ #pragma once - +#include #include #include #include @@ -236,6 +239,40 @@ class Pgr_ksp : public Pgr_messages { } // namespace yen + +/* +* Added the namespace algorithm to calculate combinations +*/ +namespace algorithms { + + template + std::deque ksp( + G &graph, + const std::map> &combinations, + size_t k, + bool heap_paths) { + std::deque paths; + pgrouting::yen::Pgr_ksp fn_yen; + + for (const auto &c : combinations) { + if (!graph.has_vertex(c.first)) + continue; + + for (const auto &destination : c.second) { + if (!graph.has_vertex(destination)) + continue; + + fn_yen.clear(); + auto result_path = fn_yen.Yen(graph, c.first, destination, k, heap_paths); + paths.insert(paths.end(), result_path.begin(), result_path.end()); + } + } + + return paths; + } + +} // namespace algorithms + } // namespace pgrouting #endif // INCLUDE_YEN_PGR_KSP_HPP_ diff --git a/sql/ksp/_ksp.sql b/sql/ksp/_ksp.sql index dd6c180e0d..6aed4c4e2f 100644 --- a/sql/ksp/_ksp.sql +++ b/sql/ksp/_ksp.sql @@ -4,6 +4,9 @@ File: _ksp.sql Copyright (c) 2015 Celia Virginia Vergara Castillo vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -28,10 +31,57 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --------------- --v2.6 +-- CREATE FUNCTION _pgr_ksp( +-- edges_sql TEXT, +-- start_vid INTEGER, +-- end_vid INTEGER, +-- k INTEGER, + +-- directed BOOLEAN, +-- heap_paths BOOLEAN, + +-- OUT seq INTEGER, +-- OUT path_id INTEGER, +-- OUT path_seq INTEGER, +-- OUT start_vid BIGINT, +-- OUT end_vid BIGINT, +-- OUT node BIGINT, +-- OUT edge BIGINT, +-- OUT cost FLOAT, +-- OUT agg_cost FLOAT) +-- RETURNS SETOF RECORD AS +-- 'MODULE_PATHNAME' +-- LANGUAGE C VOLATILE STRICT; + + +--v3.6 +CREATE FUNCTION _pgr_ksp( + edges_sql TEXT, + start_vids ANYARRAY, + end_vids ANYARRAY, + k INTEGER, + + directed BOOLEAN, + heap_paths BOOLEAN, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE C VOLATILE STRICT; + +--v3.6 CREATE FUNCTION _pgr_ksp( edges_sql TEXT, - start_vid BIGINT, - end_vid BIGINT, + combinations TEXT, + k INTEGER, directed BOOLEAN, @@ -40,6 +90,8 @@ CREATE FUNCTION _pgr_ksp( OUT seq INTEGER, OUT path_id INTEGER, OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, @@ -50,5 +102,8 @@ LANGUAGE C VOLATILE STRICT; -- COMMENTS -COMMENT ON FUNCTION _pgr_ksp(TEXT, BIGINT, BIGINT, INTEGER, BOOLEAN, BOOLEAN) +COMMENT ON FUNCTION _pgr_ksp(TEXT, ANYARRAY, ANYARRAY, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgRouting internal function'; + +COMMENT ON FUNCTION _pgr_ksp(TEXT, TEXT, INTEGER, BOOLEAN, BOOLEAN) IS 'pgRouting internal function'; diff --git a/sql/ksp/ksp.sql b/sql/ksp/ksp.sql index 5d9bf78df7..56f54b5d43 100644 --- a/sql/ksp/ksp.sql +++ b/sql/ksp/ksp.sql @@ -4,6 +4,9 @@ File: ksp.sql Copyright (c) 2015 Celia Virginia Vergara Castillo vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -23,10 +26,166 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ --v2.6 +-- CREATE FUNCTION pgr_ksp( +-- TEXT, -- edges_sql (required) +-- BIGINT, -- from_vids (required) +-- BIGINT, -- to_vids (required) +-- INTEGER, -- K (required) + +-- directed BOOLEAN DEFAULT true, +-- heap_paths BOOLEAN DEFAULT false, + +-- OUT seq INTEGER, +-- OUT path_id INTEGER, +-- OUT path_seq INTEGER, +-- OUT node BIGINT, +-- OUT edge BIGINT, +-- OUT cost FLOAT, +-- OUT agg_cost FLOAT) +-- RETURNS SETOF RECORD AS +-- $BODY$ +-- SELECT * +-- FROM _pgr_ksp(_pgr_get_statement($1), $2, $3, $4, $5, $6); +-- $BODY$ +-- LANGUAGE SQL VOLATILE STRICT +-- COST 100 +-- ROWS 1000; + +-- -- COMMENTS + +-- COMMENT ON FUNCTION pgr_ksp(TEXT, BIGINT, BIGINT, INTEGER, BOOLEAN, BOOLEAN) +-- IS 'pgr_KSP +-- - Parameters: +-- - Edges SQL with columns: id, source, target, cost [,reverse_cost] +-- - From vertex identifier +-- - To vertex identifier +-- - K +-- - Optional Parameters +-- - directed := true +-- - heap_paths := false +-- - Documentation: +-- - ${PROJECT_DOC_LINK}/pgr_KSP.html +-- '; + + +-- one-to-one +-- v3.6 +CREATE FUNCTION pgr_ksp( + TEXT, -- edges_sql (required) + BIGINT, -- from_vid (required) + BIGINT, -- to_vid (required) + INTEGER, -- K (required) + + directed BOOLEAN DEFAULT true, + heap_paths BOOLEAN DEFAULT false, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT a.seq, a.path_id, a.path_seq, a.node, a.edge, a.cost, a.agg_cost + FROM _pgr_ksp(_pgr_get_statement($1), ARRAY[$2]::BIGINT[],ARRAY[$3]::BIGINT[], $4, $5, $6) AS a; +$BODY$ +LANGUAGE SQL VOLATILE STRICT +COST 100 +ROWS 1000; + + +-- one-to-many +-- v3.6 +CREATE FUNCTION pgr_ksp( + TEXT, -- edges_sql (required) + BIGINT, -- from_vid (required) + ANYARRAY, -- to_vids (required) + INTEGER, -- K (required) + + directed BOOLEAN DEFAULT true, + heap_paths BOOLEAN DEFAULT false, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT end_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT a.seq, a.path_id, a.path_seq, a.end_vid, a.node, a.edge, a.cost, a.agg_cost + FROM _pgr_ksp(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], $3::BIGINT[], $4, $5, $6) AS a; +$BODY$ +LANGUAGE SQL VOLATILE STRICT +COST 100 +ROWS 1000; + +-- many-to-one +-- v3.6 +CREATE FUNCTION pgr_ksp( + TEXT, -- edges_sql (required) + ANYARRAY, -- from_vids (required) + BIGINT, -- to_vid (required) + INTEGER, -- K (required) + + directed BOOLEAN DEFAULT true, + heap_paths BOOLEAN DEFAULT false, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT a.seq, a.path_id, a.path_seq, a.start_vid, a.node, a.edge, a.cost, a.agg_cost + FROM _pgr_ksp(_pgr_get_statement($1), $2::BIGINT[], ARRAY[$3]::BIGINT[], $4, $5, $6) as a; +$BODY$ +LANGUAGE SQL VOLATILE STRICT +COST 100 +ROWS 1000; + +-- many-to-many +-- v3.6 +CREATE FUNCTION pgr_ksp( + TEXT, -- edges_sql (required) + ANYARRAY, -- from_vids (required) + ANYARRAY, -- to_vids (required) + INTEGER, -- K (required) + + directed BOOLEAN DEFAULT true, + heap_paths BOOLEAN DEFAULT false, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT * + FROM _pgr_ksp(_pgr_get_statement($1), $2::BIGINT[], $3::BIGINT[], $4, $5, $6); +$BODY$ +LANGUAGE SQL VOLATILE STRICT +COST 100 +ROWS 1000; + +-- combinations +-- v3.6 CREATE FUNCTION pgr_ksp( TEXT, -- edges_sql (required) - BIGINT, -- from_vids (required) - BIGINT, -- to_vids (required) + TEXT, -- combinations_sql (required) INTEGER, -- K (required) directed BOOLEAN DEFAULT true, @@ -35,6 +194,8 @@ CREATE FUNCTION pgr_ksp( OUT seq INTEGER, OUT path_id INTEGER, OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, @@ -42,7 +203,7 @@ CREATE FUNCTION pgr_ksp( RETURNS SETOF RECORD AS $BODY$ SELECT * - FROM _pgr_ksp(_pgr_get_statement($1), $2, $3, $4, $5, $6); + FROM _pgr_ksp(_pgr_get_statement($1), _pgr_get_statement($2), $3, $4, $5, $6); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -51,10 +212,38 @@ ROWS 1000; -- COMMENTS COMMENT ON FUNCTION pgr_ksp(TEXT, BIGINT, BIGINT, INTEGER, BOOLEAN, BOOLEAN) -IS 'pgr_KSP +IS 'pgr_KSP(One to One) +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] + - From vertex identifier + - To vertex identifier + - K +- Optional Parameters + - directed := true + - heap_paths := false +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_KSP.html +'; + +COMMENT ON FUNCTION pgr_ksp(TEXT, BIGINT, ANYARRAY, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_KSP(One to Many) - Parameters: - Edges SQL with columns: id, source, target, cost [,reverse_cost] - From vertex identifier + - To ARRAY[vertex identifier] + - K +- Optional Parameters + - directed := true + - heap_paths := false +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_KSP.html +'; + +COMMENT ON FUNCTION pgr_ksp(TEXT, ANYARRAY, BIGINT, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_KSP(Many to One) +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] + - From ARRAY[vertex identifier] - To vertex identifier - K - Optional Parameters @@ -63,3 +252,31 @@ IS 'pgr_KSP - Documentation: - ${PROJECT_DOC_LINK}/pgr_KSP.html '; + +COMMENT ON FUNCTION pgr_ksp(TEXT, ANYARRAY, ANYARRAY, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_KSP(Many to Many) +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] + - From ARRAY[vertex identifier] + - To ARRAY[vertex identifier] + - K +- Optional Parameters + - directed := true + - heap_paths := false +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_KSP.html +'; + +COMMENT ON FUNCTION pgr_ksp(TEXT, TEXT, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_KSP(Combinations) +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] + - Combinations SQL with columns: source, target + - K +- Optional Parameters + - directed := true + - heap_paths := false +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_KSP.html +'; + diff --git a/src/common/basePath_SSEC.cpp b/src/common/basePath_SSEC.cpp index 99708e26cd..ab49078fd6 100644 --- a/src/common/basePath_SSEC.cpp +++ b/src/common/basePath_SSEC.cpp @@ -239,8 +239,8 @@ void Path::generate_postgres_data( std::numeric_limits::infinity() : e.agg_cost; auto cost = std::fabs(e.cost - (std::numeric_limits::max)()) < 1? std::numeric_limits::infinity() : e.cost; - - (*postgres_data)[sequence] = {i, start_id(), end_id(), e.node, e.edge, cost, agg_cost}; + /* added zero on the place of route id*/ + (*postgres_data)[sequence] = {0, i, start_id(), end_id(), e.node, e.edge, cost, agg_cost}; ++i; ++sequence; } @@ -267,8 +267,15 @@ 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++) { + /* + * Added route_id + */ + (*ret_path)[sequence].route_id = routeId + 1; (*ret_path)[sequence].seq = static_cast(i + 1); - (*ret_path)[sequence].start_id = routeId; + /* + * keeping it start_id + */ + (*ret_path)[sequence].start_id = start_id(); (*ret_path)[sequence].end_id = end_id(); (*ret_path)[sequence].node = path[i].node; (*ret_path)[sequence].edge = path[i].edge; diff --git a/src/ksp/ksp.c b/src/ksp/ksp.c index a0edbebcd6..0c3f6c6db9 100644 --- a/src/ksp/ksp.c +++ b/src/ksp/ksp.c @@ -4,6 +4,9 @@ File: ksp.c Copyright (c) 2015 Celia Virginia Vergara Castillo vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -40,9 +43,9 @@ PG_FUNCTION_INFO_V1(_pgr_ksp); static void compute( char* edges_sql, - int64_t start_vertex, - int64_t end_vertex, - + char* combinations_sql, + ArrayType *starts, + ArrayType *ends, int p_k, bool directed, bool heap_paths, @@ -57,15 +60,34 @@ void compute( size_t k = (size_t)p_k; + int64_t* start_vidsArr = NULL; + size_t size_start_vidsArr = 0; + + int64_t* end_vidsArr = NULL; + size_t size_end_vidsArr = 0; + + II_t_rt *combinations = NULL; + size_t total_combinations = 0; + + if (starts && ends) { + start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); + throw_error(err_msg, "While getting start vids"); + end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); + throw_error(err_msg, "While getting end vids"); + } else if (combinations_sql) { + pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); + throw_error(err_msg, combinations_sql); + } + PGR_DBG("Load data"); Edge_t *edges = NULL; size_t total_edges = 0; - if (start_vertex == end_vertex) { - pgr_SPI_finish(); - return; - } + // if (start_vertex == end_vertex) { + // pgr_SPI_finish(); + // return; + // } pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); throw_error(err_msg, edges_sql); @@ -84,10 +106,10 @@ void compute( clock_t start_t = clock(); do_pgr_ksp( - edges, - total_edges, - start_vertex, - end_vertex, + edges, total_edges, + combinations, total_combinations, + start_vidsArr, size_start_vidsArr, + end_vidsArr, size_end_vidsArr, k, directed, heap_paths, @@ -110,6 +132,9 @@ void compute( if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); + if (start_vidsArr) pfree(start_vidsArr); + if (end_vidsArr) pfree(end_vidsArr); + pgr_global_report(log_msg, notice_msg, err_msg); @@ -141,15 +166,36 @@ _pgr_ksp(PG_FUNCTION_ARGS) { heap_paths boolean */ PGR_DBG("Calling process"); - compute( + if (PG_NARGS() == 6) { + /* + * many to many + */ + compute( text_to_cstring(PG_GETARG_TEXT_P(0)), - PG_GETARG_INT64(1), - PG_GETARG_INT64(2), + NULL, + PG_GETARG_ARRAYTYPE_P(1), + PG_GETARG_ARRAYTYPE_P(2), PG_GETARG_INT32(3), PG_GETARG_BOOL(4), PG_GETARG_BOOL(5), &path, &result_count); + } else if (PG_NARGS() == 5) { + /* + * combinations + */ + compute( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + NULL, + NULL, + PG_GETARG_INT32(2), + PG_GETARG_BOOL(3), + PG_GETARG_BOOL(4), + &path, + &result_count); + } + PGR_DBG("Total number of tuples to be returned %ld \n", result_count); @@ -180,22 +226,25 @@ _pgr_ksp(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - values = palloc(7 * sizeof(Datum)); - nulls = palloc(7 * sizeof(bool)); + values = palloc(9 * sizeof(Datum)); + nulls = palloc(9 * sizeof(bool)); size_t i; - for (i = 0; i < 7; ++i) { + for (i = 0; i < 9; ++i) { nulls[i] = false; } values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int32GetDatum((int32_t)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); + /* added start_id and end_id */ + values[3] = Int64GetDatum(path[funcctx->call_cntr].start_id); + values[4] = Int64GetDatum(path[funcctx->call_cntr].end_id); + values[5] = Int64GetDatum(path[funcctx->call_cntr].node); + values[6] = Int64GetDatum(path[funcctx->call_cntr].edge); + values[7] = Float8GetDatum(path[funcctx->call_cntr].cost); + values[8] = Float8GetDatum(path[funcctx->call_cntr].agg_cost); tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/ksp/ksp_driver.cpp b/src/ksp/ksp_driver.cpp index e77d029c11..d8fe71cb35 100644 --- a/src/ksp/ksp_driver.cpp +++ b/src/ksp/ksp_driver.cpp @@ -4,6 +4,9 @@ File: ksp_driver.cpp Copyright (c) 2015 Celia Virginia Vergara Castillo vicky_vergara@hotmail.com +Copyright (c) 2023 Aniket Agarwal +aniketgarg187@gmail.com + ------ This program is free software; you can redistribute it and/or modify @@ -31,20 +34,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "yen/pgr_ksp.hpp" +#include "cpp_common/combinations.h" #include "cpp_common/pgr_alloc.hpp" #include "cpp_common/pgr_assert.h" #include "cpp_common/pgr_base_graph.hpp" +#include "c_types/ii_t_rt.h" + using pgrouting::yen::Pgr_ksp; void do_pgr_ksp( - Edge_t *data_edges, - size_t total_edges, - int64_t start_vid, - int64_t end_vid, + Edge_t *data_edges, size_t total_edges, + II_t_rt *combinationsArr, size_t total_combinations, + int64_t* start_vids, size_t size_start_vids, + int64_t * end_vids, size_t size_end_vids, size_t k, bool directed, bool heap_paths, @@ -69,20 +75,22 @@ void do_pgr_ksp( pgassert(*return_count == 0); pgassert(total_edges != 0); + auto combinations = total_combinations? + pgrouting::utilities::get_combinations(combinationsArr, total_combinations) + : pgrouting::utilities::get_combinations(start_vids, size_start_vids, end_vids, size_end_vids); + graphType gType = directed? DIRECTED: UNDIRECTED; std::deque< Path > paths; if (directed) { pgrouting::DirectedGraph digraph(gType); - Pgr_ksp< pgrouting::DirectedGraph > fn_yen; digraph.insert_edges(data_edges, total_edges); - paths = fn_yen.Yen(digraph, start_vid, end_vid, k, heap_paths); + paths = pgrouting::algorithms::ksp(digraph, combinations, k, heap_paths); } else { pgrouting::UndirectedGraph undigraph(gType); - Pgr_ksp< pgrouting::UndirectedGraph > fn_yen; undigraph.insert_edges(data_edges, total_edges); - paths = fn_yen.Yen(undigraph, start_vid, end_vid, k, heap_paths); + paths = pgrouting::algorithms::ksp(undigraph, combinations, k, heap_paths); }