@@ -34,61 +34,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3434
3535#include " c_types/routes_t.h"
3636#include " cpp_common/pgdata_getters.hpp"
37- #include " cpp_common/alloc .hpp"
37+ #include " cpp_common/to_postgres .hpp"
3838#include " cpp_common/assert.hpp"
3939#include " dijkstra/dijkstraVia.hpp"
4040
4141
42- namespace {
43- void
44- get_path (
45- int route_id,
46- int path_id,
47- const pgrouting::Path &path,
48- Routes_t **postgres_data,
49- double &route_cost,
50- size_t &sequence) {
51- size_t i = 0 ;
52- for (const auto e : path) {
53- (*postgres_data)[sequence] = {
54- route_id,
55- path_id,
56- static_cast <int >(i),
57- path.start_id (),
58- path.end_id (),
59- e.node ,
60- e.edge ,
61- e.cost ,
62- e.agg_cost ,
63- route_cost};
64- route_cost += path[i].cost ;
65- ++i;
66- ++sequence;
67- }
68- }
69-
70-
71- size_t
72- get_route (
73- Routes_t **ret_path,
74- std::deque<pgrouting::Path> &paths) {
75- size_t sequence = 0 ;
76- int path_id = 1 ;
77- int route_id = 1 ;
78- double route_cost = 0 ; // routes_agg_cost
79- for (auto &p : paths) {
80- p.recalculate_agg_cost ();
81- }
82- for (const auto &path : paths) {
83- if (path.size () > 0 ) {
84- get_path (route_id, path_id, path, ret_path, route_cost, sequence);
85- }
86- ++path_id;
87- }
88- return sequence;
89- }
90- } // namespace
91-
9242void
9343pgr_do_dijkstraVia (
9444 const char *edges_sql,
@@ -97,7 +47,7 @@ pgr_do_dijkstraVia(
9747 bool directed,
9848 bool strict,
9949 bool U_turn_on_edge,
100- Routes_t** return_tuples, size_t * return_count,
50+ Routes_t** return_tuples, size_t * return_count,
10151
10252 char ** log_msg,
10353 char ** notice_msg,
@@ -108,10 +58,11 @@ pgr_do_dijkstraVia(
10858 using pgrouting::pgr_free;
10959 using pgrouting::pgget::get_intArray;
11060 using pgrouting::pgget::get_edges;
61+ using pgrouting::to_postgres::get_viaRoute;
11162
11263 std::ostringstream log;
113- std::ostringstream err;
11464 std::ostringstream notice;
65+ std::ostringstream err;
11566 const char *hint = nullptr ;
11667
11768 try {
@@ -121,21 +72,19 @@ pgr_do_dijkstraVia(
12172 pgassert (!(*return_tuples));
12273 pgassert (*return_count == 0 );
12374
124-
125-
12675 auto via = get_intArray (viaArr, false );
12776
12877 hint = edges_sql;
12978 auto edges = get_edges (std::string (edges_sql), true , false );
13079
13180 if (edges.empty ()) {
13281 *notice_msg = to_pg_msg (" No edges found" );
133- *log_msg = hint? to_pg_msg (hint) : to_pg_msg (log );
82+ *log_msg = to_pg_msg (edges_sql );
13483 return ;
13584 }
13685 hint = nullptr ;
13786
138- std::deque<Path>paths;
87+ std::deque<Path> paths;
13988 if (directed) {
14089 pgrouting::DirectedGraph digraph;
14190 digraph.insert_edges (edges);
@@ -158,23 +107,13 @@ pgr_do_dijkstraVia(
158107 log);
159108 }
160109
161- size_t count ( count_tuples ( paths) );
110+ (*return_count) = get_viaRoute ( paths, return_tuples );
162111
163- if (count == 0 ) {
164- (*return_tuples) = NULL ;
165- (*return_count) = 0 ;
166- notice <<
167- " No paths found" ;
168- *log_msg = to_pg_msg (notice);
112+ if ((*return_count) == 0 ) {
113+ *log_msg = to_pg_msg (" No paths found" );
169114 return ;
170115 }
171116
172- // get the space required to store all the paths
173- (*return_tuples) = pgr_alloc (count, (*return_tuples));
174- log << " \n Converting a set of paths into the tuples" ;
175- (*return_count) = (get_route (return_tuples, paths));
176- (*return_tuples)[count - 1 ].edge = -2 ;
177-
178117 *log_msg = to_pg_msg (log);
179118 *notice_msg = to_pg_msg (notice);
180119 } catch (AssertFailedException &except) {
0 commit comments