Skip to content

Commit

Permalink
tracking: tracks an attribute for a path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
felixguendling committed Jul 21, 2024
1 parent 6cf0a46 commit db25f05
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[geo]
[email protected]:motis-project/geo.git
branch=master
commit=10fde5b467825c059881c93aeea00412338a9b06
commit=82ff7ceeb25abd8ddba01320be27d3cf1bdee1b0
[cista]
[email protected]:felixguendling/cista.git
branch=master
Expand Down
16 changes: 7 additions & 9 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ struct http_server::impl {
? 0U
: to_idx(w_.way_osm_idx_[s.way_])},
{"cost", s.cost_},
{"distance", s.dist_},
{"from_node", s.from_node_properties_},
{"to_node", s.to_node_properties_}},
{"distance", s.dist_}},
},
{"geometry", to_line_string(s.polyline_)}};
}) |
Expand All @@ -155,7 +153,7 @@ struct http_server::impl {
auto const max = point::from_latlng(
{waypoints[3].as_double(), waypoints[2].as_double()});
auto levels = hash_set<level_t>{};
l_.find(min, max, [&](way_idx_t const x) {
l_.find({min, max}, [&](way_idx_t const x) {
auto const p = w_.r_->way_properties_[x];
levels.emplace(p.from_level());
if (p.from_level() != p.to_level()) {
Expand All @@ -175,13 +173,13 @@ struct http_server::impl {
auto const query = boost::json::parse(req.body()).as_object();
auto const waypoints = query.at("waypoints").as_array();
auto const profile = get_search_profile_from_request(query);
auto const min = point::from_latlng(
{waypoints[1].as_double(), waypoints[0].as_double()});
auto const max = point::from_latlng(
{waypoints[3].as_double(), waypoints[2].as_double()});
auto const min =
geo::latlng{waypoints[1].as_double(), waypoints[0].as_double()};
auto const max =
geo::latlng{waypoints[3].as_double(), waypoints[2].as_double()};

auto gj = geojson_writer{.w_ = w_};
l_.find(min, max, [&](way_idx_t const w) { gj.write_way(w); });
l_.find({min, max}, [&](way_idx_t const w) { gj.write_way(w); });

switch (profile) {
case search_profile::kFoot:
Expand Down
17 changes: 8 additions & 9 deletions include/osr/lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "cista/reflection/printable.h"

#include "geo/box.h"

#include "osr/ways.h"

#include "utl/cflow.h"
Expand Down Expand Up @@ -192,16 +194,14 @@ struct lookup {

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

template <typename Fn>
void find(geo::latlng const& a, geo::latlng const& b, Fn&& fn) const {
auto const min =
std::array{std::min(a.lng_, b.lng_), std::min(a.lat_, b.lat_)};
auto const max =
std::array{std::max(a.lng_, b.lng_), std::max(a.lat_, b.lat_)};
void find(geo::box const& b, Fn&& fn) const {
auto const min = b.min_.lnglat();
auto const max = b.max_.lnglat();
rtree_search(
rtree_, min.data(), max.data(),
[](double const* /* min */, double const* /* max */, void const* item,
Expand All @@ -214,10 +214,9 @@ struct lookup {
&fn);
}

hash_set<node_idx_t> find_elevators(geo::latlng const& a,
geo::latlng const& b) const {
hash_set<node_idx_t> find_elevators(geo::box const& b) const {
auto elevators = hash_set<node_idx_t>{};
find(a, b, [&](way_idx_t const way) {
find(b, [&](way_idx_t const way) {
for (auto const n : ways_.r_->way_nodes_[way]) {
if (ways_.r_->node_properties_[n].is_elevator()) {
elevators.emplace(n);
Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/dijkstra.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct dijkstra {
cost_[neighbor.get_key()].update(
l, neighbor, static_cast<cost_t>(total), curr)) {
auto next = label{neighbor, static_cast<cost_t>(total)};
next.track(r, way, neighbor.get_node());
next.track(l, r, way, neighbor.get_node());
pq_.push(std::move(next));
}
});
Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/profiles/bike.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct bike {
constexpr node get_node() const noexcept { return {n_}; }
constexpr cost_t cost() const noexcept { return cost_; }

void track(ways::routing const&, way_idx_t, node_idx_t) {}
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}

node_idx_t n_;
level_t lvl_;
Expand Down
4 changes: 1 addition & 3 deletions include/osr/routing/profiles/car.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ struct car {

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

void track(ways::routing const&, way_idx_t, node_idx_t) {}

std::ostream& print(std::ostream& out, ways const& w) const {
return out << "(node=" << w.node_to_osm_[n_] << ", dir=" << to_str(dir_)
<< ", way=" << w.way_osm_idx_[w.r_->node_ways_[n_][way_]]
Expand All @@ -53,7 +51,7 @@ struct car {
constexpr node get_node() const noexcept { return {n_, way_, dir_}; }
constexpr cost_t cost() const noexcept { return cost_; }

void track(ways::routing const&, way_idx_t, node_idx_t) {}
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}

node_idx_t n_;
way_pos_t way_;
Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/profiles/car_parking.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct car_parking {

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

void track(ways::routing const&, way_idx_t, node_idx_t) {}
void track(label const&, ways::routing const&, way_idx_t, node_idx_t) {}

node_idx_t n_;
cost_t cost_;
Expand Down
7 changes: 5 additions & 2 deletions include/osr/routing/profiles/foot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ struct foot {
constexpr node get_node() const noexcept { return {n_, lvl_}; }
constexpr cost_t cost() const noexcept { return cost_; }

void track(ways::routing const& r, way_idx_t const w, node_idx_t const n) {
tracking_.track(r, w, n);
void track(label const& l,
ways::routing const& r,
way_idx_t const w,
node_idx_t const n) {
tracking_.track(l.tracking_, r, w, n);
}

node_idx_t n_;
Expand Down
8 changes: 5 additions & 3 deletions include/osr/routing/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ struct path {
std::vector<geo::latlng> polyline_;
level_t from_level_;
level_t to_level_;
node_idx_t from_, to_;
way_idx_t way_;
cost_t cost_{kInfeasible};
distance_t dist_{0};
boost::json::object from_node_properties_{};
boost::json::object to_node_properties_{};
};

cost_t cost_{kInfeasible};
Expand All @@ -56,7 +55,10 @@ std::vector<std::optional<path>> route(
cost_t max,
direction,
double max_match_distance,
bitvec<node_idx_t> const* blocked = nullptr);
bitvec<node_idx_t> const* blocked = nullptr,
std::function<bool(path const&)> const& = [](path const&) {
return false;
});

std::optional<path> route(ways const&,
lookup const&,
Expand Down
12 changes: 9 additions & 3 deletions include/osr/routing/tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ namespace osr {

struct elevator_tracking {
void write(path& p) const { p.uses_elevator_ = uses_elevator_; }
void track(ways::routing const& r, way_idx_t, node_idx_t const n) {
uses_elevator_ |= r.node_properties_[n].is_elevator();
void track(elevator_tracking const& l,
ways::routing const& r,
way_idx_t,
node_idx_t const n) {
uses_elevator_ = l.uses_elevator_ || r.node_properties_[n].is_elevator();
}

bool uses_elevator_{false};
};

struct noop_tracking {
void write(path&) const {}
void track(ways::routing const&, way_idx_t, node_idx_t) {}
void track(noop_tracking const&,
ways::routing const&,
way_idx_t,
node_idx_t) {}
};

} // namespace osr
Loading

0 comments on commit db25f05

Please sign in to comment.