pgRouting  2.2
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Functions Variables Pages
driving.cpp
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
4 Mail: project@pgrouting.org
5 
6 ------
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 
22 ********************************************************************PGR-GNU*/
23 void process_drivingDistance(G &graph, const std::vector<std::string> &tokens) {
24 
25  std::string::size_type sz;
26  if (tokens[1].compare("from") != 0) {
27  std::cout << "missing 'from' kewyword\n";
28  return;
29  }
30 
31  std::vector< int64_t > sources;
32  unsigned int i_ptr = 2;
33 
34  for ( ; i_ptr < tokens.size(); ++i_ptr) {
35  if (tokens[i_ptr].compare("dist") == 0) break;
36  try {
37  uint64_t start_vertex(stol(tokens[i_ptr], &sz));
38  sources.push_back(start_vertex);
39  } catch(...) {
40  break;
41  }
42  }
43 
44  if (i_ptr == tokens.size() || tokens[i_ptr].compare("dist") != 0) {
45  std::cout << "drivDist: 'dist' kewyword not found\n";
46  return;
47  }
48 
49  if (sources.size() == 0) {
50  std::cout << "drivDist: No start value found\n";
51  return;
52  }
53 
54  ++i_ptr;
55  if (i_ptr == tokens.size()) {
56  std::cout << " 'distance' value not found\n";
57  return;
58  }
59 
60  double distance = stod(tokens[i_ptr], &sz);
61 
62  ++i_ptr;
63  bool equiCost(false);
64  if (i_ptr != tokens.size()) {
65  if (tokens[i_ptr].compare("equi") != 0) {
66  std::cout << " Unknown keyword '" << tokens[i_ptr] << "' found\n";
67  return;
68  } else {
69  equiCost = true;
70  }
71  }
72 
73  std::cout << "found " << sources.size() << "starting locations\n";
74  Pgr_dijkstra< G > fn_dijkstra;
75 
76  if (sources.size() == 1) {
77  std::cout << "Performing pgr_DrivingDistance for single source\n";
78  Path path;
79  pgr_drivingDistance(graph, path, sources[0], distance);
80  std::cout << "\t\t\tTHE OPUTPUT\n";
81  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
82  path.print_path();
83  } else {
84  std::deque< Path > paths;
85  pgr_drivingDistance(graph, paths, sources, distance);
86  if (equiCost == false) {
87  std::cout << "Performing pgr_DrivingDistance for multiple sources\n";
88  std::cout << "\t\t\tTHE OPUTPUT\n";
89  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
90  for (const auto &path : paths) {
91  if (sizeof(path) == 0) return; //no solution found
92  path.print_path();
93  }
94  } else {
95  std::cout << "Performing pgr_DrivingDistance for multiple sources with equi-cost\n";
96  Path path = equi_cost(paths);
97  std::cout << "\t\t\tTHE EquiCost OPUTPUT\n";
98  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
99  path.print_path();
100  }
101  }
102 }
103