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: Aryan Gupta week 8 #329

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cpp_common/pgr_base_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class Pgr_base_graph {
@return V: The vertex descriptor of the vertex
*/
V get_V(int64_t vid) const {
pgassert(has_vertex(vid));
// pgassert(has_vertex(vid));
return vertices_map.find(vid)->second;
}

Expand Down
46 changes: 20 additions & 26 deletions include/dijkstra/v4drivingDist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <limits>
#include <map>
#include <numeric>
#include <utility>

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

#include "c_types/ii_t_rt.h"
#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"
#include "visitors/dijkstra_visitors.hpp"
#include <deque>
#include <set>
#include <vector>
#include <utility>

#include <visitors/dfs_visitor_with_root.hpp>
#include "cpp_common/basePath_SSEC.hpp"
#include <visitors/edges_order_dfs_visitor.hpp>
#include <boost/graph/filtered_graph.hpp>

Expand Down Expand Up @@ -516,8 +511,8 @@ class ShortestPath_tree{
const G&);

std::deque<MST_rt> dfs_order(
const G&,
int64_t);
const G&,
int64_t);

void get_edges_from_path(
const G&,
Expand Down Expand Up @@ -556,7 +551,9 @@ ShortestPath_tree<G>::get_results(
}

if (depth[u] == 0 && depth[v] == 0) {
if (graph[u].id != root) std::swap(u, v);
if (graph[u].id != root) {
std::swap(u, v);
}
if (!p_root && graph[u].id > graph[v].id) std::swap(u, v);

root = p_root? p_root: graph[u].id;
Expand All @@ -573,7 +570,7 @@ ShortestPath_tree<G>::get_results(
depth[v] = depth[u] == -1? 1 : depth[u] + 1;

if (graph[v].id < 0) depth[v] = depth[u];
if (graph[v].id > 0){
if (graph[v].id > 0) {
results.push_back({
root,
depth[v],
Expand Down Expand Up @@ -621,7 +618,7 @@ ShortestPath_tree<G>::dfs_order(const G &graph, int64_t root) {
} else {
results.push_back({root, 0, root, -1, 0.0, 0.0});
}

return results;
}

Expand All @@ -630,19 +627,17 @@ template <class G>
void
ShortestPath_tree<G>::get_edges_from_path(
const G& graph,
const Path path){
// m_spanning_tree.clear();

for (size_t i = 0; i < path.size(); i++){
const Path path) {
for (size_t i = 0; i < path.size(); i++) {
auto u = graph.get_V(path[i].node);

for (size_t j = i+1; j < path.size(); j++){
for (size_t j = i+1; j < path.size(); j++) {
auto v = graph.get_V(path[j].node);
double cost = path[j].cost;
double cost = path[j].cost;
auto edge = graph.get_edge(u, v, cost);
if(graph.target(edge) == v
&& path[i].agg_cost+cost == path[j].agg_cost
&& graph[edge].id == path[j].edge){
if (graph.target(edge) == v
&& path[i].agg_cost+cost == path[j].agg_cost
&& graph[edge].id == path[j].edge) {
this->m_spanning_tree.edges.insert(edge);
}
}
Expand All @@ -654,13 +649,12 @@ std::deque<MST_rt>
ShortestPath_tree<G>::get_depths(
G &graph,
std::deque<Path> paths) {

std::deque<MST_rt> results;

for (const Path& path : paths) {
get_edges_from_path(graph, path);
int64_t root = path.start_id();
auto result = this->dfs_order(graph, root);
get_edges_from_path(graph, path);
int64_t root = path.start_id();
auto result = this->dfs_order(graph, root);

std::sort(result.begin(), result.end(),
[](const MST_rt &l, const MST_rt &r)
Expand All @@ -670,12 +664,12 @@ ShortestPath_tree<G>::get_depths(
{return l.agg_cost < r.agg_cost;});

results.insert(results.end(), result.begin(), result.end());
}
}
return results;
}


}
} // namespace functions
} // namespace pgrouting


Expand Down
2 changes: 1 addition & 1 deletion include/drivers/driving_distance/v4drivedist_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ extern "C" {
}
#endif

#endif //INCLUDE_DRIVERS_DRIVING_DISTANCE_V4DRIVEDIST_DRIVER_H_
#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_V4DRIVEDIST_DRIVER_H_
2 changes: 1 addition & 1 deletion pgtap/dijkstra/driving_distance/edge_cases/issue_1152.pg
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ language plpgsql;

SELECT * FROM issue1154();
SELECT lives_ok($$
SELECT *
SELECT seq, start_vid, node, edge, cost, agg_cost
FROM pgr_drivingdistance(
'SELECT * FROM tmp_net',
ARRAY[
Expand Down
2 changes: 1 addition & 1 deletion pgtap/dijkstra/driving_distance/edge_cases/issue_519.pg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PREPARE q3 AS
SELECT 25 AS start_vid, node, edge, cost, agg_cost FROM pgr_drivingDistance( 'select id, source, target, cost from edge_table',
25, 3.5);

/* TODO check C/C++ code because it is crashing the server when using ARRAY'
/* TODO check C/C++ code because it is crashing the server when using ARRAY*/
Prepare q4 AS
SELECT start_vid, node, edge, cost, agg_cost FROM pgr_drivingDistance( 'select id, source, target, cost from edge_table',
ARRAY[1, 5, 25], 3.5);
Expand Down
6 changes: 3 additions & 3 deletions pgtap/dijkstra/driving_distance/types_check.pg
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ RETURN QUERY
SELECT set_eq(
$$SELECT proallargtypes from pg_proc where proname = 'pgr_drivingdistance'$$,
$$VALUES
('{25,20,701,16,23,20,20,20,20,701,701}'::OID[]),
('{25,2277,701,16,16,23,20,20,20,20,701,701}'::OID[])
('{25,20,701,16,20,20,20,20,20,701,701}'::OID[]),
('{25,2277,701,16,16,20,20,20,20,20,701,701}'::OID[])
$$);
ELSE
-- old signatures
Expand All @@ -65,7 +65,7 @@ SELECT set_eq(
$$SELECT proallargtypes from pg_proc where proname = 'pgr_drivingdistance'$$,
$$VALUES
('{25,20,701,16,23,20,20,701,701}'::OID[]),
('{25,2277,701,16,16,23,20,20,20,701,701}'::OID[])
('{25,2277,701,16,16,20,20,20,20,701,701}'::OID[])
$$);
END IF;
END;
Expand Down
2 changes: 1 addition & 1 deletion sql/driving_distance/_drivingDistance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CREATE FUNCTION _pgr_v4drivingDistance(
distance FLOAT,
directed BOOLEAN DEFAULT TRUE,
equicost BOOLEAN DEFAULT FALSE,
OUT seq INTEGER,
OUT seq BIGINT,
OUT depth BIGINT,
OUT start_vid BIGINT,
OUT node BIGINT,
Expand Down
4 changes: 2 additions & 2 deletions sql/driving_distance/drivingDistance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CREATE FUNCTION pgr_drivingDistance(
directed BOOLEAN DEFAULT TRUE,
equicost BOOLEAN DEFAULT FALSE,

OUT seq INTEGER,
OUT seq BIGINT,
OUT depth BIGINT,
OUT start_vid BIGINT,
OUT node BIGINT,
Expand All @@ -61,7 +61,7 @@ CREATE FUNCTION pgr_drivingDistance(

directed BOOLEAN DEFAULT TRUE,

OUT seq INTEGER,
OUT seq BIGINT,
OUT depth BIGINT,
OUT start_vid BIGINT,
OUT node BIGINT,
Expand Down
2 changes: 1 addition & 1 deletion sql/sigs/pgrouting--3.6.sig
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pgr_dijkstravia(text,anyarray,boolean,boolean,boolean)
_pgr_drivingdistance(text,anyarray,double precision,boolean,boolean)
pgr_drivingdistance(text,anyarray,double precision,boolean,boolean)
pgr_drivingdistance(text,bigint,double precision,boolean)
_pgr_v4drivingdistance(text,anyarray,double precision,boolean,boolean)
_pgr_edgecoloring(text)
pgr_edgecoloring(text)
_pgr_edgedisjointpaths(text,anyarray,anyarray,boolean)
Expand Down Expand Up @@ -292,6 +291,7 @@ _pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double prec
pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean)
_pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean)
pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean)
_pgr_v4drivingdistance(text,anyarray,double precision,boolean,boolean)
pgr_version()
_pgr_versionless(text,text)
_pgr_vrponedepot(text,text,text,integer)
Expand Down