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 20, 2024
1 parent 6cf0a46 commit 9d3c63f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
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
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

0 comments on commit 9d3c63f

Please sign in to comment.