Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSoC 2023: Aniket Agarwal Week 2 #295

Merged
merged 13 commits into from
Jun 10, 2023
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is ok in this GSoC repository, this change would be unacceptable in the pgRouting repository.
You need to learn to live with the files that are "helper" files for the development you are doing, past present of future
For example, in my case I have zillions of files I have to see when I do a git status, and I live with them. Either I used them in the past, or I am using them, or I am preparing something for the future.
But none of them are to be included in the repository.

git status
On branch foo
Your branch is up to date with 'origin/foo'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	after.txt
	astar_benchmark.pg
	before.txt
	change.sh
	commitByDirectory.sh
	commitBySubDirectory.sh
	commits.sh
	contributions.txt
	contributors.txt
	dmain.txt
	errs.txt
	exe.sh
	get_contributors.sh
	info.txt
	install-all.sh
	install-old-version.sh
	install-one.sh
	instructions.sh
	nmain.txt
	node_change.txt
	orderedinfo.txt
	page_history_gh_page.js
	patch.cpp
	pge_history_main.js
	run.sh
	taptest-4.sh
	taptest.sh
	update3.4.sh
	v4.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*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying types will cause a lot of problems on the other functions.
I suggest you look how things are handled when there is an identifier of a route on the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, that makes sense could you please tell me the name of the function that outputs path_id except pgr_ksp?

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: vicky_vergara@hotmail.com

Copyright (c) 2023 Aniket Agarwal
Mail: aniketgarg187@gmail.com
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use at instead of @ one of our goals for v4 is to not have clickable mails to avoid unwanted mails from robots

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vicky at erosion.dev


------

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove name of parameters in header files

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: 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
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
vicky_vergara@hotmail.com

Copyright (c) 2023 Aniket Agarwal
aniketgarg187@gmail.com

------

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are marking a function for deletion, in SQL use /* */ to wrap the unwanted code
and a -- TODO if 0 <--- makes it easier to find the unwanted code that was forgotten to remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention, you can not delete an SQL function, this is a 3.6.0 which can only add functions from 3.5, you will have problems when testing updates.
TRSP had a similar problem and the way around was:

CREATE FUNCTION _v4trsp(

As you can see the old function remains, but the new one to be kept on v4 is named differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, Got it Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention, you can not delete an SQL function, this is a 3.6.0 which can only add functions from 3.5, you will have problems when testing updates. TRSP had a similar problem and the way around was:

CREATE FUNCTION _v4trsp(

As you can see the old function remains, but the new one to be kept on v4 is named differently.

Can I change SQL function?

-- 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