Skip to content

Commit

Permalink
GSoC 2023: Aniket Agarwal Week 2 (pgRouting#295)
Browse files Browse the repository at this point in the history
* added one-to-many overload and try to run pgtap on ksp

* removed white spaces at the end of the lines

* update function's developer

* added overloads

* fixing the errors

* fixing more errors

* added function's developer and updates in .hpp

* fixed error of algorithm

* fix the start_id and route_id problem

* changes in ksp.sql to pass tests

* fixing linting

* fixing linter

* added name in contributor list and added namspace comment
  • Loading branch information
Aniket-debug committed Aug 22, 2023
1 parent 2e50d9d commit 953978f
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ build
fix_typos
code_linter
src/version/version.h

run.sh
taptest.sh
.DS_Store
.vagrant
.directory
Expand Down
1 change: 1 addition & 0 deletions doc/src/pgRouting-introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This Release Contributors
Individuals in this release (in alphabetical order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Aniket Agarwal
Ashish Kumar,
Cayetano Benavent,
Daniel Kastl,
Expand Down
2 changes: 2 additions & 0 deletions include/c_types/path_rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions include/drivers/yen/ksp_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ File: ksp_driver.h
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail: [email protected]
Copyright (c) 2023 Aniket Agarwal
Mail: [email protected]
------
This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -32,11 +35,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include <cstddef>
using Edge_t = struct Edge_t;
using Path_rt = struct Path_rt;
using II_t_rt = struct II_t_rt;
#else
# include <stddef.h>
# include <stdint.h>
typedef struct Edge_t Edge_t;
typedef struct Path_rt Path_rt;
typedef struct II_t_rt II_t_rt;
#endif


Expand All @@ -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);
Expand Down
39 changes: 38 additions & 1 deletion include/yen/pgr_ksp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ File: pgr_ksp.hpp
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail: [email protected]
Copyright (c) 2023 Aniket Agarwal
Mail: [email protected]
------
This program is free software; you can redistribute it and/or modify
Expand All @@ -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 <map>
#include <sstream>
#include <deque>
#include <vector>
Expand Down Expand Up @@ -236,6 +239,40 @@ class Pgr_ksp : public Pgr_messages {


} // namespace yen

/*
* Added the namespace algorithm to calculate combinations
*/
namespace algorithms {

template <class G>
std::deque<Path> ksp(
G &graph,
const std::map<int64_t, std::set<int64_t>> &combinations,
size_t k,
bool heap_paths) {
std::deque<Path> paths;
pgrouting::yen::Pgr_ksp<G> 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_
61 changes: 58 additions & 3 deletions sql/ksp/_ksp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ File: _ksp.sql
Copyright (c) 2015 Celia Virginia Vergara Castillo
[email protected]
Copyright (c) 2023 Aniket Agarwal
[email protected]
------
This program is free software; you can redistribute it and/or modify
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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';
Loading

0 comments on commit 953978f

Please sign in to comment.