PGROUTING  3.2
trsp_driver.cpp File Reference
#include "drivers/trsp/trsp_driver.h"
#include <utility>
#include <vector>
#include <cstdint>
#include <sstream>
#include <algorithm>
#include "trsp/pgr_trspHandler.h"
#include "cpp_common/rule.h"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/pgr_alloc.hpp"
Include dependency graph for trsp_driver.cpp:

Go to the source code of this file.

Functions

void do_trsp (pgr_edge_t *edges, size_t total_edges, Restriction_t *restrictions, size_t restrictions_size, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_trsp()

void do_trsp ( pgr_edge_t edges,
size_t  total_edges,
Restriction_t restrictions,
size_t  restrictions_size,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 41 of file trsp_driver.cpp.

60  {
61  std::ostringstream log;
62  std::ostringstream err;
63  std::ostringstream notice;
64  try {
65  pgassert(*return_tuples == NULL);
66  pgassert(*return_count == 0);
67  pgassert(*log_msg == NULL);
68  pgassert(*notice_msg == NULL);
69  pgassert(*err_msg == NULL);
70 
71  std::vector<pgrouting::trsp::Rule> ruleList;
72  for (size_t i = 0; i < restrictions_size; ++i) {
73  ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i)));
74  }
75 
76  /*
77  * Inserting vertices into a c++ vector structure
78  */
79  std::vector<int64_t>
80  sources(start_vidsArr, start_vidsArr + size_start_vidsArr);
81  std::vector< int64_t >
82  targets(end_vidsArr, end_vidsArr + size_end_vidsArr);
83 
84  /*
85  * ordering and removing duplicates
86  */
87  std::sort(sources.begin(), sources.end());
88  sources.erase(
89  std::unique(sources.begin(), sources.end()),
90  sources.end());
91 
92  std::sort(targets.begin(), targets.end());
93  targets.erase(
94  std::unique(targets.begin(), targets.end()),
95  targets.end());
96 
97 
98 
100  edges,
101  total_edges,
102  directed,
103  ruleList);
104 
105  auto paths = gdef.process(
106  sources,
107  targets);
108 
109 
110  size_t count(0);
111  count = count_tuples(paths);
112 
113  if (count == 0) {
114  (*return_tuples) = NULL;
115  (*return_count) = 0;
116  return;
117  }
118 
119  (*return_tuples) = pgr_alloc(count, (*return_tuples));
120  (*return_count) = collapse_paths(return_tuples, paths);
121 
122 
123  *log_msg = log.str().empty()?
124  *log_msg :
125  pgr_msg(log.str().c_str());
126  *notice_msg = notice.str().empty()?
127  *notice_msg :
128  pgr_msg(notice.str().c_str());
129 
130  return;
131  } catch (AssertFailedException &except) {
132  (*return_tuples) = pgr_free(*return_tuples);
133  (*return_count) = 0;
134  err << except.what();
135  *err_msg = pgr_msg(err.str().c_str());
136  *log_msg = pgr_msg(log.str().c_str());
137  } catch (std::exception &except) {
138  (*return_tuples) = pgr_free(*return_tuples);
139  (*return_count) = 0;
140  err << except.what();
141  *err_msg = pgr_msg(err.str().c_str());
142  *log_msg = pgr_msg(log.str().c_str());
143  } catch(...) {
144  (*return_tuples) = pgr_free(*return_tuples);
145  (*return_count) = 0;
146  err << "Caught unknown exception!";
147  *err_msg = pgr_msg(err.str().c_str());
148  *log_msg = pgr_msg(log.str().c_str());
149  }
150 }

References collapse_paths(), count_tuples(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), pgrouting::trsp::Pgr_trspHandler::process(), and AssertFailedException::what().

Referenced by compute_trsp().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgrouting::trsp::Pgr_trspHandler
Definition: pgr_trspHandler.h:52
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
collapse_paths
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:310
pgrouting::trsp::Rule
Definition: rule.h:39
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139