2
2
3
3
#include < bitset>
4
4
5
+ #include " boost/graph/graph_traits.hpp"
6
+
5
7
#include " utl/helpers/algorithm.h"
6
8
7
9
#include " osr/ways.h"
8
10
9
- #include < boost/graph/graph_traits.hpp>
10
-
11
11
namespace osr {
12
12
13
13
struct hybrid {
@@ -44,31 +44,11 @@ struct node {
44
44
return node{};
45
45
}
46
46
47
- constexpr node () : type_{node_type::kInvalid }, idx_{node_idx_t::invalid ()}, lvl_{level_t::invalid ()} {}
48
-
49
- constexpr node (node_idx_t const n, level_t const lvl, bool const is_parking)
50
- : type_{node_type::kFoot }, idx_{n}, lvl_{lvl}, is_parking_{is_parking} {}
51
-
52
- constexpr node (node_idx_t const n, level_t const lvl, bool const is_parking, direction const dir, way_pos_t const way)
53
- : type_{node_type::kCar }, idx_{n}, lvl_{lvl}, is_parking_{is_parking}, dir_{dir}, node_way_index_{way} {}
54
-
55
- constexpr node (node_type const t, node_idx_t const n, level_t const lvl, bool const is_parking, direction const dir, way_pos_t const way)
56
- : type_{t}, idx_{n}, lvl_{lvl}, is_parking_{is_parking}, dir_{dir}, node_way_index_{way} {}
57
-
58
- node_type type_;
59
- node_idx_t idx_;
60
-
61
- level_t lvl_;
62
- bool is_parking_{false };
63
-
64
- direction dir_{};
65
- way_pos_t node_way_index_{};
66
-
67
47
constexpr node_idx_t get_node () const noexcept {
68
48
return idx_;
69
49
}
70
50
71
- boost::json::object custom_geojson_properties (ways const & w) const {
51
+ boost::json::object geojson_properties (ways const & w) const {
72
52
auto properties = boost::json::object{
73
53
{" node_id" , idx_.v_ },
74
54
{" level" , to_float (lvl_)},
@@ -105,6 +85,15 @@ struct node {
105
85
constexpr bool is_invalid_node () const noexcept {
106
86
return type_ == node_type::kInvalid ;
107
87
}
88
+
89
+ node_type type_{node_type::kInvalid };
90
+ node_idx_t idx_{node_idx_t::invalid ()};
91
+
92
+ level_t lvl_{level_t::invalid ()};
93
+ bool is_parking_;
94
+
95
+ direction dir_{};
96
+ way_pos_t node_way_index_{};
108
97
};
109
98
110
99
struct entry {
@@ -114,7 +103,6 @@ struct node {
114
103
entry () {
115
104
utl::fill (cost_, kInfeasible );
116
105
utl::fill (pred_, node_idx_t::invalid ());
117
- utl::fill (pred_way_, way_pos_t {0U });
118
106
}
119
107
120
108
constexpr std::optional<node> pred (node const n) const noexcept {
@@ -124,24 +112,13 @@ struct node {
124
112
return std::nullopt;
125
113
}
126
114
127
- if (pred_type_[idx]) {
128
- return std::optional {
129
- node{
130
- pred_[idx],
131
- pred_lvl_[idx],
132
- pred_parking_[idx],
133
- }
134
- };
135
- }
136
-
137
- return std::optional {
138
- node{
139
- pred_[idx],
140
- pred_lvl_[idx],
141
- pred_parking_[idx],
142
- to_dir (pred_dir_[idx]),
143
- pred_way_[idx],
144
- }
115
+ return node{
116
+ to_node_type (pred_type_[idx]),
117
+ pred_[idx],
118
+ pred_lvl_[idx],
119
+ pred_parking_[idx],
120
+ to_dir (pred_dir_[idx]),
121
+ pred_way_[idx],
145
122
};
146
123
}
147
124
@@ -152,22 +129,16 @@ struct node {
152
129
constexpr bool update (node const n,
153
130
cost_t const c,
154
131
node const pred) noexcept {
155
- if (pred.is_invalid_node ()) {
156
- cost_[get_index (n)] = c;
157
- return true ;
158
- }
132
+ auto const idx = get_index (n);
159
133
160
- if (auto const idx = get_index (n); c < cost_[idx]) {
134
+ if (c < cost_[idx]) {
161
135
cost_[idx] = c;
162
136
pred_[idx] = pred.idx_ ;
163
137
pred_lvl_[idx] = pred.lvl_ ;
164
138
pred_parking_[idx] = pred.is_parking_ ;
165
139
pred_type_[idx] = to_bool (pred.type_ );
166
-
167
- if (pred.is_car_node ()) {
168
- pred_way_[idx] = pred.node_way_index_ ;
169
- pred_dir_[idx] = to_bool (pred.dir_ );
170
- }
140
+ pred_way_[idx] = pred.node_way_index_ ;
141
+ pred_dir_[idx] = to_bool (pred.dir_ );
171
142
172
143
return true ;
173
144
}
@@ -241,7 +212,7 @@ struct node {
241
212
* mode depending on search direction.
242
213
*/
243
214
template <typename Fn>
244
- static void resolve (ways::routing const & w,
215
+ static void resolve_start_node (ways::routing const & w,
245
216
way_idx_t const way,
246
217
node_idx_t const n,
247
218
level_t const lvl,
@@ -250,22 +221,23 @@ struct node {
250
221
auto const way_properties = w.way_properties_ [way];
251
222
auto const ways = w.node_ways_ [n];
252
223
224
+
253
225
level_t const node_level = lvl == level_t::invalid () ? way_properties.from_level () : lvl;
254
226
bool const is_parking = w.node_properties_ [n].is_parking_ ;
255
227
256
228
if (search_dir == direction::kBackward ) {
257
229
// when seraching backward, we have to start with the foot node
258
230
if (lvl == level_t::invalid () || (way_properties.from_level () == lvl || way_properties.to_level () == lvl || can_use_elevator (w, n, lvl))) {
259
- f (node{n, node_level, is_parking});
231
+ f (node{node_type:: kFoot , n, node_level, is_parking});
260
232
}
261
233
262
234
return ;
263
235
}
264
236
265
237
for (auto i = way_pos_t {0U }; i != ways.size (); ++i) {
266
238
if (ways[i] == way) {
267
- f (node{n, node_level, is_parking, direction::kForward , i});
268
- f (node{n, node_level, is_parking, direction::kBackward , i});
239
+ f (node{node_type:: kCar , n, node_level, is_parking, direction::kForward , i});
240
+ f (node{node_type:: kCar , n, node_level, is_parking, direction::kBackward , i});
269
241
}
270
242
}
271
243
}
@@ -280,27 +252,27 @@ struct node {
280
252
281
253
auto levels = hash_set<level_t >{};
282
254
283
- bool const is_parking = node_properties.is_parking_ ;
255
+ auto const is_parking = node_properties.is_parking_ ;
284
256
285
257
for (auto i = way_pos_t {0U }; i != ways.size (); ++i) {
286
258
auto const p = w.way_properties_ [w.node_ways_ [n][i]];
287
259
288
- level_t const node_level = lvl == level_t::invalid () ? p.from_level () : lvl;
260
+ auto const node_level = lvl == level_t::invalid () ? p.from_level () : lvl;
289
261
290
- f (node{n, node_level, is_parking, direction::kForward , i});
291
- f (node{n, node_level, is_parking, direction::kBackward , i});
262
+ f (node{node_type:: kCar , n, node_level, is_parking, direction::kForward , i});
263
+ f (node{node_type:: kCar , n, node_level, is_parking, direction::kBackward , i});
292
264
293
265
if (lvl == level_t::invalid ()) {
294
266
if (levels.emplace (p.from_level ()).second ) {
295
- f (node{n, p.from_level (), is_parking});
267
+ f (node{node_type:: kFoot , n, p.from_level (), is_parking});
296
268
}
297
269
if (levels.emplace (p.to_level ()).second ) {
298
- f (node{n, p.to_level (), is_parking});
270
+ f (node{node_type:: kFoot , n, p.to_level (), is_parking});
299
271
}
300
272
} else if ((p.from_level () == lvl || p.to_level () == lvl ||
301
273
can_use_elevator (w, n, lvl)) &&
302
274
levels.emplace (lvl).second ) {
303
- f (node{n, lvl, is_parking});
275
+ f (node{node_type:: kFoot , n, lvl, is_parking});
304
276
}
305
277
}
306
278
}
@@ -348,7 +320,7 @@ struct node {
348
320
w, target_node, [&](level_t const target_lvl) {
349
321
auto const dist = w.way_node_dist_ [way][std::min (from, to)];
350
322
auto const cost = foot_way_cost (target_way_prop, dist) + target_node_cost;
351
- fn (node{target_node, target_lvl, target_node_prop.is_parking_ }, cost, dist, way, from, to);
323
+ fn (node{node_type:: kFoot , target_node, target_lvl, target_node_prop.is_parking_ }, cost, dist, way, from, to);
352
324
});
353
325
354
326
return ; // node is an elevator
@@ -362,7 +334,7 @@ struct node {
362
334
363
335
auto const dist = w.way_node_dist_ [way][std::min (from, to)];
364
336
auto const cost = foot_way_cost (target_way_prop, dist) + target_node_cost;
365
- fn (node{target_node, *target_lvl, target_node_prop.is_parking_ }, cost, dist, way, from, to);
337
+ fn (node{node_type:: kFoot , target_node, *target_lvl, target_node_prop.is_parking_ }, cost, dist, way, from, to);
366
338
}
367
339
368
340
template <direction SearchDir, typename Fn>
@@ -384,7 +356,7 @@ struct node {
384
356
385
357
auto const target_node = w.way_nodes_ [way][to];
386
358
auto const target_node_prop = w.node_properties_ [target_node];
387
- cost_t const target_node_cost = car_node_cost (target_node_prop);
359
+ auto const target_node_cost = car_node_cost (target_node_prop);
388
360
389
361
if (target_node_cost == kInfeasible ) {
390
362
return ;
@@ -400,7 +372,7 @@ struct node {
400
372
auto const target_level = way_prop.from_level () == n.lvl_ ? way_prop.to_level () : way_prop.from_level ();
401
373
402
374
auto const target =
403
- node{target_node, target_level, target_node_prop.is_parking_ , way_dir, w.get_way_pos (target_node, way)};
375
+ node{node_type:: kCar , target_node, target_level, target_node_prop.is_parking_ , way_dir, w.get_way_pos (target_node, way)};
404
376
405
377
if (n.is_foot_node ()) {
406
378
if (!n.is_parking_ ) {
@@ -410,7 +382,6 @@ struct node {
410
382
auto const dist = w.way_node_dist_ [way][std::min (from, to)];
411
383
cost_t const cost = car_way_cost (target_way_prop, way_dir, dist) + target_node_cost + kSwitchPenalty ;
412
384
fn (target, cost, dist, way, from, to);
413
- return ;
414
385
}
415
386
416
387
if (w.is_restricted <SearchDir>(n.idx_ , n.node_way_index_ , way_pos)) {
@@ -505,6 +476,7 @@ struct node {
505
476
static constexpr cost_t way_cost (way_properties const & e,
506
477
direction const dir,
507
478
std::uint16_t const dist) {
479
+
508
480
return foot_way_cost (e, dist);
509
481
}
510
482
0 commit comments