PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
driving.cpp
Go to the documentation of this file.
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 
24 #include <deque>
25 #include <string>
26 #include <vector>
27 
28 void process_drivingDistance(G &graph, const std::vector<std::string> &tokens) {
29  std::string::size_type sz;
30  if (tokens[1].compare("from") != 0) {
31  std::cout << "missing 'from' kewyword\n";
32  return;
33  }
34 
35  std::vector< int64_t > sources;
36  unsigned int i_ptr = 2;
37 
38  for ( ; i_ptr < tokens.size(); ++i_ptr) {
39  if (tokens[i_ptr].compare("dist") == 0) break;
40  try {
41  uint64_t start_vertex(stol(tokens[i_ptr], &sz));
42  sources.push_back(start_vertex);
43  } catch(...) {
44  break;
45  }
46  }
47 
48  if (i_ptr == tokens.size() || tokens[i_ptr].compare("dist") != 0) {
49  std::cout << "drivDist: 'dist' kewyword not found\n";
50  return;
51  }
52 
53  if (sources.size() == 0) {
54  std::cout << "drivDist: No start value found\n";
55  return;
56  }
57 
58  ++i_ptr;
59  if (i_ptr == tokens.size()) {
60  std::cout << " 'distance' value not found\n";
61  return;
62  }
63 
64  double distance = stod(tokens[i_ptr], &sz);
65 
66  ++i_ptr;
67  bool equiCost(false);
68  if (i_ptr != tokens.size()) {
69  if (tokens[i_ptr].compare("equi") != 0) {
70  std::cout << " Unknown keyword '" << tokens[i_ptr] << "' found\n";
71  return;
72  } else {
73  equiCost = true;
74  }
75  }
76 
77  std::cout << "found " << sources.size() << "starting locations\n";
78  Pgr_dijkstra< G > fn_dijkstra;
79 
80  if (sources.size() == 1) {
81  std::cout << "Performing pgr_DrivingDistance for single source\n";
82  Path path;
83  pgr_drivingDistance(graph, path, sources[0], distance);
84  std::cout << "\t\t\tTHE OPUTPUT\n";
85  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
86  path.print_path();
87  } else {
88  std::deque< Path > paths;
89  pgr_drivingDistance(graph, paths, sources, distance);
90  if (equiCost == false) {
91  std::cout << "Performing pgr_DrivingDistance for multiple sources\n";
92  std::cout << "\t\t\tTHE OPUTPUT\n";
93  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
94  for (const auto &path : paths) {
95  if (sizeof(path) == 0) return; // no solution found
96  path.print_path();
97  }
98  } else {
99  std::cout << "Performing pgr_DrivingDistance for multiple sources with equi-cost\n";
100  Path path = equi_cost(paths);
101  std::cout << "\t\t\tTHE EquiCost OPUTPUT\n";
102  std::cout << "seq\tfrom\tnode\tedge\tcost\n";
103  path.print_path();
104  }
105  }
106 }
107 
void process_drivingDistance(G &graph, const std::vector< std::string > &tokens)
Definition: driving.cpp:28
std::deque< Path > pgr_drivingDistance(G &graph, std::vector< int64_t > start_vids, double distance, bool equicost)
path_element_t * path
Definition: BDATester.cpp:49