PGROUTING  3.2
turnRestrictedPath_driver.cpp File Reference
#include "drivers/yen/turnRestrictedPath_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <string>
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/rule.h"
#include "cpp_common/basePath_SSEC.hpp"
#include "yen/pgr_turnRestrictedPath.hpp"
Include dependency graph for turnRestrictedPath_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_turnRestrictedPath (pgr_edge_t *data_edges, size_t total_edges, Restriction_t *restrictions, size_t total_restrictions, int64_t start_vid, int64_t end_vid, size_t k, bool directed, bool heap_paths, bool stop_on_first, 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 std::deque< Pathpgr_dijkstraTR (G &graph, const std::vector< pgrouting::trsp::Rule > &restrictions, int64_t source, int64_t target, std::string &log, size_t k, bool heap_paths, bool stop_on_first, bool strict)
 

Function Documentation

◆ do_pgr_turnRestrictedPath()

void do_pgr_turnRestrictedPath ( pgr_edge_t data_edges,
size_t  total_edges,
Restriction_t restrictions,
size_t  total_restrictions,
int64_t  start_vid,
int64_t  end_vid,
size_t  k,
bool  directed,
bool  heap_paths,
bool  stop_on_first,
bool  strict,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 77 of file turnRestrictedPath_driver.cpp.

98  {
99  std::ostringstream log;
100  std::ostringstream err;
101  std::ostringstream notice;
102  try {
103  pgassert(!(*log_msg));
104  pgassert(!(*notice_msg));
105  pgassert(!(*err_msg));
106  pgassert(!(*return_tuples));
107  pgassert(*return_count == 0);
108  pgassert(total_edges != 0);
109 
110  std::vector<pgrouting::trsp::Rule> ruleList;
111  for (size_t i = 0; i < total_restrictions; ++i) {
112  ruleList.push_back(Rule(*(restrictions + i)));
113  }
114 
115  log << "\n---------------------------------------\nRestrictions data\n";
116  for (const auto &r : ruleList) {
117  log << r << "\n";
118  }
119  log <<"------------------------------------------------------------\n";
120 
121  graphType gType = directed? DIRECTED: UNDIRECTED;
122 
123  std::vector < pgr_edge_t > edges(data_edges, data_edges + total_edges);
124 
125  std::deque<Path> paths;
126 
127  std::string logstr;
128  if (directed) {
129  log << "Working with directed Graph\n";
130  pgrouting::DirectedGraph digraph(gType);
132  digraph.insert_edges(edges);
133  log << digraph;
134  paths = pgr_dijkstraTR(digraph,
135  ruleList,
136 
137  start_vid,
138  end_vid,
139 
140  logstr,
141  k,
142  heap_paths,
143  stop_on_first,
144  strict);
145  } else {
146  log << "TODO Working with Undirected Graph\n";
147  pgrouting::UndirectedGraph undigraph(gType);
149  undigraph.insert_edges(data_edges, total_edges);
150  paths = pgr_dijkstraTR(undigraph,
151  ruleList,
152 
153  start_vid,
154  end_vid,
155 
156  logstr,
157 
158  k,
159  heap_paths,
160  stop_on_first,
161  strict);
162  }
163 
164  log << logstr;
165 
166  auto count(count_tuples(paths));
167  log << "\nCount = " << count;
168 
169  if (!(count == 0)) {
170  *return_tuples = NULL;
171  *return_tuples = pgr_alloc(count, (*return_tuples));
172 
173  size_t sequence = 0;
174  int route_id = 0;
175  for (const auto &path : paths) {
176  if (path.size() > 0) {
177  path.get_pg_turn_restricted_path(
178  return_tuples,
179  sequence,
180  route_id);
181  }
182  log << "the agg cost" << (*return_tuples)[0].agg_cost;
183  ++route_id;
184  }
185  }
186  *return_count = count;
187 
188 
189  pgassert(*err_msg == NULL);
190  *log_msg = log.str().empty()?
191  *log_msg :
192  pgr_msg(log.str().c_str());
193  *notice_msg = notice.str().empty()?
194  *notice_msg :
195  pgr_msg(notice.str().c_str());
196  pgassert(!log.str().empty());
197  } catch (AssertFailedException &except) {
198  (*return_tuples) = pgr_free(*return_tuples);
199  (*return_count) = 0;
200  err << except.what();
201  *err_msg = pgr_msg(err.str().c_str());
202  *log_msg = pgr_msg(log.str().c_str());
203  } catch (std::exception &except) {
204  (*return_tuples) = pgr_free(*return_tuples);
205  (*return_count) = 0;
206  err << except.what();
207  *err_msg = pgr_msg(err.str().c_str());
208  *log_msg = pgr_msg(log.str().c_str());
209  } catch(...) {
210  (*return_tuples) = pgr_free(*return_tuples);
211  (*return_count) = 0;
212  err << "Caught unknown exception!";
213  *err_msg = pgr_msg(err.str().c_str());
214  *log_msg = pgr_msg(log.str().c_str());
215  }
216 }

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

Referenced by process().

◆ pgr_dijkstraTR()

template<class G >
static std::deque<Path> pgr_dijkstraTR ( G &  graph,
const std::vector< pgrouting::trsp::Rule > &  restrictions,
int64_t  source,
int64_t  target,
std::string &  log,
size_t  k,
bool  heap_paths,
bool  stop_on_first,
bool  strict 
)
static

Definition at line 51 of file turnRestrictedPath_driver.cpp.

60  {
62 
63  auto paths = fn_TRSP.turnRestrictedPath(graph,
64  restrictions,
65  source,
66  target,
67  k,
68  heap_paths,
69  stop_on_first,
70  strict);
71 
72  log += fn_TRSP.get_log();
73  return paths;
74 }

References pgrouting::Pgr_messages::get_log(), and pgrouting::yen::Pgr_turnRestrictedPath< G >::turnRestrictedPath().

Referenced by do_pgr_turnRestrictedPath().

Rule
struct Rule Rule
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
count_tuples
size_t count_tuples(const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:387
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgrouting::yen::Pgr_turnRestrictedPath
Definition: pgr_turnRestrictedPath.hpp:52
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::Pgr_messages::get_log
std::string get_log() const
get_log
Definition: pgr_messages.cpp:36
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgrouting::yen::Pgr_turnRestrictedPath::turnRestrictedPath
std::deque< Path > turnRestrictedPath(G &graph, const std::vector< pgrouting::trsp::Rule > &restrictions, int64_t source, int64_t target, size_t k, bool heap_paths, bool stop_on_first, bool strict)
Definition: pgr_turnRestrictedPath.hpp:106
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
pgr_dijkstraTR
static std::deque< Path > pgr_dijkstraTR(G &graph, const std::vector< pgrouting::trsp::Rule > &restrictions, int64_t source, int64_t target, std::string &log, size_t k, bool heap_paths, bool stop_on_first, bool strict)
Definition: turnRestrictedPath_driver.cpp:51
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139