-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathutilities.cpp
More file actions
261 lines (237 loc) · 7.39 KB
/
Copy pathutilities.cpp
File metadata and controls
261 lines (237 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*PGR-GNU*****************************************************************
File: utilities.cpp
Copyright (c) 2026-2026 pgRouting developers
Mail: project@pgrouting.org
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
#include "cpp_common/utilities.hpp"
#include <set>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include "c_common/enums.h"
#include "c_types/mst_rt.h"
namespace pgrouting {
std::string
get_name(Which which) {
switch (which) {
case SLOAN:
return "pgr_sloanOrdering";
break;
case CUTCHILL:
return "pgr_cuthillMckeeOrdering";
break;
case KING:
return "pgr_kingOrdering";
break;
case TOPOSORT:
return "pgr_topologicalSort";
break;
case FLOYD:
return "pgr_floydWarshall";
break;
case JOHNSON:
return "pgr_johnson";
break;
case BANDWIDTH:
return "pgr_bandwidth";
break;
case KRUSKAL:
return "pgr_kruskal";
break;
case KRUSKALDD:
return "pgr_kruskalDD";
break;
case KRUSKALDFS:
return "pgr_kruskalDFS";
break;
case KRUSKALBFS:
return "pgr_kruskalBFS";
break;
case PRIM:
return "pgr_prim";
break;
case PRIMDD:
return "pgr_primDD";
break;
case PRIMDFS:
return "pgr_primDFS";
break;
case PRIMBFS:
return "pgr_primBFS";
break;
case DFS:
return "pgr_depthFirstSearch";
break;
case BFS:
return "pgr_breadthFirstSearch";
break;
case DIJKSTRADD:
return "pgr_drivingDistance";
break;
case MAXFLOW:
return "pgr_maxFlow";
break;
case PUSHRELABEL:
return "pgr_pushRelabel";
break;
case BOYKOV:
return "pgr_boykovKolmogorov";
break;
case EDMONDSKARP:
return "pgr_edmondsKarp";
break;
case ARTICULATIONPOINTS:
return "pgr_articulationPoints";
break;
case BRIDGES:
return "pgr_bridges";
break;
case MAKECONNECTED:
return "pgr_makeConnected";
break;
case BICONNECTEDCOMPONENTS:
return "pgr_biconnectedComponents";
break;
case CONNECTEDCOMPONENTS:
return "pgr_connectedComponents";
break;
case STRONGCOMPONENTS:
return "pgr_strongComponents";
break;
default:
return "unknown";
break;
}
return "unknown";
}
std::string
get_name(Which which, bool is_only_cost, bool is_near, bool is_matrix) {
std::string base = "";
std::string suffix = "";
switch (which) {
case DIJKSTRA :
base = "pgr_dijkstra";
suffix = std::string(is_near? "Near" : "")
+ (is_only_cost? "Cost" : "")
+ (is_only_cost && is_matrix? "Matrix" : "");
break;
case BDDIJKSTRA :
base = "pgr_bdDijkstra";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;
case EDWARDMOORE:
base = "pgr_edwardMoore";
break;
case DAGSP :
base = "pgr_dagShortestPath";
break;
case BELLMANFORD :
base = "pgr_bellmanFord";
break;
case EDGEDISJOINT:
base = "pgr_edgeDisjointPaths";
break;
case OLD_WITHPOINTS:
case WITHPOINTS:
base = "pgr_withPoints";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;
default : base = "unknown";
}
return base + suffix;
}
std::string
get_name(Which which, bool is_only_cost, bool is_matrix) {
std::string base = "";
std::string suffix = "";
switch (which) {
case ASTAR :
base = "pgr_aStar";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;
case BDASTAR :
base = "pgr_bdAstar";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;
default : base = "unknown";
}
return base + suffix;
}
char
estimate_drivingSide(char driving_side, Which which) {
char d_side = static_cast<char>(tolower(driving_side));
if (!((d_side == 'r') || (d_side == 'l') || (d_side == 'b'))) {
d_side = ' ';
}
switch (which) {
case ASTAR :
case BDASTAR :
case DAGSP :
case EDWARDMOORE:
case BELLMANFORD :
case BDDIJKSTRA:
case DIJKSTRA:
return ' ';
break;
case WITHPOINTS:
if (d_side == ' ') {
throw std::make_pair(std::string("Invalid value of 'driving side'"),
std::string("Valid value are 'r', 'l', 'b'"));
}
break;
default:
/* For the moment its old signature of pgr_withPoints */
if (!((d_side == 'r') || (d_side == 'l'))) d_side = 'b';
}
return d_side;
}
void
get_new_queries(
const std::string &edges_sql,
const std::string &points_sql,
std::string &edges_of_points_query,
std::string &edges_no_points_query) {
if (points_sql.empty()) {
edges_no_points_query = edges_sql;
return;
}
edges_of_points_query = std::string("WITH ")
+ " edges AS (" + edges_sql + "), "
+ " points AS (" + points_sql + ")"
+ " SELECT DISTINCT edges.* FROM edges JOIN points ON (id = edge_id)";
edges_no_points_query = std::string("WITH ")
+ " edges AS (" + edges_sql + "), "
+ " points AS (" + points_sql + ")"
+ " SELECT edges.*"
+ " FROM edges"
+ " WHERE NOT EXISTS (SELECT edge_id FROM points WHERE id = edge_id)";
}
std::vector<MST_rt>
only_root_result(const std::set<int64_t> &vids) {
std::vector<MST_rt> results;
if (vids.empty()) return results;
for (auto const root : vids) {
if (root != 0) results.push_back({root, 0, root, root, -1, 0.0, 0.0});
}
return results;
}
std::vector<Flow_t>
only_maxFlow_result(int64_t maxFlow) {
std::vector<Flow_t> results;
results.push_back({-1, -1, -1, maxFlow, -1, 0, 0});
return results;
}
} // namespace pgrouting