PGROUTING  2.6
trsp_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 File: trsp_driver.cpp
4 
5 Copyright (c) 2017 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24 ********************************************************************PGR-GNU*/
25 
26 
28 #include <utility>
29 #include <vector>
30 #include <cstdint>
31 #include <sstream>
32 #include <algorithm>
33 #include "trsp/pgr_trspHandler.h"
34 #include "trsp/rule.h"
35 #include "cpp_common/pgr_assert.h"
36 #include "cpp_common/pgr_alloc.hpp"
37 
38 
39 
40 void
42  pgr_edge_t *edges,
43  size_t total_edges,
44 
45  Restriction_t *restrictions,
46  size_t restrictions_size,
47 
48  int64_t *start_vidsArr,
49  size_t size_start_vidsArr,
50 
51  int64_t *end_vidsArr,
52  size_t size_end_vidsArr,
53 
54  bool directed,
55 
56  General_path_element_t **return_tuples,
57  size_t *return_count,
58  char **log_msg,
59  char **notice_msg,
60  char **err_msg) {
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 
72  std::vector<pgrouting::trsp::Rule> ruleList;
73  for (size_t i = 0; i < restrictions_size; ++i) {
74  ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i)));
75  }
76 
77  /*
78  * Inserting vertices into a c++ vector structure
79  */
80  std::vector<int64_t>
81  sources(start_vidsArr, start_vidsArr + size_start_vidsArr);
82  std::vector< int64_t >
83  targets(end_vidsArr, end_vidsArr + size_end_vidsArr);
84 
85  /*
86  * ordering and removing duplicates
87  */
88  std::sort(sources.begin(), sources.end());
89  sources.erase(
90  std::unique(sources.begin(), sources.end()),
91  sources.end());
92 
93  std::sort(targets.begin(), targets.end());
94  targets.erase(
95  std::unique(targets.begin(), targets.end()),
96  targets.end());
97 
98 
99 
101  edges,
102  total_edges,
103  directed,
104  ruleList);
105 
106  auto paths = gdef.process(
107  sources,
108  targets);
109 
110 
111  size_t count(0);
112  count = count_tuples(paths);
113 
114  if (count == 0) {
115  (*return_tuples) = NULL;
116  (*return_count) = 0;
117  return;
118  }
119 
120  (*return_tuples) = pgr_alloc(count, (*return_tuples));
121  (*return_count) = collapse_paths(return_tuples, paths);
122 
123 
124  return;
125  } catch (AssertFailedException &except) {
126  (*return_tuples) = pgr_free(*return_tuples);
127  (*return_count) = 0;
128  err << except.what();
129  *err_msg = pgr_msg(err.str().c_str());
130  *log_msg = pgr_msg(log.str().c_str());
131  } catch (std::exception &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(...) {
138  (*return_tuples) = pgr_free(*return_tuples);
139  (*return_count) = 0;
140  err << "Caught unknown exception!";
141  *err_msg = pgr_msg(err.str().c_str());
142  *log_msg = pgr_msg(log.str().c_str());
143  }
144 }
145 
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
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: trsp_driver.cpp:41
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:79
#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
size_t count_tuples(const std::deque< Path > &paths)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:68
Assertions Handling.
Path process(const int64_t start_vertex, const int64_t end_vertex)
process
virtual const char * what() const
Definition: pgr_assert.cpp:53