PGROUTING  2.6-dev
dijkstraTRSP_driver.cpp File Reference
#include "drivers/dijkstraTRSP/dijkstraTRSP_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <string>
#include "dijkstraTRSP/pgr_dijkstraTRSP.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for dijkstraTRSP_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_dijkstraTRSP (pgr_edge_t *data_edges, size_t total_edges, Restrict_t *restrictions, size_t total_restrictions, int64_t start_vid, int64_t end_vid, bool directed, bool only_cost, bool strict, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
static Path pgr_dijkstraTRSP (G &graph, const std::vector< Restriction > &restrictions_array, const std::vector< pgr_edge_t > edges, int64_t source, int64_t target, std::string &log, bool only_cost=false, bool strict=false)
 

Function Documentation

void do_pgr_dijkstraTRSP ( pgr_edge_t data_edges,
size_t  total_edges,
Restrict_t *  restrictions,
size_t  total_restrictions,
int64_t  start_vid,
int64_t  end_vid,
bool  directed,
bool  only_cost,
bool  strict,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 69 of file dijkstraTRSP_driver.cpp.

References DIRECTED, Path::generate_postgres_data(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_dijkstraTRSP(), pgr_free(), pgr_msg(), Path::size(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

83  {
84  std::ostringstream log;
85  std::ostringstream err;
86  std::ostringstream notice;
87  try {
88  pgassert(!(*log_msg));
89  pgassert(!(*notice_msg));
90  pgassert(!(*err_msg));
91  pgassert(!(*return_tuples));
92  pgassert(*return_count == 0);
93  pgassert(total_edges != 0);
94 
95  log << "\n---------------------------------------\nRestrictions data\n";
96  std::vector< Restriction > restrict_array;
97  for (size_t i = 0; i < total_restrictions; i++) {
98  restrict_array.push_back(Restriction(restrictions[i]));
99  }
100  log << "\n-----------------------------------------\nStart from here\n";
101  for (const auto &it : restrict_array) {
102  log << it << "\n";
103  }
104  log <<"------------------------------------------------------------\n";
105 
106  graphType gType = directed? DIRECTED: UNDIRECTED;
107 
108  std::vector < pgr_edge_t > edges(data_edges, data_edges + total_edges);
109 
110  Path path;
111  std::string logstr;
112  if (directed) {
113  log << "Working with directed Graph\n";
114  pgrouting::DirectedGraph digraph(gType);
116  digraph.insert_edges(edges);
117  path = pgr_dijkstraTRSP(digraph,
118  restrict_array,
119  edges,
120  start_vid,
121  end_vid,
122  logstr,
123  only_cost,
124  strict);
125  } else {
126  log << "Working with Undirected Graph\n";
127  pgrouting::UndirectedGraph undigraph(gType);
129  undigraph.insert_edges(data_edges, total_edges);
130  #if 0
131  path = pgr_dijkstraTRSP(undigraph,
132  restrict_array,
133  edges,
134  start_vid,
135  end_vid,
136  logstr,
137  only_cost,
138  strict);
139  #endif
140  }
141  log << logstr;
142  auto count = path.size();
143  log << "\nCount = " << count;
144 
145  if (count == 0) {
146  (*return_tuples) = NULL;
147  (*return_count) = 0;
148  notice <<
149  "No paths found between start_vid and end_vid vertices";
150  } else {
151  (*return_tuples) = pgr_alloc(count, (*return_tuples));
152  size_t sequence = 0;
153  path.generate_postgres_data(return_tuples, sequence);
154  (*return_count) = sequence;
155  }
156 
157  pgassert(*err_msg == NULL);
158  *log_msg = log.str().empty()?
159  *log_msg :
160  pgr_msg(log.str().c_str());
161  #if 0
162  *notice_msg = notice.str().empty()?
163  *notice_msg :
164  pgr_msg(notice.str().c_str());
165  #endif
166  pgassert(!log.str().empty());
167  } catch (AssertFailedException &except) {
168  (*return_tuples) = pgr_free(*return_tuples);
169  (*return_count) = 0;
170  err << except.what();
171  *err_msg = pgr_msg(err.str().c_str());
172  *log_msg = pgr_msg(log.str().c_str());
173  } catch (std::exception &except) {
174  (*return_tuples) = pgr_free(*return_tuples);
175  (*return_count) = 0;
176  err << except.what();
177  *err_msg = pgr_msg(err.str().c_str());
178  *log_msg = pgr_msg(log.str().c_str());
179  } catch(...) {
180  (*return_tuples) = pgr_free(*return_tuples);
181  (*return_count) = 0;
182  err << "Caught unknown exception!";
183  *err_msg = pgr_msg(err.str().c_str());
184  *log_msg = pgr_msg(log.str().c_str());
185  }
186 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
static Path pgr_dijkstraTRSP(G &graph, const std::vector< Restriction > &restrictions_array, const std::vector< pgr_edge_t > edges, int64_t source, int64_t target, std::string &log, bool only_cost=false, bool strict=false)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
void generate_postgres_data(General_path_element_t **postgres_data, size_t &sequence) const
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
virtual const char * what() const
Definition: pgr_assert.cpp:53
graphType
Definition: graph_enum.h:30
size_t size() const

Here is the call graph for this function:

Here is the caller graph for this function:

template<class G >
static Path pgr_dijkstraTRSP ( G &  graph,
const std::vector< Restriction > &  restrictions_array,
const std::vector< pgr_edge_t edges,
int64_t  source,
int64_t  target,
std::string &  log,
bool  only_cost = false,
bool  strict = false 
)
static

Definition at line 46 of file dijkstraTRSP_driver.cpp.

References Pgr_dijkstraTRSP< G >::dijkstraTRSP(), and Pgr_dijkstraTRSP< G >::log.

Referenced by do_pgr_dijkstraTRSP().

54  {
55  Pgr_dijkstraTRSP< G > fn_TRSP;
56  Path path = fn_TRSP.dijkstraTRSP(graph,
57  restrictions_array,
58  edges,
59  source,
60  target,
61  only_cost,
62  strict);
63  log += fn_TRSP.log.str().c_str();
64  return path;
65 }
Path dijkstraTRSP(G &graph, const std::vector< Restriction > &restrictions, const std::vector< pgr_edge_t > &edges, int64_t source, int64_t target, bool only_cost, bool strict)
std::ostringstream log

Here is the call graph for this function:

Here is the caller graph for this function: