Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work in progress #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion include/osr/lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ struct lookup {
return cista::mmap{(p_ / file).generic_string().c_str(), mode_};
}

match_t get_raw_match(location const& query,
double const max_match_distance) {
auto way_candidates = std::vector<way_candidate>{};
find(geo::box{query.pos_, max_match_distance}, [&](way_idx_t const way) {
auto d = geo::distance_to_polyline<way_candidate>(
query.pos_, ways_.way_polylines_[way]);
if (d.dist_to_way_ < max_match_distance) {
d.way_ = way;
way_candidates.emplace_back(d);
}
});
utl::sort(way_candidates);
return way_candidates;
}

template <typename Profile>
match_t complete_match(match_t match,
bool reverse,
direction const search_dir,
bitvec<node_idx_t>& blocked) {
for (auto& wc : match) {
wc.left_ =
find_next_node<Profile>(wc, wc.query_, direction::kBackward,
wc.query_.lvl_, reverse, search_dir, blocked);
wc.right_ =
find_next_node<Profile>(wc, wc.query_, direction::kForward,
wc.query_.lvl_, reverse, search_dir, blocked);
}
return match;
}

match_t match(location const& query,
bool const reverse,
direction const search_dir,
Expand Down Expand Up @@ -128,7 +159,6 @@ struct lookup {
query.pos_, ways_.way_polylines_[way]);
if (d.dist_to_way_ < max_match_distance) {
auto& wc = way_candidates.emplace_back(std::move(d));
wc.query_ = query;
wc.way_ = way;
wc.left_ =
find_next_node<Profile>(wc, query, direction::kBackward, query.lvl_,
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 @@ -149,7 +149,7 @@ struct bike {
direction,
std::uint16_t const dist) {
if (e.is_bike_accessible()) {
return static_cast<cost_t>(std::round(dist / 2.8F));
return static_cast<cost_t>(std::round(dist / 4.F));
} else {
return kInfeasible;
}
Expand Down
14 changes: 13 additions & 1 deletion include/osr/routing/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ struct path {
template <typename Profile>
dijkstra<Profile>& get_dijkstra();

std::vector<std::optional<path>> route(
struct one_to_many_result {
one_to_many_result(std::chrono::milliseconds&& lookup_time,
std::vector<std::optional<path>>&& paths)
: lookup_time_{lookup_time}, paths_{std::move(paths)} {}

one_to_many_result(std::vector<std::optional<path>>&& paths)
: paths_{std::move(paths)} {}

std::chrono::milliseconds lookup_time_{};
std::vector<std::optional<path>> paths_;
};

one_to_many_result route(
ways const&,
lookup const&,
search_profile,
Expand Down
16 changes: 11 additions & 5 deletions src/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "boost/thread/tss.hpp"

#include "utl/concat.h"
#include "utl/timing.h"
#include "utl/to_vec.h"
#include "utl/verify.h"

Expand Down Expand Up @@ -387,7 +388,7 @@ std::vector<std::optional<path>> route(
return result;
}

std::vector<std::optional<path>> route(
one_to_many_result route(
ways const& w,
lookup const& l,
search_profile const profile,
Expand All @@ -399,8 +400,9 @@ std::vector<std::optional<path>> route(
bitvec<node_idx_t> const* blocked,
sharing_data const* sharing,
std::function<bool(path const&)> const& do_reconstruct) {
auto const r = [&]<typename Profile>(
dijkstra<Profile>& d) -> std::vector<std::optional<path>> {
auto const r =
[&]<typename Profile>(dijkstra<Profile>& d) -> one_to_many_result {
UTL_START_TIMING(lookup);
auto const from_match =
l.match<Profile>(from, false, dir, max_match_distance, blocked);
if (from_match.empty()) {
Expand All @@ -409,8 +411,12 @@ std::vector<std::optional<path>> route(
auto const to_match = utl::to_vec(to, [&](auto&& x) {
return l.match<Profile>(x, true, dir, max_match_distance, blocked);
});
return route(w, d, from, to, from_match, to_match, max, dir, blocked,
sharing, do_reconstruct);
UTL_STOP_TIMING(lookup);
return one_to_many_result{
std::chrono::duration_cast<std::chrono::milliseconds>(lookup_stop -
lookup_start),
route(w, d, from, to, from_match, to_match, max, dir, blocked, sharing,
do_reconstruct)};
};

switch (profile) {
Expand Down
Loading