void do_pgr_driving_many_to_dist( pgr_edge_t *data_edges, size_t total_tuples, int64_t *start_vertex, size_t s_len, float8 distance, bool directedFlag, bool equiCostFlag, General_path_element_t **ret_path, size_t *path_count, char ** err_msg) { try { graphType gType = directedFlag? DIRECTED: UNDIRECTED; const auto initial_size = total_tuples; std::deque< Path >paths; std::set< int64_t > s_start_vertices(start_vertex, start_vertex + s_len); std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end()); if (directedFlag) { Pgr_base_graph< DirectedGraph > digraph(gType, initial_size); digraph.graph_insert_data(data_edges, total_tuples); pgr_drivingDistance(digraph, paths, start_vertices, distance, equiCostFlag); } else { Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size); undigraph.graph_insert_data(data_edges, total_tuples); pgr_drivingDistance(undigraph, paths, start_vertices, distance, equiCostFlag); } size_t count(count_tuples(paths)); if (count == 0) { *err_msg = strdup("NOTICE: No return values was found"); *ret_path = noResult(path_count, (*ret_path)); return; } *ret_path = get_memory(count, (*ret_path)); auto trueCount(collapse_paths(ret_path, paths)); *path_count = trueCount; #ifndef DEBUG *err_msg = strdup("OK"); #else *err_msg = strdup(log.str().c_str()); #endif return; } catch ( ... ) { *err_msg = strdup("Caught unknown expection!"); *ret_path = noResult(path_count, (*ret_path)); return; } }
void do_pgr_driving_distance( pgr_edge_t *data_edges, size_t total_edges, int64_t start_vertex, float8 distance, bool directedFlag, General_path_element_t **ret_path, size_t *path_count, char **err_msg) { std::ostringstream log; try { // if it already has values there will be a leak // call with pointing to NULL *ret_path = NULL; log << "NOTICE: Started processing pgr_drivingDistance for 1 start_vid\n"; // in c code this should have been checked: // 1) start_vertex is in the data_edges DONE graphType gType = directedFlag? DIRECTED: UNDIRECTED; const auto initial_size = total_edges; Path path; if (directedFlag) { log << "NOTICE: Processing Directed graph\n"; Pgr_base_graph< DirectedGraph > digraph(gType, initial_size); digraph.graph_insert_data(data_edges, total_edges); pgr_drivingDistance(digraph, path, start_vertex, distance); } else { log << "NOTICE: Processing Undirected graph\n"; Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size); undigraph.graph_insert_data(data_edges, total_edges); pgr_drivingDistance(undigraph, path, start_vertex, distance); } log << "Returning number of tuples" << path.size() << "\n"; if (path.empty()) { log << "NOTICE: it should have at least the one for it self"; *err_msg = strdup(log.str().c_str()); *ret_path = noResult(path_count, (*ret_path)); return; } log << "NOTICE: Calculating the number of tuples \n"; auto count = path.size(); log << "NOTICE Count: " << count << " tuples\n"; *ret_path = get_memory(count, (*ret_path)); size_t sequence = 0; path.get_pg_dd_path(ret_path, sequence); *path_count = count; #ifndef DEBUG *err_msg = strdup("OK"); #else *err_msg = strdup(log.str().c_str()); #endif return; } catch ( ... ) { log << "NOTICE: unknown exception cought"; *err_msg = strdup(log.str().c_str()); *ret_path = noResult(path_count, (*ret_path)); return; } }
void process_drivingDistance(G &graph, const std::vector<std::string> &tokens) { std::string::size_type sz; if (tokens[1].compare("from") != 0) { std::cout << "missing 'from' kewyword\n"; return; } std::vector< int64_t > sources; unsigned int i_ptr = 2; for ( ; i_ptr < tokens.size(); ++i_ptr) { if (tokens[i_ptr].compare("dist") == 0) break; try { uint64_t start_vertex(stol(tokens[i_ptr], &sz)); sources.push_back(start_vertex); } catch(...) { break; } } if (i_ptr == tokens.size() || tokens[i_ptr].compare("dist") != 0) { std::cout << "drivDist: 'dist' kewyword not found\n"; return; } if (sources.size() == 0) { std::cout << "drivDist: No start value found\n"; return; } ++i_ptr; if (i_ptr == tokens.size()) { std::cout << " 'distance' value not found\n"; return; } double distance = stod(tokens[i_ptr], &sz); ++i_ptr; bool equiCost(false); if (i_ptr != tokens.size()) { if (tokens[i_ptr].compare("equi") != 0) { std::cout << " Unknown keyword '" << tokens[i_ptr] << "' found\n"; return; } else { equiCost = true; } } std::cout << "found " << sources.size() << "starting locations\n"; Pgr_dijkstra< G > fn_dijkstra; if (sources.size() == 1) { std::cout << "Performing pgr_DrivingDistance for single source\n"; Path path; pgr_drivingDistance(graph, path, sources[0], distance); std::cout << "\t\t\tTHE OPUTPUT\n"; std::cout << "seq\tfrom\tnode\tedge\tcost\n"; path.print_path(); } else { std::deque< Path > paths; pgr_drivingDistance(graph, paths, sources, distance); if (equiCost == false) { std::cout << "Performing pgr_DrivingDistance for multiple sources\n"; std::cout << "\t\t\tTHE OPUTPUT\n"; std::cout << "seq\tfrom\tnode\tedge\tcost\n"; for (const auto &path : paths) { if (sizeof(path) == 0) return; // no solution found path.print_path(); } } else { std::cout << "Performing pgr_DrivingDistance for multiple sources with equi-cost\n"; Path path = equi_cost(paths); std::cout << "\t\t\tTHE EquiCost OPUTPUT\n"; std::cout << "seq\tfrom\tnode\tedge\tcost\n"; path.print_path(); } } }