Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Jun 11, 2024
1 parent 178d931 commit d61c4d4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
22 changes: 14 additions & 8 deletions include/osr/lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,21 @@ struct lookup {
template <typename Profile>
match_t match(location const& query,
bool const reverse,
direction const search_dir) const {
direction const search_dir,
double const max_match_distance,
bitvec<node_idx_t> const* blocked) const {
auto way_candidates = std::vector<way_candidate>{};
find(query.pos_, [&](way_idx_t const way) {
auto d = distance_to_way(query.pos_, ways_.way_polylines_[way]);
if (d.dist_to_way_ < Profile::kMaxMatchDistance) {
if (d.dist_to_way_ < max_match_distance) {
auto& wc = way_candidates.emplace_back(std::move(d));
wc.way_ = way;
wc.left_ = find_next_node<Profile>(wc, query, direction::kBackward,
query.lvl_, reverse, search_dir);
wc.right_ = find_next_node<Profile>(wc, query, direction::kForward,
query.lvl_, reverse, search_dir);
wc.left_ =
find_next_node<Profile>(wc, query, direction::kBackward, query.lvl_,
reverse, search_dir, blocked);
wc.right_ =
find_next_node<Profile>(wc, query, direction::kForward, query.lvl_,
reverse, search_dir, blocked);
}
});
utl::sort(way_candidates);
Expand All @@ -118,7 +122,8 @@ struct lookup {
direction const dir,
level_t const lvl,
bool const reverse,
direction const search_dir) const {
direction const search_dir,
bitvec<node_idx_t> const* blocked) const {
auto const way_prop = ways_.r_->way_properties_[wc.way_];
auto const edge_dir = reverse ? opposite(dir) : dir;
auto const way_cost =
Expand Down Expand Up @@ -151,7 +156,8 @@ struct lookup {
c.path_.push_back(pos);

auto const way_node = ways_.find_node_idx(osm_node_idx);
if (way_node.has_value()) {
if (way_node.has_value() &&
(blocked == nullptr || !blocked->test(*way_node))) {
c.node_ = *way_node;
return cflow::kBreak;
}
Expand Down
2 changes: 2 additions & 0 deletions include/osr/routing/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ std::vector<std::optional<path>> route(
std::vector<location> const& to,
cost_t max,
direction,
double max_match_distance,
bitvec<node_idx_t> const* blocked = nullptr);

std::optional<path> route(ways const&,
Expand All @@ -65,6 +66,7 @@ std::optional<path> route(ways const&,
location const& to,
cost_t max,
direction,
double max_match_distance,
bitvec<node_idx_t> const* blocked = nullptr);

} // namespace osr
57 changes: 34 additions & 23 deletions src/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,12 @@ std::optional<path> route(ways const& w,
location const& to,
cost_t const max,
direction const dir,
bitvec<node_idx_t> const* blocked = nullptr) {
auto const from_match = l.match<Profile>(from, false, dir);
auto const to_match = l.match<Profile>(to, true, dir);
double const max_match_distance,
bitvec<node_idx_t> const* blocked) {
auto const from_match =
l.match<Profile>(from, false, dir, max_match_distance, blocked);
auto const to_match =
l.match<Profile>(to, true, dir, max_match_distance, blocked);

if (from_match.empty() || to_match.empty()) {
return std::nullopt;
Expand Down Expand Up @@ -263,18 +266,20 @@ std::optional<path> route(ways const& w,
}

template <typename Profile>
std::vector<std::optional<path>> route(
ways const& w,
lookup const& l,
dijkstra<Profile>& d,
location const& from,
std::vector<location> const& to,
cost_t const max,
direction const dir,
bitvec<node_idx_t> const* blocked = nullptr) {
auto const from_match = l.match<Profile>(from, false, dir);
auto const to_match =
utl::to_vec(to, [&](auto&& x) { return l.match<Profile>(x, true, dir); });
std::vector<std::optional<path>> route(ways const& w,
lookup const& l,
dijkstra<Profile>& d,
location const& from,
std::vector<location> const& to,
cost_t const max,
direction const dir,
double const max_match_distance,
bitvec<node_idx_t> const* blocked) {
auto const from_match =
l.match<Profile>(from, false, dir, max_match_distance, blocked);
auto const to_match = utl::to_vec(to, [&](auto&& x) {
return l.match<Profile>(x, true, dir, max_match_distance, blocked);
});

auto result = std::vector<std::optional<path>>{};
result.resize(to.size());
Expand Down Expand Up @@ -332,18 +337,21 @@ std::vector<std::optional<path>> route(ways const& w,
std::vector<location> const& to,
cost_t const max,
direction const dir,
double const max_match_distance,
bitvec<node_idx_t> const* blocked) {
switch (profile) {
case search_profile::kFoot:
return route(w, l, get_dijkstra<foot<false>>(), from, to, max, dir,
blocked);
max_match_distance, blocked);
case search_profile::kWheelchair:
return route(w, l, get_dijkstra<foot<true>>(), from, to, max, dir,
blocked);
max_match_distance, blocked);
case search_profile::kBike:
return route(w, l, get_dijkstra<bike>(), from, to, max, dir, blocked);
return route(w, l, get_dijkstra<bike>(), from, to, max, dir,
max_match_distance, blocked);
case search_profile::kCar:
return route(w, l, get_dijkstra<car>(), from, to, max, dir, blocked);
return route(w, l, get_dijkstra<car>(), from, to, max, dir,
max_match_distance, blocked);
}
throw utl::fail("not implemented");
}
Expand All @@ -355,18 +363,21 @@ std::optional<path> route(ways const& w,
location const& to,
cost_t const max,
direction const dir,
double const max_match_distance,
bitvec<node_idx_t> const* blocked) {
switch (profile) {
case search_profile::kFoot:
return route(w, l, get_dijkstra<foot<false>>(), from, to, max, dir,
blocked);
max_match_distance, blocked);
case search_profile::kWheelchair:
return route(w, l, get_dijkstra<foot<true>>(), from, to, max, dir,
blocked);
max_match_distance, blocked);
case search_profile::kBike:
return route(w, l, get_dijkstra<bike>(), from, to, max, dir, blocked);
return route(w, l, get_dijkstra<bike>(), from, to, max, dir,
max_match_distance, blocked);
case search_profile::kCar:
return route(w, l, get_dijkstra<car>(), from, to, max, dir, blocked);
return route(w, l, get_dijkstra<car>(), from, to, max, dir,
max_match_distance, blocked);
}
throw utl::fail("not implemented");
}
Expand Down

0 comments on commit d61c4d4

Please sign in to comment.