PGROUTING  2.5
dijkstra.hpp File Reference
#include <deque>
#include <string>
#include <vector>
Include dependency graph for dijkstra.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename G >
void process_dijkstra (G &graph, const std::vector< std::string > &tokens)
 

Function Documentation

template<typename G >
void process_dijkstra ( G &  graph,
const std::vector< std::string > &  tokens 
)

Definition at line 29 of file dijkstra.hpp.

References Path::clear(), and pgr_dijkstra().

Referenced by process().

29  {
30  std::string::size_type sz;
31  if (tokens[1].compare("from") != 0) {
32  std::cout << "missing 'from' kewyword\n";
33  return;
34  }
35 
36  std::vector< int64_t > sources;
37  unsigned int i_ptr = 2;
38 
39  for ( ; i_ptr < tokens.size(); ++i_ptr) {
40  if (tokens[i_ptr].compare("to") == 0) break;
41  try {
42  uint64_t start_vertex(stol(tokens[i_ptr], &sz));
43  sources.push_back(start_vertex);
44  } catch(...) {
45  break;
46  }
47  }
48 
49  if (i_ptr == tokens.size() || tokens[i_ptr].compare("to") != 0) {
50  std::cout << "dijkstra: 'dist' kewyword not found\n";
51  return;
52  }
53 
54  if (sources.size() == 0) {
55  std::cout << "dijkstra: No start value found\n";
56  return;
57  }
58 
59  ++i_ptr;
60  if (i_ptr == tokens.size()) {
61  std::cout << "dijkstra: No 'to' values found\n";
62  return;
63  }
64 
65  std::vector< int64_t > targets;
66  for ( ; i_ptr < tokens.size(); ++i_ptr) {
67  auto end_vertex(stol(tokens[i_ptr], &sz));
68  targets.push_back(end_vertex);
69  }
70 
71 
72  if (sources.size() == 1 && targets.size() == 1) {
73  // one to one
74  Path path;
75  pgr_dijkstra(graph, path, sources[0], targets[0]);
76  std::cout << "THE OPUTPUT ----> total cost: " << path.cost << "\n";
77  path.print_path();
78  path.clear();
79 
80 
81  } else if (sources.size() == 1 && targets.size() > 1) {
82  // one to many
83  pgr_dijkstra(graph, paths, sources[0], targets);
84 
85  std::cout << "THE OPUTPUTS ----> total outputs: " << paths.size() << "\n";
86  for (unsigned int i = 0; i < paths.size(); ++i) {
87  if (sizeof(paths[i]) == 0) continue; // no solution found
88  std::cout << "Path #" << i << " cost: " << paths[i].cost << "\n";
89  paths[i].print_path();
90  }
91  } else if (sources.size() > 1 && targets.size() == 1) {
92  // many to 1
93  std::deque<Path> paths;
94  pgr_dijkstra(graph, paths, sources, targets[0]);
95 
96 
97  std::cout << "THE OPUTPUTS ----> total outputs: " << paths.size() << "\n";
98  for (unsigned int i = 0; i < paths.size(); ++i) {
99  if (sizeof(paths[i]) == 0) continue; // no solution found
100  std::cout << "Path #" << i << " cost: " << paths[i].cost << "\n";
101  paths[i].print_path();
102  }
103  } else {
104  // many to many
105  std::deque<Path> paths;
106  pgr_dijkstra(graph, paths, sources, targets);
107 
108  std::cout << "THE OPUTPUTS ----> total outputs: " << paths.size() << "\n";
109  for (unsigned int i = 0; i < paths.size(); ++i) {
110  if (sizeof(paths[i]) == 0) continue; // no solution found
111  std::cout << "Path #" << i << " cost: " << paths[i].cost << "\n";
112  paths[i].print_path();
113  }
114  }
115 }
std::deque< Path > pgr_dijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
void clear()

Here is the call graph for this function:

Here is the caller graph for this function: