void do_pgr_dijkstraVia( pgr_edge_t* data_edges, size_t total_edges, int64_t* via_vidsArr, size_t size_via_vidsArr, bool directed, bool strict, bool U_turn_on_edge, Routes_t** return_tuples, size_t* return_count, char** log_msg, char** notice_msg, char** err_msg) { std::ostringstream log; std::ostringstream err; std::ostringstream notice; try { pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); graphType gType = directed? DIRECTED: UNDIRECTED; std::deque< Path >paths; log << "\nInserting vertices into a c++ vector structure"; std::vector< int64_t > via_vertices( via_vidsArr, via_vidsArr + size_via_vidsArr); if (directed) { log << "\nWorking with directed Graph"; pgrouting::DirectedGraph digraph(gType); digraph.insert_edges(data_edges, total_edges); pgr_dijkstraViaVertex( digraph, via_vertices, paths, strict, U_turn_on_edge, log); } else { log << "\nWorking with Undirected Graph"; pgrouting::UndirectedGraph undigraph(gType); undigraph.insert_edges(data_edges, total_edges); pgr_dijkstraViaVertex( undigraph, via_vertices, paths, strict, U_turn_on_edge, log); } size_t count(count_tuples(paths)); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; notice << "No paths found"; *log_msg = pgr_msg(notice.str().c_str()); 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 = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); *notice_msg = notice.str().empty()? *notice_msg : pgr_msg(notice.str().c_str()); } catch (AssertFailedException &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << "Caught unknown exception!"; *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } }
// CREATE OR REPLACE FUNCTION pgr_dijkstraViaVertices(sql text, vertices anyarray, directed boolean default true, void do_pgr_dijkstraViaVertex( pgr_edge_t *data_edges, size_t total_tuples, int64_t *via_vidsArr, size_t size_via_vidsArr, bool directed, bool strict, bool U_turn_on_edge, Routes_t **return_tuples, size_t *return_count, char ** err_msg){ std::ostringstream log; try { if (total_tuples == 1) { log << "Requiered: more than one tuple\n"; (*return_tuples) = NULL; (*return_count) = 0; *err_msg = strdup(log.str().c_str()); return; } graphType gType = directed? DIRECTED: UNDIRECTED; const auto initial_size = total_tuples; std::deque< Path >paths; log << "Inserting vertices into a c++ vector structure\n"; std::vector< int64_t > via_vertices(via_vidsArr, via_vidsArr + size_via_vidsArr); if (directed) { log << "Working with directed Graph\n"; Pgr_base_graph< DirectedGraph > digraph(gType, initial_size); digraph.graph_insert_data(data_edges, total_tuples); pgr_dijkstraViaVertex(digraph, via_vertices, paths, strict, U_turn_on_edge, log); } else { log << "Working with Undirected Graph\n"; Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size); undigraph.graph_insert_data(data_edges, total_tuples); pgr_dijkstraViaVertex(undigraph, via_vertices, paths, strict, U_turn_on_edge, log); } size_t count(count_tuples(paths)); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; log << "No paths found between Starting and any of the Ending vertices\n"; *err_msg = strdup(log.str().c_str()); return; } // get the space required to store all the paths (*return_tuples) = get_memory(count, (*return_tuples)); log << "Converting a set of paths into the tuples\n"; (*return_count) = (get_route(return_tuples, paths)); (*return_tuples)[count - 1].edge = -2; #ifndef DEBUG *err_msg = strdup("OK"); #else *err_msg = strdup(log.str().c_str()); #endif } catch ( ... ) { log << "Caught unknown expection!\n"; *err_msg = strdup(log.str().c_str()); } }