Skip to content

Commit db25f05

Browse files
tracking: tracks an attribute for a path
works via labels + entry dijkstra updates entry tracking with the label tracking useful to know if a path contains an elevator somewhere without having to actually reconstruct the whole path
1 parent 6cf0a46 commit db25f05

File tree

11 files changed

+118
-103
lines changed

11 files changed

+118
-103
lines changed

.pkg

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[geo]
1414
url=git@github.com:motis-project/geo.git
1515
branch=master
16-
commit=10fde5b467825c059881c93aeea00412338a9b06
16+
commit=82ff7ceeb25abd8ddba01320be27d3cf1bdee1b0
1717
[cista]
1818
url=git@github.com:felixguendling/cista.git
1919
branch=master

exe/backend/src/http_server.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ struct http_server::impl {
137137
? 0U
138138
: to_idx(w_.way_osm_idx_[s.way_])},
139139
{"cost", s.cost_},
140-
{"distance", s.dist_},
141-
{"from_node", s.from_node_properties_},
142-
{"to_node", s.to_node_properties_}},
140+
{"distance", s.dist_}},
143141
},
144142
{"geometry", to_line_string(s.polyline_)}};
145143
}) |
@@ -155,7 +153,7 @@ struct http_server::impl {
155153
auto const max = point::from_latlng(
156154
{waypoints[3].as_double(), waypoints[2].as_double()});
157155
auto levels = hash_set<level_t>{};
158-
l_.find(min, max, [&](way_idx_t const x) {
156+
l_.find({min, max}, [&](way_idx_t const x) {
159157
auto const p = w_.r_->way_properties_[x];
160158
levels.emplace(p.from_level());
161159
if (p.from_level() != p.to_level()) {
@@ -175,13 +173,13 @@ struct http_server::impl {
175173
auto const query = boost::json::parse(req.body()).as_object();
176174
auto const waypoints = query.at("waypoints").as_array();
177175
auto const profile = get_search_profile_from_request(query);
178-
auto const min = point::from_latlng(
179-
{waypoints[1].as_double(), waypoints[0].as_double()});
180-
auto const max = point::from_latlng(
181-
{waypoints[3].as_double(), waypoints[2].as_double()});
176+
auto const min =
177+
geo::latlng{waypoints[1].as_double(), waypoints[0].as_double()};
178+
auto const max =
179+
geo::latlng{waypoints[3].as_double(), waypoints[2].as_double()};
182180

183181
auto gj = geojson_writer{.w_ = w_};
184-
l_.find(min, max, [&](way_idx_t const w) { gj.write_way(w); });
182+
l_.find({min, max}, [&](way_idx_t const w) { gj.write_way(w); });
185183

186184
switch (profile) {
187185
case search_profile::kFoot:

include/osr/lookup.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "cista/reflection/printable.h"
44

5+
#include "geo/box.h"
6+
57
#include "osr/ways.h"
68

79
#include "utl/cflow.h"
@@ -192,16 +194,14 @@ struct lookup {
192194

193195
template <typename Fn>
194196
void find(geo::latlng const& x, Fn&& fn) const {
195-
find({x.lat() - 0.01, x.lng() - 0.01}, {x.lat() + 0.01, x.lng() + 0.01},
197+
find({{x.lat() - 0.01, x.lng() - 0.01}, {x.lat() + 0.01, x.lng() + 0.01}},
196198
std::forward<Fn>(fn));
197199
}
198200

199201
template <typename Fn>
200-
void find(geo::latlng const& a, geo::latlng const& b, Fn&& fn) const {
201-
auto const min =
202-
std::array{std::min(a.lng_, b.lng_), std::min(a.lat_, b.lat_)};
203-
auto const max =
204-
std::array{std::max(a.lng_, b.lng_), std::max(a.lat_, b.lat_)};
202+
void find(geo::box const& b, Fn&& fn) const {
203+
auto const min = b.min_.lnglat();
204+
auto const max = b.max_.lnglat();
205205
rtree_search(
206206
rtree_, min.data(), max.data(),
207207
[](double const* /* min */, double const* /* max */, void const* item,
@@ -214,10 +214,9 @@ struct lookup {
214214
&fn);
215215
}
216216

217-
hash_set<node_idx_t> find_elevators(geo::latlng const& a,
218-
geo::latlng const& b) const {
217+
hash_set<node_idx_t> find_elevators(geo::box const& b) const {
219218
auto elevators = hash_set<node_idx_t>{};
220-
find(a, b, [&](way_idx_t const way) {
219+
find(b, [&](way_idx_t const way) {
221220
for (auto const n : ways_.r_->way_nodes_[way]) {
222221
if (ways_.r_->node_properties_[n].is_elevator()) {
223222
elevators.emplace(n);

include/osr/routing/dijkstra.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct dijkstra {
5757
cost_[neighbor.get_key()].update(
5858
l, neighbor, static_cast<cost_t>(total), curr)) {
5959
auto next = label{neighbor, static_cast<cost_t>(total)};
60-
next.track(r, way, neighbor.get_node());
60+
next.track(l, r, way, neighbor.get_node());
6161
pq_.push(std::move(next));
6262
}
6363
});

include/osr/routing/profiles/bike.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct bike {
3939
constexpr node get_node() const noexcept { return {n_}; }
4040
constexpr cost_t cost() const noexcept { return cost_; }
4141

42-
void track(ways::routing const&, way_idx_t, node_idx_t) {}
42+
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}
4343

4444
node_idx_t n_;
4545
level_t lvl_;

include/osr/routing/profiles/car.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ struct car {
3333

3434
constexpr node_idx_t get_key() const noexcept { return n_; }
3535

36-
void track(ways::routing const&, way_idx_t, node_idx_t) {}
37-
3836
std::ostream& print(std::ostream& out, ways const& w) const {
3937
return out << "(node=" << w.node_to_osm_[n_] << ", dir=" << to_str(dir_)
4038
<< ", way=" << w.way_osm_idx_[w.r_->node_ways_[n_][way_]]
@@ -53,7 +51,7 @@ struct car {
5351
constexpr node get_node() const noexcept { return {n_, way_, dir_}; }
5452
constexpr cost_t cost() const noexcept { return cost_; }
5553

56-
void track(ways::routing const&, way_idx_t, node_idx_t) {}
54+
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}
5755

5856
node_idx_t n_;
5957
way_pos_t way_;

include/osr/routing/profiles/car_parking.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct car_parking {
9393

9494
constexpr cost_t cost() const noexcept { return cost_; }
9595

96-
void track(ways::routing const&, way_idx_t, node_idx_t) {}
96+
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}
9797

9898
node_idx_t n_;
9999
cost_t cost_;

include/osr/routing/profiles/foot.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ struct foot {
4141
constexpr node get_node() const noexcept { return {n_, lvl_}; }
4242
constexpr cost_t cost() const noexcept { return cost_; }
4343

44-
void track(ways::routing const& r, way_idx_t const w, node_idx_t const n) {
45-
tracking_.track(r, w, n);
44+
void track(label const& l,
45+
ways::routing const& r,
46+
way_idx_t const w,
47+
node_idx_t const n) {
48+
tracking_.track(l.tracking_, r, w, n);
4649
}
4750

4851
node_idx_t n_;

include/osr/routing/route.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ struct path {
3131
std::vector<geo::latlng> polyline_;
3232
level_t from_level_;
3333
level_t to_level_;
34+
node_idx_t from_, to_;
3435
way_idx_t way_;
3536
cost_t cost_{kInfeasible};
3637
distance_t dist_{0};
37-
boost::json::object from_node_properties_{};
38-
boost::json::object to_node_properties_{};
3938
};
4039

4140
cost_t cost_{kInfeasible};
@@ -56,7 +55,10 @@ std::vector<std::optional<path>> route(
5655
cost_t max,
5756
direction,
5857
double max_match_distance,
59-
bitvec<node_idx_t> const* blocked = nullptr);
58+
bitvec<node_idx_t> const* blocked = nullptr,
59+
std::function<bool(path const&)> const& = [](path const&) {
60+
return false;
61+
});
6062

6163
std::optional<path> route(ways const&,
6264
lookup const&,

include/osr/routing/tracking.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ namespace osr {
77

88
struct elevator_tracking {
99
void write(path& p) const { p.uses_elevator_ = uses_elevator_; }
10-
void track(ways::routing const& r, way_idx_t, node_idx_t const n) {
11-
uses_elevator_ |= r.node_properties_[n].is_elevator();
10+
void track(elevator_tracking const& l,
11+
ways::routing const& r,
12+
way_idx_t,
13+
node_idx_t const n) {
14+
uses_elevator_ = l.uses_elevator_ || r.node_properties_[n].is_elevator();
1215
}
1316

1417
bool uses_elevator_{false};
1518
};
1619

1720
struct noop_tracking {
1821
void write(path&) const {}
19-
void track(ways::routing const&, way_idx_t, node_idx_t) {}
22+
void track(noop_tracking const&,
23+
ways::routing const&,
24+
way_idx_t,
25+
node_idx_t) {}
2026
};
2127

2228
} // namespace osr

0 commit comments

Comments
 (0)