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(); } } }
int do_pgr_driving_many_to_dist(pgr_edge_t *data_edges, int64_t total_tuples, int64_t *start_vertex, int s_len, float8 distance, bool directedFlag, bool equiCostFlag, pgr_path_element3_t **ret_path, int *path_count, char ** err_msg) { try { // in c code this should this must have been checked: // 1) end_vertex is in the data_edges #if 0 // set to 1 if needed std::ostringstream log; #endif graphType gType = directedFlag? DIRECTED: UNDIRECTED; const int initial_size = 1; std::deque< Path >paths; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, boost_vertex_t, boost_edge_t > UndirectedGraph; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::bidirectionalS, boost_vertex_t, boost_edge_t > DirectedGraph; Pgr_dijkstra < DirectedGraph > digraph(gType, initial_size); Pgr_dijkstra < UndirectedGraph > undigraph(gType, initial_size); std::vector< int64_t > start_vertices(start_vertex, start_vertex + s_len); if (directedFlag) { digraph.initialize_graph(data_edges, total_tuples); digraph.dijkstra_dd(paths, start_vertices, distance); } else { undigraph.initialize_graph(data_edges, total_tuples); undigraph.dijkstra_dd(paths, start_vertices, distance); } if (equiCostFlag == false) { int count(count_tuples(paths)); if (count == 0) { *err_msg = strdup("NOTICE: No return values was found"); *ret_path = noPathFound3(-1, path_count, (*ret_path)); return 0; } *ret_path = pgr_get_memory3(count, (*ret_path)); int trueCount(collapse_paths(ret_path, paths)); *path_count = trueCount; // assert (count == trueCount); } else { Path path = equi_cost(paths); size_t count(path.size()); if (count == 0) { *err_msg = strdup("NOTICE: No return values was found"); *ret_path = noPathFound3(-1, path_count, (*ret_path)); return 0; } int trueCount = 0; *ret_path = pgr_get_memory3(count, (*ret_path)); path.dpPrint(ret_path, trueCount); *path_count = trueCount; // assert (count == trueCount); } #if 1 *err_msg = strdup("OK"); #else *err_msg = strdup(log.str().c_str()); #endif return EXIT_SUCCESS; } catch ( ... ) { *err_msg = strdup("Caught unknown expection!"); return -1; } }