PGROUTING  2.4
 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  int start_vertex,
38  int 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 
47  std::vector<PDVI> ruleTable;
48 
49  int j;
50  ruleTable.clear();
51  for (size_t i=0; i<restrict_count; i++) {
52  std::vector<int64_t> seq;
53  seq.clear();
54  seq.push_back(restricts[i].target_id);
55  for(j = 0; j<MAX_RULE_LENGTH && restricts[i].via[j]>-1; j++)
56  {
57  seq.push_back(restricts[i].via[j]);
58  }
59  ruleTable.push_back(make_pair(restricts[i].to_cost, seq));
60  }
61 
62  GraphDefinition gdef(edges, static_cast<unsigned int>(edge_count), directed, has_reverse_cost);
63  gdef.set_restrictions(start_vertex, end_vertex, ruleTable);
64  int res = gdef.my_dijkstra(start_vertex, end_vertex, path, path_count, 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  int start_edge,
88  double start_pos,
89  int 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 
98  std::vector<PDVI> ruleTable;
99 
100  int j;
101  ruleTable.clear();
102  for (size_t i=0; i<restrict_count; i++) {
103  std::vector<int64_t> seq;
104  seq.clear();
105  seq.push_back(restricts[i].target_id);
106  for(j = 0; j<MAX_RULE_LENGTH && restricts[i].via[j]>-1; j++)
107  {
108  seq.push_back(restricts[i].via[j]);
109  }
110  ruleTable.push_back(make_pair(restricts[i].to_cost, seq));
111  }
112 
113  GraphDefinition gdef(edges, static_cast<unsigned int>(edge_count), directed, has_reverse_cost);
114 
115  int64_t start_vertex = 0;
116  int64_t end_vertex = 0;
117  gdef.add_virtual_vertices(
118  start_edge, start_pos,
119  end_edge, end_pos,
120  start_vertex, end_vertex);
121 
122  gdef.set_restrictions(start_vertex, end_vertex, ruleTable);
123  int res = gdef.my_dijkstra(start_vertex, end_vertex, path, path_count, 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 }
int path_count
Definition: BDATester.cpp:51
int my_dijkstra(long start_vertex, long end_vertex, unsigned int edge_count, char **err_msg)
int trsp_node_wrapper(edge_t *edges, size_t edge_count, restrict_t *restricts, size_t restrict_count, int start_vertex, int 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 edge_count
Definition: BDATester.cpp:47
edge_astar_t * edges
Definition: BDATester.cpp:46
path_element_t * path
Definition: BDATester.cpp:49
int via[5]
Definition: trsp.h:42
char * err_msg
Definition: BDATester.cpp:50
#define MAX_RULE_LENGTH
Definition: pgr_types.h:172
int trsp_edge_wrapper(edge_t *edges, size_t edge_count, restrict_t *restricts, size_t restrict_count, int start_edge, double start_pos, int 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