From 1b29684529d9f94054dae8d9b812b49e4d4b3999 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sat, 23 Aug 2025 09:43:13 -0600 Subject: [PATCH 1/5] (C++) File rename: */common/basePath_SSEC.cpp -> */common/path.cpp --- include/cpp_common/{basePath_SSEC.hpp => path.hpp} | 0 src/common/{basePath_SSEC.cpp => path.cpp} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename include/cpp_common/{basePath_SSEC.hpp => path.hpp} (100%) rename src/common/{basePath_SSEC.cpp => path.cpp} (100%) diff --git a/include/cpp_common/basePath_SSEC.hpp b/include/cpp_common/path.hpp similarity index 100% rename from include/cpp_common/basePath_SSEC.hpp rename to include/cpp_common/path.hpp diff --git a/src/common/basePath_SSEC.cpp b/src/common/path.cpp similarity index 100% rename from src/common/basePath_SSEC.cpp rename to src/common/path.cpp From 880f291234f3885f1cf619ba3b740f59dc0b8fd8 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sat, 23 Aug 2025 09:44:51 -0600 Subject: [PATCH 2/5] (C++) Adjusting includes to file name changes --- include/astar/astar.hpp | 2 +- include/bdAstar/bdAstar.hpp | 2 +- include/bdDijkstra/bdDijkstra.hpp | 2 +- include/bellman_ford/bellman_ford.hpp | 2 +- include/bellman_ford/edwardMoore.hpp | 2 +- include/breadthFirstSearch/binaryBreadthFirstSearch.hpp | 2 +- include/circuits/hawickcircuits.hpp | 2 +- include/cpp_common/bidirectional.hpp | 2 +- include/cpp_common/combinations.hpp | 2 +- include/cpp_common/compPaths.hpp | 2 +- include/cpp_common/path.hpp | 2 +- include/dagShortestPath/dagShortestPath.hpp | 2 +- include/dijkstra/dijkstra.hpp | 2 +- include/dijkstra/drivingDist.hpp | 2 +- include/mincut/stoerWagner.hpp | 2 +- include/spanningTree/pgr_randomSpanningTree.hpp | 2 +- include/topologicalSort/topologicalSort.hpp | 2 +- include/trsp/trspHandler.hpp | 2 +- include/withPoints/withPoints.hpp | 2 +- include/yen/ksp.hpp | 2 +- include/yen/turnRestrictedPath.hpp | 2 +- src/bellman_ford/edwardMoore_driver.cpp | 2 +- src/coloring/bipartite_driver.cpp | 2 +- src/common/CMakeLists.txt | 2 +- src/common/path.cpp | 4 ++-- src/cpp_common/combinations.cpp | 2 +- src/cpp_common/compPaths.cpp | 2 +- src/dominator/lengauerTarjanDominatorTree_driver.cpp | 2 +- src/ksp/turnRestrictedPath_driver.cpp | 2 +- src/transitiveClosure/transitiveClosure_driver.cpp | 2 +- src/trsp/trspHandler.cpp | 2 +- 31 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/astar/astar.hpp b/include/astar/astar.hpp index c00ec0c00d3..09d17ff3403 100644 --- a/include/astar/astar.hpp +++ b/include/astar/astar.hpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "visitors/astar_visitors.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "c_types/ii_t_rt.h" diff --git a/include/bdAstar/bdAstar.hpp b/include/bdAstar/bdAstar.hpp index 3c0e160aa2f..576c3b1b943 100644 --- a/include/bdAstar/bdAstar.hpp +++ b/include/bdAstar/bdAstar.hpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/bidirectional.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/include/bdDijkstra/bdDijkstra.hpp b/include/bdDijkstra/bdDijkstra.hpp index c698430b979..298bd90239a 100644 --- a/include/bdDijkstra/bdDijkstra.hpp +++ b/include/bdDijkstra/bdDijkstra.hpp @@ -38,7 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/bidirectional.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/include/bellman_ford/bellman_ford.hpp b/include/bellman_ford/bellman_ford.hpp index 3134c5bf9cf..ef1e073eace 100644 --- a/include/bellman_ford/bellman_ford.hpp +++ b/include/bellman_ford/bellman_ford.hpp @@ -44,7 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include "cpp_common/messages.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "c_types/ii_t_rt.h" diff --git a/include/bellman_ford/edwardMoore.hpp b/include/bellman_ford/edwardMoore.hpp index d5fe38680e1..dca4660bd34 100644 --- a/include/bellman_ford/edwardMoore.hpp +++ b/include/bellman_ford/edwardMoore.hpp @@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" diff --git a/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp b/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp index a3026be2c22..44ba5df543f 100644 --- a/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp +++ b/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/assert.hpp" diff --git a/include/circuits/hawickcircuits.hpp b/include/circuits/hawickcircuits.hpp index 2367ecbe734..08ba3b1d1dd 100644 --- a/include/circuits/hawickcircuits.hpp +++ b/include/circuits/hawickcircuits.hpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "cpp_common/assert.hpp" diff --git a/include/cpp_common/bidirectional.hpp b/include/cpp_common/bidirectional.hpp index 307a34affa3..ba3d4e57629 100644 --- a/include/cpp_common/bidirectional.hpp +++ b/include/cpp_common/bidirectional.hpp @@ -49,7 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/assert.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" diff --git a/include/cpp_common/combinations.hpp b/include/cpp_common/combinations.hpp index 9123b9674af..0ba3c8c7398 100644 --- a/include/cpp_common/combinations.hpp +++ b/include/cpp_common/combinations.hpp @@ -38,7 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/ii_t_rt.h" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/rule.hpp" diff --git a/include/cpp_common/compPaths.hpp b/include/cpp_common/compPaths.hpp index 69fc7db6516..cec2a769615 100644 --- a/include/cpp_common/compPaths.hpp +++ b/include/cpp_common/compPaths.hpp @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_CPP_COMMON_COMPPATHS_HPP_ #pragma once -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/include/cpp_common/path.hpp b/include/cpp_common/path.hpp index f55808eea24..5f0875b3b37 100644 --- a/include/cpp_common/path.hpp +++ b/include/cpp_common/path.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: basePath_SSEC.hpp +File: path.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/include/dagShortestPath/dagShortestPath.hpp b/include/dagShortestPath/dagShortestPath.hpp index e15eecc66ce..60a05a60935 100644 --- a/include/dagShortestPath/dagShortestPath.hpp +++ b/include/dagShortestPath/dagShortestPath.hpp @@ -44,7 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" diff --git a/include/dijkstra/dijkstra.hpp b/include/dijkstra/dijkstra.hpp index 7ba860d9bf9..989bc0102e2 100644 --- a/include/dijkstra/dijkstra.hpp +++ b/include/dijkstra/dijkstra.hpp @@ -51,7 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_types/ii_t_rt.h" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "visitors/dijkstra_visitors.hpp" diff --git a/include/dijkstra/drivingDist.hpp b/include/dijkstra/drivingDist.hpp index d34ef120320..6ef40076c97 100644 --- a/include/dijkstra/drivingDist.hpp +++ b/include/dijkstra/drivingDist.hpp @@ -51,7 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "visitors/dijkstra_visitors.hpp" diff --git a/include/mincut/stoerWagner.hpp b/include/mincut/stoerWagner.hpp index a70a401969f..186102d9155 100644 --- a/include/mincut/stoerWagner.hpp +++ b/include/mincut/stoerWagner.hpp @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include #include #include diff --git a/include/spanningTree/pgr_randomSpanningTree.hpp b/include/spanningTree/pgr_randomSpanningTree.hpp index 70f5d8149c6..098d72e999d 100644 --- a/include/spanningTree/pgr_randomSpanningTree.hpp +++ b/include/spanningTree/pgr_randomSpanningTree.hpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/pgr_base_graph.hpp" #include "cpp_common/interruption.hpp" diff --git a/include/topologicalSort/topologicalSort.hpp b/include/topologicalSort/topologicalSort.hpp index 9b0044546a3..45756d45025 100644 --- a/include/topologicalSort/topologicalSort.hpp +++ b/include/topologicalSort/topologicalSort.hpp @@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/interruption.hpp" #include "c_types//i_rt.h" diff --git a/include/trsp/trspHandler.hpp b/include/trsp/trspHandler.hpp index 5f56797c3e1..fc6e332e209 100644 --- a/include/trsp/trspHandler.hpp +++ b/include/trsp/trspHandler.hpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "trsp/edgeInfo.hpp" #include "cpp_common/rule.hpp" #include "cpp_common/messages.hpp" diff --git a/include/withPoints/withPoints.hpp b/include/withPoints/withPoints.hpp index 05b3fc788c9..939d277b56c 100644 --- a/include/withPoints/withPoints.hpp +++ b/include/withPoints/withPoints.hpp @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/point_on_edge_t.hpp" #include "cpp_common/messages.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/include/yen/ksp.hpp b/include/yen/ksp.hpp index 6539e72cf4c..9d0df522fb7 100644 --- a/include/yen/ksp.hpp +++ b/include/yen/ksp.hpp @@ -47,7 +47,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/assert.hpp" #include "cpp_common/compPaths.hpp" #include "cpp_common/messages.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { namespace yen { diff --git a/include/yen/turnRestrictedPath.hpp b/include/yen/turnRestrictedPath.hpp index 27badadb528..0b89e649689 100644 --- a/include/yen/turnRestrictedPath.hpp +++ b/include/yen/turnRestrictedPath.hpp @@ -39,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "yen/ksp.hpp" #include "cpp_common/assert.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/compPaths.hpp" #include "cpp_common/messages.hpp" #include "cpp_common/rule.hpp" diff --git a/src/bellman_ford/edwardMoore_driver.cpp b/src/bellman_ford/edwardMoore_driver.cpp index 9bf4b971692..d0823753641 100644 --- a/src/bellman_ford/edwardMoore_driver.cpp +++ b/src/bellman_ford/edwardMoore_driver.cpp @@ -42,7 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/combinations.hpp" #include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/alloc.hpp" #include "cpp_common/assert.hpp" diff --git a/src/coloring/bipartite_driver.cpp b/src/coloring/bipartite_driver.cpp index 3bf178dfd11..13873212a9f 100644 --- a/src/coloring/bipartite_driver.cpp +++ b/src/coloring/bipartite_driver.cpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/ii_t_rt.h" #include "cpp_common/identifiers.hpp" #include "cpp_common/alloc.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "drivers/coloring/bipartite_driver.h" #include "coloring/bipartite_driver.hpp" diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 824ad178b02..3d417393e8f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,7 +1,7 @@ ADD_LIBRARY(common OBJECT postgres_connection.c e_report.c - basePath_SSEC.cpp + path.cpp check_parameters.c diff --git a/src/common/path.cpp b/src/common/path.cpp index 23a7f84e29f..1214cf780c7 100644 --- a/src/common/path.cpp +++ b/src/common/path.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: basePath_SSEC.cpp +File: path.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include #include diff --git a/src/cpp_common/combinations.cpp b/src/cpp_common/combinations.cpp index ee71afeb2dd..ee066574b41 100644 --- a/src/cpp_common/combinations.cpp +++ b/src/cpp_common/combinations.cpp @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/combinations.hpp" #include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/src/cpp_common/compPaths.cpp b/src/cpp_common/compPaths.cpp index 31bb11368c7..5827b6771ad 100644 --- a/src/cpp_common/compPaths.cpp +++ b/src/cpp_common/compPaths.cpp @@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/assert.hpp" #include "cpp_common/compPaths.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" namespace pgrouting { diff --git a/src/dominator/lengauerTarjanDominatorTree_driver.cpp b/src/dominator/lengauerTarjanDominatorTree_driver.cpp index f9e4d745a83..ee9afebf354 100644 --- a/src/dominator/lengauerTarjanDominatorTree_driver.cpp +++ b/src/dominator/lengauerTarjanDominatorTree_driver.cpp @@ -38,7 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/pgdata_getters.hpp" #include "cpp_common/identifiers.hpp" #include "cpp_common/alloc.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "c_types/ii_t_rt.h" #include "dominator/lengauerTarjanDominatorTree_driver.hpp" diff --git a/src/ksp/turnRestrictedPath_driver.cpp b/src/ksp/turnRestrictedPath_driver.cpp index bfaa53c29b8..47c560f515d 100644 --- a/src/ksp/turnRestrictedPath_driver.cpp +++ b/src/ksp/turnRestrictedPath_driver.cpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/alloc.hpp" #include "cpp_common/combinations.hpp" #include "cpp_common/restriction_t.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "yen/turnRestrictedPath.hpp" namespace { diff --git a/src/transitiveClosure/transitiveClosure_driver.cpp b/src/transitiveClosure/transitiveClosure_driver.cpp index 78e23f01cb6..02a81039f54 100644 --- a/src/transitiveClosure/transitiveClosure_driver.cpp +++ b/src/transitiveClosure/transitiveClosure_driver.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/pgdata_getters.hpp" #include "cpp_common/identifiers.hpp" #include "cpp_common/alloc.hpp" -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "c_types/transitiveClosure_rt.h" diff --git a/src/trsp/trspHandler.cpp b/src/trsp/trspHandler.cpp index b14f472b954..3b737d1e7c7 100644 --- a/src/trsp/trspHandler.cpp +++ b/src/trsp/trspHandler.cpp @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/path.hpp" #include "cpp_common/assert.hpp" namespace pgrouting { From 0d0a807d4544440b7e7753ec5bdfbd5376912bff Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sat, 23 Aug 2025 09:29:13 -0600 Subject: [PATCH 3/5] (clang-tidy) fix-google-readability-braces-around-statements --- .clang-tidy | 1 - include/chinese/chinesePostman.hpp | 6 +++-- include/dijkstra/drivingDist.hpp | 3 ++- include/max_flow/minCostMaxFlow.hpp | 4 +-- include/spanningTree/mst.hpp | 3 ++- include/visitors/dfs_visitor.hpp | 3 ++- src/common/ch_edge.cpp | 3 ++- src/common/ch_vertex.cpp | 4 +-- src/common/path.cpp | 8 +++--- src/cpp_common/compPaths.cpp | 18 +++++-------- src/cpp_common/get_check_data.cpp | 6 +++-- src/dijkstra/dijkstraVia_driver.cpp | 3 ++- src/ksp/withPoints_ksp_driver.cpp | 3 ++- src/max_flow/minCostMaxFlow.cpp | 12 ++++----- src/pickDeliver/solution.cpp | 30 +++++++-------------- src/pickDeliver/vehicle.cpp | 36 +++++++++---------------- src/trsp/trspHandler.cpp | 3 +-- src/trsp/trspVia_driver.cpp | 3 ++- src/trsp/trspVia_withPoints_driver.cpp | 3 ++- src/withPoints/withPointsVia_driver.cpp | 3 ++- 20 files changed, 67 insertions(+), 88 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 5531449dd96..1c483387e8f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,5 @@ Checks: > google-*, - -google-readability-braces-around-statements, -google-readability-casting, clang-analyzer-*, clang-diagnostic-*, diff --git a/include/chinese/chinesePostman.hpp b/include/chinese/chinesePostman.hpp index dc6adba91e9..9b364124008 100644 --- a/include/chinese/chinesePostman.hpp +++ b/include/chinese/chinesePostman.hpp @@ -187,10 +187,12 @@ PgrDirectedChPPGraph::PgrDirectedChPPGraph(const std::vector &dataEdges) edge.cost = 0.0; edge.capacity = std::abs(d); edge.edge_id = 0; - if (d > 0) + if (d > 0) { edge.source = p, edge.target = superTarget; - if (d < 0) + } + if (d < 0) { edge.source = superSource, edge.target = p; + } edges.push_back(edge); } diff --git a/include/dijkstra/drivingDist.hpp b/include/dijkstra/drivingDist.hpp index 6ef40076c97..7441874377a 100644 --- a/include/dijkstra/drivingDist.hpp +++ b/include/dijkstra/drivingDist.hpp @@ -405,8 +405,9 @@ std::deque drivingDistance_with_equicost( */ for (const auto &root : roots) { for (auto &p : pred) { - if (!p.empty() && graph.has_vertex(root)) + if (!p.empty() && graph.has_vertex(root)) { p[graph.get_V(root)] = graph.get_V(root); + } } } diff --git a/include/max_flow/minCostMaxFlow.hpp b/include/max_flow/minCostMaxFlow.hpp index 35a4ad0231c..5609c94ba61 100644 --- a/include/max_flow/minCostMaxFlow.hpp +++ b/include/max_flow/minCostMaxFlow.hpp @@ -88,9 +88,7 @@ class PgrCostFlowGraph { } int64_t GetEdgeId(E e) const { - if (eToId.find(e) == eToId.end()) - return -1; - return eToId.at(e); + return eToId.find(e) == eToId.end()? -1 : eToId.at(e); } void SetSupersource( diff --git a/include/spanningTree/mst.hpp b/include/spanningTree/mst.hpp index 1dda2c6bf60..10090542838 100644 --- a/include/spanningTree/mst.hpp +++ b/include/spanningTree/mst.hpp @@ -362,8 +362,9 @@ class Pgr_mst { bool no_neg_costs(const G &graph) { E_i ei, ei_end; - for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ++ei) + for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ++ei) { pgassert(graph[*ei].cost > 0); + } return true; } }; diff --git a/include/visitors/dfs_visitor.hpp b/include/visitors/dfs_visitor.hpp index 0a4fcc1c758..0d19dc5402e 100644 --- a/include/visitors/dfs_visitor.hpp +++ b/include/visitors/dfs_visitor.hpp @@ -68,8 +68,9 @@ class Dfs_visitor : public boost::default_dfs_visitor { void examine_edge(E e, const B_G&) { auto source = m_graph.source(e), target = m_graph.target(e); // If the target has not been visited before - if (m_depth[target] == 0 && target != m_roots) + if (m_depth[target] == 0 && target != m_roots) { m_depth[target] = m_depth[source] + 1; + } // If the max_depth is reached, mark the target as visited, and push the corresponding edge if (m_depth[target] == m_max_depth && m_colors[target] != 4) { diff --git a/src/common/ch_edge.cpp b/src/common/ch_edge.cpp index 76a62b789ca..3df3673f780 100644 --- a/src/common/ch_edge.cpp +++ b/src/common/ch_edge.cpp @@ -70,8 +70,9 @@ CH_edge::add_contracted_vertex(CH_vertex& v) { void CH_edge::add_contracted_edge_vertices(CH_edge &e) { - if (e.has_contracted_vertices()) + if (e.has_contracted_vertices()) { m_contracted_vertices += e.contracted_vertices(); + } } void CH_edge::add_contracted_vertices(Identifiers& ids) { diff --git a/src/common/ch_vertex.cpp b/src/common/ch_vertex.cpp index 11ad13c5ac4..5c08ece597b 100644 --- a/src/common/ch_vertex.cpp +++ b/src/common/ch_vertex.cpp @@ -55,9 +55,7 @@ Identifiers& bool CH_vertex::has_contracted_vertices() const { - if (m_contracted_vertices.size() == 0) - return false; - return true; + return (m_contracted_vertices.size() == 0); } void CH_vertex::add_contracted_vertex(CH_vertex& v) { diff --git a/src/common/path.cpp b/src/common/path.cpp index 1214cf780c7..bdcd96a7f6b 100644 --- a/src/common/path.cpp +++ b/src/common/path.cpp @@ -168,10 +168,9 @@ bool Path::isEqual(const Path &subpath) const { if (subpath.empty()) return true; if (subpath.size() >= path.size()) return false; std::deque< Path_t >::const_iterator i, j; - for (i = path.begin(), j = subpath.begin(); - j != subpath.end(); - ++i, ++j) + for (i = path.begin(), j = subpath.begin(); j != subpath.end(); ++i, ++j) { if ((*i).node != (*j).node) return false; + } return true; } @@ -319,8 +318,9 @@ collapse_paths( const std::deque< Path > &paths) { size_t sequence = 0; for (const Path &path : paths) { - if (path.path.size() > 0) + if (path.path.size() > 0) { path.generate_postgres_data(ret_path, sequence); + } } return sequence; } diff --git a/src/cpp_common/compPaths.cpp b/src/cpp_common/compPaths.cpp index 5827b6771ad..e56b5dfeb24 100644 --- a/src/cpp_common/compPaths.cpp +++ b/src/cpp_common/compPaths.cpp @@ -44,17 +44,13 @@ bool compPathsLess::operator()(const Path &p1, const Path &p2) const { if (!(std::fabs(p2.tot_cost() - p1.tot_cost()) < std::numeric_limits::epsilon())) { - if (p1.tot_cost() > p2.tot_cost()) - return false; - if (p1.tot_cost() < p2.tot_cost()) - return true; + if (p1.tot_cost() > p2.tot_cost()) return false; + if (p1.tot_cost() < p2.tot_cost()) return true; } // paths costs are equal now check by length - if (p1.size() > p2.size()) - return false; - if (p1.size() < p2.size()) - return true; + if (p1.size() > p2.size()) return false; + if (p1.size() < p2.size()) return true; // pgassert(p1.tot_cost() == p2.tot_cost()); pgassert(p1.size() == p2.size()); @@ -62,10 +58,8 @@ bool compPathsLess::operator()(const Path &p1, const Path &p2) const { // paths weights & lengths are equal now check by node ID unsigned int i; for (i = 0; i < p1.size(); i++) { - if (p1[i].node > p2[i].node) - return false; - if (p1[i].node < p2[i].node) - return true; + if (p1[i].node > p2[i].node) return false; + if (p1[i].node < p2[i].node) return true; } // pgassert(p1.tot_cost() == p2.tot_cost()); diff --git a/src/cpp_common/get_check_data.cpp b/src/cpp_common/get_check_data.cpp index e4a8bf0fc3a..a28504ce558 100644 --- a/src/cpp_common/get_check_data.cpp +++ b/src/cpp_common/get_check_data.cpp @@ -560,8 +560,9 @@ int64_t getBigInt( bool isnull; int64_t value = 0; binval = SPI_getbinval(tuple, tupdesc, info.colNumber, &isnull); - if (isnull) + if (isnull) { throw std::string("Unexpected Null value in column ") + info.name; + } switch (info.type) { case INT2OID: value = static_cast(DatumGetInt16(binval)); @@ -591,8 +592,9 @@ double getFloat8( Datum binval; bool isnull = false; binval = SPI_getbinval(tuple, tupdesc, info.colNumber, &isnull); - if (isnull) + if (isnull) { throw std::string("Unexpected Null value in column ") + info.name; + } switch (info.type) { case INT2OID: diff --git a/src/dijkstra/dijkstraVia_driver.cpp b/src/dijkstra/dijkstraVia_driver.cpp index 503fa1e697e..cd9fe67752f 100644 --- a/src/dijkstra/dijkstraVia_driver.cpp +++ b/src/dijkstra/dijkstraVia_driver.cpp @@ -80,8 +80,9 @@ get_route( p.recalculate_agg_cost(); } for (const auto &path : paths) { - if (path.size() > 0) + if (path.size() > 0) { get_path(route_id, path_id, path, ret_path, route_cost, sequence); + } ++path_id; } return sequence; diff --git a/src/ksp/withPoints_ksp_driver.cpp b/src/ksp/withPoints_ksp_driver.cpp index 8c0722a3bdd..8cf1575f60d 100644 --- a/src/ksp/withPoints_ksp_driver.cpp +++ b/src/ksp/withPoints_ksp_driver.cpp @@ -173,8 +173,9 @@ pgr_do_withPointsKsp( size_t sequence = 0; for (const auto &path : paths) { - if (path.size() > 0) + if (path.size() > 0) { path.get_pg_nksp_path(return_tuples, sequence); + } } if (count != sequence) { diff --git a/src/max_flow/minCostMaxFlow.cpp b/src/max_flow/minCostMaxFlow.cpp index 8bf71c61b3c..e33184a0364 100644 --- a/src/max_flow/minCostMaxFlow.cpp +++ b/src/max_flow/minCostMaxFlow.cpp @@ -130,10 +130,9 @@ PgrCostFlowGraph::GetMaxFlow() const { int64_t maxFlow = 0; E_it e, eEnd; for (boost::tie(e, eEnd) = boost::edges(graph); e != eEnd; ++e) { - if (((capacity[*e] - residual_capacity[*e]) > 0) && - ((*e).m_source == supersource)) - maxFlow += - static_cast(capacity[*e] - residual_capacity[*e]); + if (((capacity[*e] - residual_capacity[*e]) > 0) && ((*e).m_source == supersource)) { + maxFlow += static_cast(capacity[*e] - residual_capacity[*e]); + } } return maxFlow; } @@ -155,10 +154,11 @@ PgrCostFlowGraph::GetFlowEdges() const { edge.residual_capacity = static_cast(residual_capacity[*e]); edge.cost = weight[*e] * static_cast(edge.flow); - if (flowEdges.size() == 0) + if (flowEdges.size() == 0) { edge.agg_cost = edge.cost; - else + } else { edge.agg_cost = (flowEdges.back()).agg_cost + edge.cost; + } flowEdges.push_back(edge); } } diff --git a/src/pickDeliver/solution.cpp b/src/pickDeliver/solution.cpp index c4a8dedaddd..df42ca8a222 100644 --- a/src/pickDeliver/solution.cpp +++ b/src/pickDeliver/solution.cpp @@ -194,42 +194,32 @@ Solution::operator<(const Solution &s_rhs) const { /* * capacity violations */ - if (std::get<0>(lhs) < std::get<0>(rhs)) - return true; - if (std::get<0>(lhs) > std::get<0>(rhs)) - return false; + if (std::get<0>(lhs) < std::get<0>(rhs)) return true; + if (std::get<0>(lhs) > std::get<0>(rhs)) return false; /* * time window violations */ - if (std::get<1>(lhs) < std::get<1>(rhs)) - return true; - if (std::get<1>(lhs) > std::get<1>(rhs)) - return false; + if (std::get<1>(lhs) < std::get<1>(rhs)) return true; + if (std::get<1>(lhs) > std::get<1>(rhs)) return false; /* * fleet size */ - if (std::get<2>(lhs) < std::get<2>(rhs)) - return true; - if (std::get<2>(lhs) > std::get<2>(rhs)) - return false; + if (std::get<2>(lhs) < std::get<2>(rhs)) return true; + if (std::get<2>(lhs) > std::get<2>(rhs)) return false; /* * waiting time */ - if (std::get<3>(lhs) < std::get<3>(rhs)) - return true; - if (std::get<3>(lhs) > std::get<3>(rhs)) - return false; + if (std::get<3>(lhs) < std::get<3>(rhs)) return true; + if (std::get<3>(lhs) > std::get<3>(rhs)) return false; /* * duration */ - if (std::get<4>(lhs) < std::get<4>(rhs)) - return true; - if (std::get<4>(lhs) > std::get<4>(rhs)) - return false; + if (std::get<4>(lhs) < std::get<4>(rhs)) return true; + if (std::get<4>(lhs) > std::get<4>(rhs)) return false; return false; } diff --git a/src/pickDeliver/vehicle.cpp b/src/pickDeliver/vehicle.cpp index 700a2f98450..d97cec5770c 100644 --- a/src/pickDeliver/vehicle.cpp +++ b/src/pickDeliver/vehicle.cpp @@ -99,42 +99,32 @@ Vehicle::cost_compare(const Cost &lhs, const Cost &rhs) const { /* * capacity violations */ - if (std::get<1>(lhs) < std::get<1>(rhs)) - return true; - if (std::get<1>(lhs) > std::get<1>(rhs)) - return false; + if (std::get<1>(lhs) < std::get<1>(rhs)) return true; + if (std::get<1>(lhs) > std::get<1>(rhs)) return false; /* * time window violations */ - if (std::get<0>(lhs) < std::get<0>(rhs)) - return true; - if (std::get<0>(lhs) > std::get<0>(rhs)) - return false; + if (std::get<0>(lhs) < std::get<0>(rhs)) return true; + if (std::get<0>(lhs) > std::get<0>(rhs)) return false; /* * waiting time */ - if (std::get<3>(lhs) < std::get<3>(rhs)) - return true; - if (std::get<3>(lhs) > std::get<3>(rhs)) - return false; + if (std::get<3>(lhs) < std::get<3>(rhs)) return true; + if (std::get<3>(lhs) > std::get<3>(rhs)) return false; /* * duration */ - if (std::get<4>(lhs) < std::get<4>(rhs)) - return true; - if (std::get<4>(lhs) > std::get<4>(rhs)) - return false; + if (std::get<4>(lhs) < std::get<4>(rhs)) return true; + if (std::get<4>(lhs) > std::get<4>(rhs)) return false; /* * truck size */ - if (std::get<2>(lhs) < std::get<2>(rhs)) - return true; - if (std::get<2>(lhs) > std::get<2>(rhs)) - return false; + if (std::get<2>(lhs) < std::get<2>(rhs)) return true; + if (std::get<2>(lhs) > std::get<2>(rhs)) return false; return false; } @@ -201,8 +191,7 @@ Vehicle::erase(const Vehicle_node &node) { POS pos = 0; for ( ; pos < m_path.size() ; ++pos) { - if (node.idx() == m_path[pos].idx()) - break; + if (node.idx() == m_path[pos].idx()) break; } erase(pos); @@ -451,8 +440,7 @@ Vehicle::tau() const { log << "Truck " << id() << "(" << idx() << ")" << " ("; for (const auto &p_stop : m_path) { - if (!(p_stop == m_path.front())) - log << ", "; + if (!(p_stop == m_path.front())) log << ", "; log << p_stop.id(); } log << ")" << " \t(cv, twv, wait_time, duration) = (" diff --git a/src/trsp/trspHandler.cpp b/src/trsp/trspHandler.cpp index 3b737d1e7c7..decf9521478 100644 --- a/src/trsp/trspHandler.cpp +++ b/src/trsp/trspHandler.cpp @@ -208,8 +208,7 @@ double TrspHandler::getRestrictionCost( v_pos = m_parent[static_cast(edge_ind)].v_pos[static_cast(v_pos)]; edge_ind = static_cast(m_parent_ind); } - if (flag) - cost += rule.cost(); + cost += flag? rule.cost() : 0; } return cost; } diff --git a/src/trsp/trspVia_driver.cpp b/src/trsp/trspVia_driver.cpp index 9c8cefcd8f8..97a213a4c8d 100644 --- a/src/trsp/trspVia_driver.cpp +++ b/src/trsp/trspVia_driver.cpp @@ -124,8 +124,9 @@ get_route( p.recalculate_agg_cost(); } for (const auto &path : paths) { - if (path.size() > 0) + if (path.size() > 0) { get_path(route_id, path_id, path, ret_path, route_cost, sequence); + } ++path_id; } return sequence; diff --git a/src/trsp/trspVia_withPoints_driver.cpp b/src/trsp/trspVia_withPoints_driver.cpp index 3218f967699..04278f70c3c 100644 --- a/src/trsp/trspVia_withPoints_driver.cpp +++ b/src/trsp/trspVia_withPoints_driver.cpp @@ -122,8 +122,9 @@ get_route( p.recalculate_agg_cost(); } for (const auto &path : paths) { - if (path.size() > 0) + if (path.size() > 0) { get_path(route_id, path_id, path, ret_path, route_cost, sequence); + } ++path_id; } return sequence; diff --git a/src/withPoints/withPointsVia_driver.cpp b/src/withPoints/withPointsVia_driver.cpp index 78e6ef926e2..861ef296dae 100644 --- a/src/withPoints/withPointsVia_driver.cpp +++ b/src/withPoints/withPointsVia_driver.cpp @@ -82,8 +82,9 @@ get_route( p.recalculate_agg_cost(); } for (const auto &path : paths) { - if (path.size() > 0) + if (path.size() > 0) { get_path(route_id, path_id, path, ret_path, route_cost, sequence); + } ++path_id; } return sequence; From 0c054707aec2910ff1e0a37d234d490627063245 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sun, 24 Aug 2025 08:28:15 -0600 Subject: [PATCH 4/5] (C/C++) Reorganizing code: removing duplicated get_route code --- include/cpp_common/to_postgres.hpp | 10 ++- src/common/ch_vertex.cpp | 2 +- src/cpp_common/CMakeLists.txt | 1 + src/cpp_common/compPaths.cpp | 6 +- src/cpp_common/to_postgres.cpp | 113 ++++++++++++++++++++++++ src/dijkstra/dijkstraVia_driver.cpp | 79 ++--------------- src/trsp/trspVia_driver.cpp | 98 ++++---------------- src/trsp/trspVia_withPoints_driver.cpp | 95 ++++---------------- src/withPoints/withPointsVia_driver.cpp | 103 +++++---------------- 9 files changed, 187 insertions(+), 320 deletions(-) create mode 100644 src/cpp_common/to_postgres.cpp diff --git a/include/cpp_common/to_postgres.hpp b/include/cpp_common/to_postgres.hpp index 51cd131aa7e..7ae8d901f21 100644 --- a/include/cpp_common/to_postgres.hpp +++ b/include/cpp_common/to_postgres.hpp @@ -31,13 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/contractionHierarchies_rt.h" #include "c_types/iid_t_rt.h" +#include "c_types/routes_t.h" +#include "cpp_common/path.hpp" #include "cpp_common/base_graph.hpp" #include "cpp_common/alloc.hpp" #include "cpp_common/identifiers.hpp" namespace pgrouting { +namespace to_postgres { namespace detail { /** @brief Count results that are going to be passed to postgres @@ -68,8 +71,6 @@ count_rows( } // namespace detail -namespace to_postgres { - /** @brief Stored results on a vector are saved on a C array * * @param[in] graph Created graph with the base Graph @@ -203,6 +204,11 @@ void graph_to_tuple( } } +/* + * @brief Via Routes save on a C array + */ +size_t get_viaRoute(std::deque&, Routes_t**); + } // namespace to_postgres } // namespace pgrouting diff --git a/src/common/ch_vertex.cpp b/src/common/ch_vertex.cpp index 5c08ece597b..aaab68ae2e1 100644 --- a/src/common/ch_vertex.cpp +++ b/src/common/ch_vertex.cpp @@ -55,7 +55,7 @@ Identifiers& bool CH_vertex::has_contracted_vertices() const { - return (m_contracted_vertices.size() == 0); + return !m_contracted_vertices.empty(); } void CH_vertex::add_contracted_vertex(CH_vertex& v) { diff --git a/src/cpp_common/CMakeLists.txt b/src/cpp_common/CMakeLists.txt index 7bfffb2128d..0b6147d8969 100644 --- a/src/cpp_common/CMakeLists.txt +++ b/src/cpp_common/CMakeLists.txt @@ -6,6 +6,7 @@ ADD_LIBRARY(cpp_common OBJECT messages.cpp combinations.cpp + to_postgres.cpp get_check_data.cpp pgdata_fetchers.cpp pgdata_getters.cpp diff --git a/src/cpp_common/compPaths.cpp b/src/cpp_common/compPaths.cpp index e56b5dfeb24..a758b286041 100644 --- a/src/cpp_common/compPaths.cpp +++ b/src/cpp_common/compPaths.cpp @@ -44,15 +44,14 @@ bool compPathsLess::operator()(const Path &p1, const Path &p2) const { if (!(std::fabs(p2.tot_cost() - p1.tot_cost()) < std::numeric_limits::epsilon())) { - if (p1.tot_cost() > p2.tot_cost()) return false; - if (p1.tot_cost() < p2.tot_cost()) return true; + if (p1.tot_cost() > p2.tot_cost()) return false; + if (p1.tot_cost() < p2.tot_cost()) return true; } // paths costs are equal now check by length if (p1.size() > p2.size()) return false; if (p1.size() < p2.size()) return true; -// pgassert(p1.tot_cost() == p2.tot_cost()); pgassert(p1.size() == p2.size()); // paths weights & lengths are equal now check by node ID @@ -62,7 +61,6 @@ bool compPathsLess::operator()(const Path &p1, const Path &p2) const { if (p1[i].node < p2[i].node) return true; } -// pgassert(p1.tot_cost() == p2.tot_cost()); pgassert(p1.size() == p2.size()); #ifdef NDEBUG for (i = 0; i < p1.size(); i++) { diff --git a/src/cpp_common/to_postgres.cpp b/src/cpp_common/to_postgres.cpp new file mode 100644 index 00000000000..566e15c5f95 --- /dev/null +++ b/src/cpp_common/to_postgres.cpp @@ -0,0 +1,113 @@ +/*PGR-GNU***************************************************************** +File: to_postgres.cpp + +Copyright (c) 2025 pgRouting developers +Mail: project@pgrouting.org + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +********************************************************************PGR-GNU*/ + +#include "cpp_common/to_postgres.hpp" + +#include +#include + +#include "c_types/routes_t.h" + +#include "cpp_common/path.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" + +namespace { + +void +get_path( + int route_id, + int path_id, + const pgrouting::Path &path, + Routes_t **postgres_data, + double &route_agg_cost, + size_t &sequence) { + int path_seq = 0; + for (const auto e : path) { + (*postgres_data)[sequence] = { + route_id, + path_id, + path_seq, + path.start_id(), + path.end_id(), + e.node, + e.edge, + e.cost, + e.agg_cost, + route_agg_cost}; + route_agg_cost += path[path_seq].cost; + path_seq++; + ++sequence; + } +} + +} // namespace + +namespace pgrouting { +namespace to_postgres { + +/** + * @param[in] paths The set of Paths + * @param[out] tuples The C array of Route_t + * @returns number of tuples on the C array + * + * Currently works for + * - pgr_dijkstraVia + * - pgr_trspVia + * - pgr_trspVia_withPoints + * - pgr_withPointsVia + */ +size_t +get_viaRoute( + std::deque &paths, + Routes_t **tuples) { + pgassert(!(*tuples)); + + auto count = count_tuples(paths); + if (count == 0) return 0; + + (*tuples) = pgr_alloc(count, (*tuples)); + + size_t sequence = 0; + int path_id = 1; + int route_id = 1; + double route_agg_cost = 0; + for (auto &p : paths) { + p.recalculate_agg_cost(); + } + for (const auto &path : paths) { + if (path.size() > 0) { + ::get_path(route_id, path_id, path, tuples, route_agg_cost, sequence); + } + ++path_id; + } + (*tuples)[count - 1].edge = -2; + + pgassert(count == sequence); + + return sequence; +} + +} // namespace to_postgres +} // namespace pgrouting diff --git a/src/dijkstra/dijkstraVia_driver.cpp b/src/dijkstra/dijkstraVia_driver.cpp index cd9fe67752f..7b6bd687000 100644 --- a/src/dijkstra/dijkstraVia_driver.cpp +++ b/src/dijkstra/dijkstraVia_driver.cpp @@ -34,61 +34,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/routes_t.h" #include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/alloc.hpp" +#include "cpp_common/to_postgres.hpp" #include "cpp_common/assert.hpp" #include "dijkstra/dijkstraVia.hpp" -namespace { -void -get_path( - int route_id, - int path_id, - const pgrouting::Path &path, - Routes_t **postgres_data, - double &route_cost, - size_t &sequence) { - size_t i = 0; - for (const auto e : path) { - (*postgres_data)[sequence] = { - route_id, - path_id, - static_cast(i), - path.start_id(), - path.end_id(), - e.node, - e.edge, - e.cost, - e.agg_cost, - route_cost}; - route_cost += path[i].cost; - ++i; - ++sequence; - } -} - - -size_t -get_route( - Routes_t **ret_path, - std::deque &paths) { - size_t sequence = 0; - int path_id = 1; - int route_id = 1; - double route_cost = 0; // routes_agg_cost - for (auto &p : paths) { - p.recalculate_agg_cost(); - } - for (const auto &path : paths) { - if (path.size() > 0) { - get_path(route_id, path_id, path, ret_path, route_cost, sequence); - } - ++path_id; - } - return sequence; -} -} // namespace - void pgr_do_dijkstraVia( const char *edges_sql, @@ -97,7 +47,7 @@ pgr_do_dijkstraVia( bool directed, bool strict, bool U_turn_on_edge, - Routes_t** return_tuples, size_t* return_count, + Routes_t** return_tuples, size_t* return_count, char** log_msg, char** notice_msg, @@ -108,10 +58,11 @@ pgr_do_dijkstraVia( using pgrouting::pgr_free; using pgrouting::pgget::get_intArray; using pgrouting::pgget::get_edges; + using pgrouting::to_postgres::get_viaRoute; std::ostringstream log; - std::ostringstream err; std::ostringstream notice; + std::ostringstream err; const char *hint = nullptr; try { @@ -121,8 +72,6 @@ pgr_do_dijkstraVia( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - - auto via = get_intArray(viaArr, false); hint = edges_sql; @@ -130,12 +79,12 @@ pgr_do_dijkstraVia( if (edges.empty()) { *notice_msg = to_pg_msg("No edges found"); - *log_msg = hint? to_pg_msg(hint) : to_pg_msg(log); + *log_msg = to_pg_msg(edges_sql); return; } hint = nullptr; - std::dequepaths; + std::deque paths; if (directed) { pgrouting::DirectedGraph digraph; digraph.insert_edges(edges); @@ -158,23 +107,13 @@ pgr_do_dijkstraVia( log); } - size_t count(count_tuples(paths)); + (*return_count) = get_viaRoute(paths, return_tuples); - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - notice << - "No paths found"; - *log_msg = to_pg_msg(notice); + if ((*return_count) == 0) { + *log_msg = to_pg_msg("No paths found"); return; } - // get the space required to store all the paths - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; - *log_msg = to_pg_msg(log); *notice_msg = to_pg_msg(notice); } catch (AssertFailedException &except) { diff --git a/src/trsp/trspVia_driver.cpp b/src/trsp/trspVia_driver.cpp index 97a213a4c8d..44622104ac5 100644 --- a/src/trsp/trspVia_driver.cpp +++ b/src/trsp/trspVia_driver.cpp @@ -33,18 +33,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "dijkstra/dijkstraVia.hpp" #include "c_types/routes_t.h" #include "cpp_common/restriction_t.hpp" #include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/to_postgres.hpp" +#include "cpp_common/assert.hpp" #include "cpp_common/rule.hpp" #include "cpp_common/combinations.hpp" -#include "cpp_common/alloc.hpp" -#include "cpp_common/assert.hpp" +#include "dijkstra/dijkstraVia.hpp" #include "trsp/trspHandler.hpp" - namespace { /** @brief Orders results in terms of the via information */ @@ -85,52 +84,6 @@ post_process_trspvia(std::deque &paths, std::vector vi paths = ordered_paths; } -void -get_path( - int route_id, - int path_id, - const pgrouting::Path &path, - Routes_t **postgres_data, - double &route_cost, - size_t &sequence) { - size_t i = 0; - for (const auto e : path) { - (*postgres_data)[sequence] = { - route_id, - path_id, - static_cast(i), - path.start_id(), - path.end_id(), - e.node, - e.edge, - e.cost, - e.agg_cost, - route_cost}; - route_cost += path[i].cost; - ++i; - ++sequence; - } -} - -size_t -get_route( - Routes_t **ret_path, - std::deque &paths) { - size_t sequence = 0; - int path_id = 1; - int route_id = 1; - double route_cost = 0; // routes_agg_cost - for (auto &p : paths) { - p.recalculate_agg_cost(); - } - for (const auto &path : paths) { - if (path.size() > 0) { - get_path(route_id, path_id, path, ret_path, route_cost, sequence); - } - ++path_id; - } - return sequence; -} } // namespace void @@ -152,10 +105,12 @@ pgr_do_trspVia( using pgrouting::to_pg_msg; using pgrouting::pgr_free; using pgrouting::pgget::get_intArray; + using pgrouting::pgget::get_edges; + using pgrouting::to_postgres::get_viaRoute; std::ostringstream log; - std::ostringstream err; std::ostringstream notice; + std::ostringstream err; const char *hint = nullptr; try { @@ -164,12 +119,11 @@ pgr_do_trspVia( pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - if (!edges_sql) return; auto via = get_intArray(viaArr, false); hint = edges_sql; - auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + auto edges = get_edges(std::string(edges_sql), true, false); if (edges.empty()) { *notice_msg = to_pg_msg("No edges found"); @@ -178,8 +132,10 @@ pgr_do_trspVia( } hint = nullptr; - - + hint = restrictions_sql; + auto restrictions = restrictions_sql? + pgrouting::pgget::get_restrictions(std::string(restrictions_sql)) : std::vector(); + hint = nullptr; std::deque paths; if (directed) { @@ -204,30 +160,18 @@ pgr_do_trspVia( log); } - size_t count(count_tuples(paths)); + size_t count = count_tuples(paths); if (count == 0) { - notice << "No paths found"; - *log_msg = to_pg_msg(notice); - return; - } - - if (!restrictions_sql) { - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; + *log_msg = to_pg_msg("No paths found"); return; } /* - * When there are turn restrictions + * Exit with the current results when there are no restrictions */ - hint = restrictions_sql; - auto restrictions = pgrouting::pgget::get_restrictions(std::string(restrictions_sql)); if (restrictions.empty()) { - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; + (*return_count) = get_viaRoute(paths, return_tuples); return; } @@ -246,17 +190,7 @@ pgr_do_trspVia( } post_process_trspvia(paths, via); - count = count_tuples(paths); - - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - return; - } - - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; + (*return_count) = get_viaRoute(paths, return_tuples); *log_msg = to_pg_msg(log); *notice_msg = to_pg_msg(notice); diff --git a/src/trsp/trspVia_withPoints_driver.cpp b/src/trsp/trspVia_withPoints_driver.cpp index 04278f70c3c..9b1991d3816 100644 --- a/src/trsp/trspVia_withPoints_driver.cpp +++ b/src/trsp/trspVia_withPoints_driver.cpp @@ -30,10 +30,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include - #include "c_types/routes_t.h" #include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/alloc.hpp" +#include "cpp_common/to_postgres.hpp" #include "cpp_common/assert.hpp" #include "cpp_common/rule.hpp" #include "cpp_common/combinations.hpp" @@ -83,52 +82,6 @@ post_process_trspvia(std::deque &paths, std::vector vi paths = ordered_paths; } -void -get_path( - int route_id, - int path_id, - const pgrouting::Path &path, - Routes_t **postgres_data, - double &route_cost, - size_t &sequence) { - size_t i = 0; - for (const auto e : path) { - (*postgres_data)[sequence] = { - route_id, - path_id, - static_cast(i), - path.start_id(), - path.end_id(), - e.node, - e.edge, - e.cost, - e.agg_cost, - route_cost}; - route_cost += path[i].cost; - ++i; - ++sequence; - } -} - -size_t -get_route( - Routes_t **ret_path, - std::deque &paths) { - size_t sequence = 0; - int path_id = 1; - int route_id = 1; - double route_cost = 0; // routes_agg_cost - for (auto &p : paths) { - p.recalculate_agg_cost(); - } - for (const auto &path : paths) { - if (path.size() > 0) { - get_path(route_id, path_id, path, ret_path, route_cost, sequence); - } - ++path_id; - } - return sequence; -} } // namespace void @@ -144,8 +97,7 @@ pgr_do_trspVia_withPoints( bool details, bool strict, bool U_turn_on_edge, - - Routes_t** return_tuples, size_t *return_count, + Routes_t** return_tuples, size_t* return_count, char** log_msg, char** notice_msg, @@ -155,6 +107,9 @@ pgr_do_trspVia_withPoints( using pgrouting::to_pg_msg; using pgrouting::pgr_free; using pgrouting::pgget::get_intArray; + using pgrouting::pgget::get_edges; + using pgrouting::pgget::get_points; + using pgrouting::to_postgres::get_viaRoute; std::ostringstream log; std::ostringstream notice; @@ -171,17 +126,17 @@ pgr_do_trspVia_withPoints( auto via = get_intArray(viaArr, false); hint = points_sql; - auto points = pgrouting::pgget::get_points(std::string(points_sql)); + auto points = get_points(std::string(points_sql)); hint = edges_of_points_sql; - auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), true, false); + auto edges_of_points = get_edges(std::string(edges_of_points_sql), true, false); hint = edges_sql; - auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + auto edges = get_edges(std::string(edges_sql), true, false); if (edges.size() + edges_of_points.size() == 0) { *notice_msg = to_pg_msg("No edges found"); - *log_msg = hint? to_pg_msg(hint) : to_pg_msg(log); + *log_msg = to_pg_msg(edges_sql); return; } @@ -189,13 +144,14 @@ pgr_do_trspVia_withPoints( auto restrictions = restrictions_sql? pgrouting::pgget::get_restrictions(std::string(restrictions_sql)) : std::vector(); - /* Dealing with points */ + /* + * processing points + */ pgrouting::Pg_points_graph pg_graph( points, edges_of_points, true, driving_side, directed); - log << pg_graph.get_log(); if (pg_graph.has_error()) { log << pg_graph.get_log(); @@ -205,9 +161,6 @@ pgr_do_trspVia_withPoints( return; } - auto vertices(pgrouting::extract_vertices(edges)); - vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); - std::deque paths; if (directed) { pgrouting::DirectedGraph digraph; @@ -240,19 +193,15 @@ pgr_do_trspVia_withPoints( size_t count(count_tuples(paths)); if (count == 0) { - notice << "No paths found"; - *log_msg = to_pg_msg(notice); + *log_msg = to_pg_msg("No paths found"); return; } - if (!restrictions_sql || restrictions.empty()) { - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; + if (restrictions.empty()) { + (*return_count) = get_viaRoute(paths, return_tuples); return; } - std::vector ruleList; for (const auto &r : restrictions) { if (r.via) ruleList.push_back(pgrouting::trsp::Rule(r)); @@ -271,22 +220,12 @@ pgr_do_trspVia_withPoints( paths.insert(paths.end(), new_paths.begin(), new_paths.end()); } post_process_trspvia(paths, via); + if (!details) { for (auto &path : paths) path = pg_graph.eliminate_details(path); } - - count = count_tuples(paths); - - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - return; - } - - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; + (*return_count) = get_viaRoute(paths, return_tuples); *log_msg = to_pg_msg(log); *notice_msg = to_pg_msg(notice); diff --git a/src/withPoints/withPointsVia_driver.cpp b/src/withPoints/withPointsVia_driver.cpp index 861ef296dae..2c585bac323 100644 --- a/src/withPoints/withPointsVia_driver.cpp +++ b/src/withPoints/withPointsVia_driver.cpp @@ -32,80 +32,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include - #include "c_types/routes_t.h" #include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/alloc.hpp" +#include "cpp_common/to_postgres.hpp" #include "cpp_common/assert.hpp" #include "dijkstra/dijkstraVia.hpp" #include "withPoints/withPoints.hpp" -namespace { - -void -get_path( - int route_id, - int path_id, - const pgrouting::Path &path, - Routes_t **postgres_data, - double &route_cost, - size_t &sequence) { - size_t i = 0; - for (const auto e : path) { - (*postgres_data)[sequence] = { - route_id, - path_id, - static_cast(i), - path.start_id(), - path.end_id(), - e.node, - e.edge, - e.cost, - e.agg_cost, - route_cost}; - route_cost += path[i].cost; - ++i; - ++sequence; - } -} - - -size_t -get_route( - Routes_t **ret_path, - std::deque &paths) { - size_t sequence = 0; - int path_id = 1; - int route_id = 1; - double route_cost = 0; // routes_agg_cost - for (auto &p : paths) { - p.recalculate_agg_cost(); - } - for (const auto &path : paths) { - if (path.size() > 0) { - get_path(route_id, path_id, path, ret_path, route_cost, sequence); - } - ++path_id; - } - return sequence; -} - -} // namespace void pgr_do_withPointsVia( const char *edges_sql, const char *points_sql, const char *edges_of_points_sql, - ArrayType* starts, + ArrayType* viaArr, bool directed, char driving_side, bool details, bool strict, bool U_turn_on_edge, - - Routes_t** return_tuples, size_t *return_count, + Routes_t** return_tuples, size_t* return_count, char** log_msg, char** notice_msg, @@ -115,6 +62,9 @@ pgr_do_withPointsVia( using pgrouting::to_pg_msg; using pgrouting::pgr_free; using pgrouting::pgget::get_intArray; + using pgrouting::pgget::get_edges; + using pgrouting::pgget::get_points; + using pgrouting::to_postgres::get_viaRoute; std::ostringstream log; std::ostringstream notice; @@ -128,31 +78,29 @@ pgr_do_withPointsVia( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - auto via_vertices = get_intArray(starts, false); - - + auto via = get_intArray(viaArr, false); hint = points_sql; - auto points = pgrouting::pgget::get_points(std::string(points_sql)); + auto points = get_points(std::string(points_sql)); hint = edges_of_points_sql; - auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), true, false); + auto edges_of_points = get_edges(std::string(edges_of_points_sql), true, false); hint = edges_sql; - auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + auto edges = get_edges(std::string(edges_sql), true, false); if (edges.size() + edges_of_points.size() == 0) { *notice_msg = to_pg_msg("No edges found"); - *log_msg = hint? to_pg_msg(hint) : to_pg_msg(log); + *log_msg = to_pg_msg(edges_sql); return; } hint = nullptr; - /* * processing points */ - pgrouting::Pg_points_graph pg_graph(points, edges_of_points, + pgrouting::Pg_points_graph pg_graph( + points, edges_of_points, true, driving_side, directed); @@ -165,28 +113,25 @@ pgr_do_withPointsVia( return; } - auto vertices(pgrouting::extract_vertices(edges)); - vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); - std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices); + pgrouting::DirectedGraph digraph; digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); pgrouting::dijkstraVia( digraph, - via_vertices, + via, paths, strict, U_turn_on_edge, log); } else { - pgrouting::UndirectedGraph undigraph(vertices); + pgrouting::UndirectedGraph undigraph; undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); pgrouting::dijkstraVia( undigraph, - via_vertices, + via, paths, strict, U_turn_on_edge, @@ -197,21 +142,13 @@ pgr_do_withPointsVia( for (auto &path : paths) path = pg_graph.eliminate_details(path); } - size_t count(0); - count = count_tuples(paths); + (*return_count) = get_viaRoute(paths, return_tuples); - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - notice << "No paths found"; - *log_msg = to_pg_msg(notice); + if ((*return_count) == 0) { + *log_msg = to_pg_msg("No paths found"); return; } - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - (*return_count) = (get_route(return_tuples, paths)); - (*return_tuples)[count - 1].edge = -2; - *log_msg = to_pg_msg(log); *notice_msg = to_pg_msg(notice); } catch (AssertFailedException &except) { From c4ac68e7dbba73d958dbb64b15bc8af254759901 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 25 Aug 2025 09:18:39 -0600 Subject: [PATCH 5/5] (binaryBFS/pgtap) Fix update test, there was a spelling error --- .../edge_cases/edge_cases.pg | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pgtap/traversal/binaryBreadthFirstSearch/edge_cases/edge_cases.pg b/pgtap/traversal/binaryBreadthFirstSearch/edge_cases/edge_cases.pg index f9c1541d1a0..d9c2fc881ba 100644 --- a/pgtap/traversal/binaryBreadthFirstSearch/edge_cases/edge_cases.pg +++ b/pgtap/traversal/binaryBreadthFirstSearch/edge_cases/edge_cases.pg @@ -80,10 +80,18 @@ FROM pgr_binaryBreadthFirstSearch( ); -SELECT throws_ok('errorTestManyWeights', +SELECT + CASE WHEN min_lib_version('4.0.0') THEN + throws_ok('errorTestManyWeights', 'XX000', 'Graph Condition Failed: Graph should have at most two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!', - '17: Graph has more than 2 distinct weights'); + '17: Graph has more than 2 distinct weights') + ELSE + throws_ok('errorTestManyWeights', + 'XX000', + 'Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!', + '17: Graph has more than 2 distinct weights') + END; SELECT * INTO edges_invalid_2 FROM edges; UPDATE edges_invalid_2 SET cost = 2 WHERE cost = 0; @@ -98,10 +106,18 @@ FROM pgr_binaryBreadthFirstSearch( ); -SELECT throws_ok('errorTestNoZeroWeight', +SELECT + CASE WHEN min_lib_version('4.0.0') THEN + throws_ok('errorTestNoZeroWeight', 'XX000', 'Graph Condition Failed: Graph should have at most two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!', - '17: If graph has 2 distinct weights, one must be zero'); + '17: If graph has 2 distinct weights, one must be zero') + ELSE + throws_ok('errorTestNoZeroWeight', + 'XX000', + 'Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!', + '17: If graph has 2 distinct weights, one must be zero') + END; SELECT * FROM finish();