PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trsp_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
4 Mail: project@pgrouting.org
5 
6 ------
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 
22 ********************************************************************PGR-GNU*/
23 #if defined(__MINGW32__) || defined(_MSC_VER)
24 #include <winsock2.h>
25 #include <windows.h>
26 #endif
27 
28 #include <string.h>
29 #include <sstream>
30 #include "GraphDefinition.h"
31 #include "trsp_driver.h"
32 
33 
35  edge_t *edges, size_t edge_count,
36  restrict_t *restricts, size_t restrict_count,
37  int64_t start_vertex,
38  int64_t end_vertex,
39  bool directed,
40  bool has_reverse_cost,
41  path_element_t **path, size_t *path_count,
42  char **err_msg) {
43 
44  std::ostringstream log;
45  try {
46  std::vector<PDVI> ruleTable;
47 
48  int j;
49  ruleTable.clear();
50  for (size_t i = 0; i < restrict_count; i++) {
51  std::vector<int64_t> seq;
52  seq.clear();
53  seq.push_back(restricts[i].target_id);
54  for (j = 0; j < MAX_RULE_LENGTH && restricts[i].via[j] > -1; j++) {
55  seq.push_back(restricts[i].via[j]);
56  }
57  ruleTable.push_back(make_pair(restricts[i].to_cost, seq));
58  }
59 
60  GraphDefinition gdef(edges, static_cast<unsigned int>(edge_count),
61  directed, has_reverse_cost);
62  gdef.set_restrictions(start_vertex, end_vertex, ruleTable);
63  int res = gdef.my_dijkstra(start_vertex, end_vertex, path, path_count,
64  log);
65 
66 
67  if (res < 0)
68  return res;
69  else
70  return EXIT_SUCCESS;
71  }
72  catch(std::exception& e) {
73  log << e.what();
74  *err_msg = strdup(log.str().c_str());
75  return -1;
76  }
77  catch(...) {
78  log << "Caught unknown exception!";
79  *err_msg = strdup(log.str().c_str());
80  return -1;
81  }
82 }
83 
85  edge_t *edges, size_t edge_count,
86  restrict_t *restricts, size_t restrict_count,
87  int64_t start_edge,
88  double start_pos,
89  int64_t end_edge,
90  double end_pos,
91  bool directed,
92  bool has_reverse_cost,
93  path_element_t **path, size_t *path_count,
94  char **err_msg) {
95  std::ostringstream log;
96  try {
97  std::vector<PDVI> ruleTable;
98 
99  int j;
100  ruleTable.clear();
101  for (size_t i = 0; i < restrict_count; i++) {
102  std::vector<int64_t> seq;
103  seq.clear();
104  seq.push_back(restricts[i].target_id);
105  for (j = 0; j < MAX_RULE_LENGTH && restricts[i].via[j] >- 1; j++) {
106  seq.push_back(restricts[i].via[j]);
107  }
108  ruleTable.push_back(make_pair(restricts[i].to_cost, seq));
109  }
110 
111  GraphDefinition gdef(edges, static_cast<unsigned int>(edge_count),
112  directed, has_reverse_cost);
113 
114  int64_t start_vertex = 0;
115  int64_t end_vertex = 0;
116  gdef.add_virtual_vertices(
117  start_edge, start_pos,
118  end_edge, end_pos,
119  start_vertex, end_vertex);
120 
121  gdef.set_restrictions(start_vertex, end_vertex, ruleTable);
122  int res = gdef.my_dijkstra(start_vertex, end_vertex, path, path_count,
123  log);
124 
125 
126  if (res < 0)
127  return res;
128  else
129  return EXIT_SUCCESS;
130  }
131  catch(std::exception& e) {
132  log << e.what();
133  *err_msg = strdup(log.str().c_str());
134  return -1;
135  }
136  catch(...) {
137  log << "Caught unknown exception!";
138  *err_msg = strdup(log.str().c_str());
139  return -1;
140  }
141 }
static edge_t edges[22573]
int trsp_node_wrapper(edge_t *edges, size_t edge_count, restrict_t *restricts, size_t restrict_count, int64_t start_vertex, int64_t end_vertex, bool directed, bool has_reverse_cost, path_element_t **path, size_t *path_count, char **err_msg)
Definition: trsp_driver.cpp:34
int trsp_edge_wrapper(edge_t *edges, size_t edge_count, restrict_t *restricts, size_t restrict_count, int64_t start_edge, double start_pos, int64_t end_edge, double end_pos, bool directed, bool has_reverse_cost, path_element_t **path, size_t *path_count, char **err_msg)
Definition: trsp_driver.cpp:84
Definition: trsp.h:31
int my_dijkstra(long start_vertex, long end_vertex, size_t edge_count, char **err_msg)
#define MAX_RULE_LENGTH
Definition: trsp.h:25
int via[5]
Definition: trsp.h:42