diff --git a/.pkg b/.pkg index cf6b946..37c89ac 100644 --- a/.pkg +++ b/.pkg @@ -13,7 +13,7 @@ [geo] url=git@github.com:motis-project/geo.git branch=master - commit=5d99aeb10674a41a82d7c78f850abfd9605bf6e1 + commit=de5a3586871b8b76a487d42fcc673c9487a1e233 [cista] url=git@github.com:felixguendling/cista.git branch=master diff --git a/.pkg.lock b/.pkg.lock index a4928d2..bb2e4da 100644 --- a/.pkg.lock +++ b/.pkg.lock @@ -1,5 +1,5 @@ -8900990051304848502 -cista 5b2ca78d1af99941ea41e195dc3a29b4f05e1b77 +15309325614644894217 +cista 52577def055e4bdf90eaa461872fc1f7b5b1131d zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3 boost 73549ebca677fe6214202a1ab580362b4f80e653 conf f9bf4bd83bf55a2170725707e526cbacc45dcc66 @@ -8,7 +8,7 @@ fmt edb385ac526c24bc917ec4a41bb0edb28f0ca59e doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0 googletest 34a46558609e05865c197f0260ab36daa7cbbb6e utl 538a11dec577de7238c7640491b3d4e091a33e08 -geo 5d99aeb10674a41a82d7c78f850abfd9605bf6e1 +geo de5a3586871b8b76a487d42fcc673c9487a1e233 libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516 mimalloc 2a557cafb2e9e7c872358a83a63c62a7e14330b3 libressl 39c1bf084d5c179d7bbce7ba902fffbebff0ee15 diff --git a/exe/backend/src/main.cc b/exe/backend/src/main.cc index a1da4cd..ce58671 100644 --- a/exe/backend/src/main.cc +++ b/exe/backend/src/main.cc @@ -90,7 +90,7 @@ int main(int argc, char const* argv[]) { pl->build_rtree(w); } - auto const l = lookup{w}; + auto const l = lookup{w, opt.data_dir_, cista::mmap::protection::READ}; auto ioc = boost::asio::io_context{}; auto pool = boost::asio::io_context{}; diff --git a/exe/benchmark.cc b/exe/benchmark.cc index 160181f..661c073 100644 --- a/exe/benchmark.cc +++ b/exe/benchmark.cc @@ -71,9 +71,11 @@ int main(int argc, char const* argv[]) { auto const start = node_idx_t{cista::hash_combine(h, ++n, i.load()) % w.n_nodes()}; d.reset(opt.max_dist_); - d.add_start(car::label{car::node{start, 0, direction::kForward}, 0U}); - d.add_start(car::label{car::node{start, 0, direction::kBackward}, 0U}); - d.run(*w.r_, opt.max_dist_, nullptr, + d.add_start(w, + car::label{car::node{start, 0, direction::kForward}, 0U}); + d.add_start(w, + car::label{car::node{start, 0, direction::kBackward}, 0U}); + d.run(w, *w.r_, opt.max_dist_, nullptr, nullptr); } }); diff --git a/include/osr/routing/dijkstra.h b/include/osr/routing/dijkstra.h index 6d69e33..a8283d2 100644 --- a/include/osr/routing/dijkstra.h +++ b/include/osr/routing/dijkstra.h @@ -9,6 +9,8 @@ namespace osr { struct sharing_data; +constexpr auto const kDebug = false; + template struct dijkstra { using profile_t = Profile; @@ -28,9 +30,14 @@ struct dijkstra { cost_.clear(); } - void add_start(label const l) { + void add_start(ways const& w, label const l) { if (cost_[l.get_node().get_key()].update(l, l.get_node(), l.cost(), node::invalid())) { + if constexpr (kDebug) { + std::cout << "START "; + l.get_node().print(std::cout, w); + std::cout << "\n"; + } pq_.push(l); } } @@ -41,7 +48,8 @@ struct dijkstra { } template - void run(ways::routing const& r, + void run(ways const& w, + ways::routing const& r, cost_t const max, bitvec const* blocked, sharing_data const* sharing) { @@ -51,11 +59,22 @@ struct dijkstra { continue; } + if constexpr (kDebug) { + std::cout << "EXTRACT "; + l.get_node().print(std::cout, w); + std::cout << "\n"; + } + auto const curr = l.get_node(); Profile::template adjacent( r, curr, blocked, sharing, [&](node const neighbor, std::uint32_t const cost, distance_t, way_idx_t const way, std::uint16_t, std::uint16_t) { + if constexpr (kDebug) { + std::cout << " NEIGHBOR "; + neighbor.print(std::cout, w); + } + auto const total = l.cost() + cost; if (total < max && cost_[neighbor.get_key()].update( @@ -63,24 +82,33 @@ struct dijkstra { auto next = label{neighbor, static_cast(total)}; next.track(l, r, way, neighbor.get_node()); pq_.push(std::move(next)); + + if constexpr (kDebug) { + std::cout << " -> PUSH\n"; + } + } else { + if constexpr (kDebug) { + std::cout << " -> DOMINATED\n"; + } } }); } } - void run(ways::routing const& r, + void run(ways const& w, + ways::routing const& r, cost_t const max, bitvec const* blocked, sharing_data const* sharing, direction const dir) { if (blocked == nullptr) { dir == direction::kForward - ? run(r, max, blocked, sharing) - : run(r, max, blocked, sharing); + ? run(w, r, max, blocked, sharing) + : run(w, r, max, blocked, sharing); } else { dir == direction::kForward - ? run(r, max, blocked, sharing) - : run(r, max, blocked, sharing); + ? run(w, r, max, blocked, sharing) + : run(w, r, max, blocked, sharing); } } diff --git a/include/osr/routing/profiles/bike_sharing.h b/include/osr/routing/profiles/bike_sharing.h index d39d68e..0770736 100644 --- a/include/osr/routing/profiles/bike_sharing.h +++ b/include/osr/routing/profiles/bike_sharing.h @@ -71,14 +71,28 @@ struct bike_sharing { } struct key { - friend bool operator==(key, key) = default; + friend bool operator==(key const a, key const b) { + auto const is_zero = [](level_t const l) { + return l == kNoLevel || l == level_t{0.F}; + }; + return a.n_ == b.n_ && + (a.lvl_ == b.lvl_ || (is_zero(a.lvl_) && is_zero(b.lvl_))); + } node_idx_t n_{node_idx_t::invalid()}; level_t lvl_{}; }; + using hash = footp::hash; + struct node { - friend bool operator==(node, node) = default; + friend bool operator==(node const a, node const b) { + auto const is_zero = [](level_t const l) { + return l == kNoLevel || l == level_t{0.F}; + }; + return a.n_ == b.n_ && a.type_ == b.type_ && + (a.lvl_ == b.lvl_ || (is_zero(a.lvl_) && is_zero(b.lvl_))); + } boost::json::object geojson_properties(ways const& w) const { auto properties = @@ -89,8 +103,10 @@ struct bike_sharing { } std::ostream& print(std::ostream& out, ways const& w) const { - return out << "(node=" << w.node_to_osm_[n_] - << ", level=" << lvl_.to_float() + return out << "(node=" + << (n_ >= w.n_nodes() ? osm_node_idx_t{to_idx(n_)} + : w.node_to_osm_[n_]) + << (n_ >= w.n_nodes() ? "*" : "") << ", level=" << lvl_ << ", type=" << node_type_to_str(type_) << ")"; } @@ -197,16 +213,6 @@ struct bike_sharing { std::array pred_type_{}; }; - struct hash { - using is_avalanching = void; - auto operator()(key const k) const noexcept -> std::uint64_t { - using namespace ankerl::unordered_dense::detail; - return wyhash::mix( - wyhash::hash(static_cast(to_idx(k.lvl_))), - wyhash::hash(static_cast(to_idx(k.n_)))); - } - }; - static footp::node to_foot(node const n) { return {.n_ = n.n_, .lvl_ = n.lvl_}; } @@ -244,6 +250,7 @@ struct bike_sharing { footp::resolve_all(w, n, lvl, [&](footp::node const neighbor) { f(to_node(neighbor, node_type::kInitialFoot)); f(to_node(neighbor, node_type::kTrailingFoot)); + f(to_node(neighbor, node_type::kBike)); }); } @@ -257,8 +264,10 @@ struct bike_sharing { auto const& handle_additional_edge = [&](additional_edge const& ae, node_type const nt, cost_t const cost) { - fn(node{.n_ = ae.node_, .type_ = nt, .lvl_ = n.lvl_}, cost, - ae.distance_, way_idx_t::invalid(), 0, 1); + fn(node{.n_ = ae.node_, + .type_ = nt, + .lvl_ = nt == node_type::kBike ? kNoLevel : n.lvl_}, + cost, ae.distance_, way_idx_t::invalid(), 0, 1); }; auto const& continue_on_foot = [&](node_type const nt, @@ -294,7 +303,7 @@ struct bike_sharing { [&](bike::node const neighbor, std::uint32_t const cost, distance_t const dist, way_idx_t const way, std::uint16_t const from, std::uint16_t const to) { - fn(to_node(neighbor, n.lvl_), cost + switch_penalty, dist, way, + fn(to_node(neighbor, kNoLevel), cost + switch_penalty, dist, way, from, to); }); if (include_additional_edges) { diff --git a/include/osr/routing/profiles/foot.h b/include/osr/routing/profiles/foot.h index 03b029c..44cd885 100644 --- a/include/osr/routing/profiles/foot.h +++ b/include/osr/routing/profiles/foot.h @@ -93,7 +93,7 @@ struct foot { struct hash { using is_avalanching = void; - auto operator()(node const n) const noexcept -> std::uint64_t { + auto operator()(auto const n) const noexcept -> std::uint64_t { using namespace ankerl::unordered_dense::detail; return wyhash::mix( wyhash::hash(static_cast( diff --git a/src/route.cc b/src/route.cc index 9ea7769..ce4759b 100644 --- a/src/route.cc +++ b/src/route.cc @@ -301,7 +301,7 @@ std::optional route(ways const& w, if (nc->valid() && nc->cost_ < max) { Profile::resolve_start_node( *w.r_, start.way_, nc->node_, from.lvl_, dir, - [&](auto const node) { d.add_start({node, nc->cost_}); }); + [&](auto const node) { d.add_start(w, {node, nc->cost_}); }); } } @@ -309,7 +309,7 @@ std::optional route(ways const& w, continue; } - d.run(*w.r_, max, blocked, sharing, dir); + d.run(w, *w.r_, max, blocked, sharing, dir); auto const c = best_candidate(w, d, to.lvl_, to_match, max, dir); if (c.has_value()) { @@ -350,12 +350,12 @@ std::vector> route( *w.r_, start.way_, nc->node_, from.lvl_, dir, [&](auto const node) { auto label = typename Profile::label{node, nc->cost_}; label.track(label, *w.r_, start.way_, node.get_node()); - d.add_start(label); + d.add_start(w, label); }); } } - d.run(*w.r_, max, blocked, sharing, dir); + d.run(w, *w.r_, max, blocked, sharing, dir); auto found = 0U; for (auto const [m, t, r] : utl::zip(to_match, to, result)) { diff --git a/test/lvl_wildcard_test.cc b/test/lvl_wildcard_test.cc index db87d63..aee7067 100644 --- a/test/lvl_wildcard_test.cc +++ b/test/lvl_wildcard_test.cc @@ -33,7 +33,7 @@ TEST(routing, no_lvl_wildcard) { extract(false, "test/stuttgart.osm.pbf", kTestFolder); auto w = osr::ways{kTestFolder, cista::mmap::protection::READ}; - auto l = osr::lookup{w}; + auto l = osr::lookup{w, kTestFolder, cista::mmap::protection::READ}; auto const p = route(w, l, search_profile::kFoot, // {{48.7829, 9.18212}, level_t{0.F}}, @@ -87,4 +87,4 @@ TEST(routing, no_lvl_wildcard) { "4.87844364E1],[9.1832201E0,4.87845268E1],[9.183214598396768E0,4." "8784528970208854E1],[9.18337E0,4.87847E1]]}}]}", path); -} \ No newline at end of file +} diff --git a/test/restriction_test.cc b/test/restriction_test.cc index 4d1b892..3ef2fe5 100644 --- a/test/restriction_test.cc +++ b/test/restriction_test.cc @@ -25,7 +25,7 @@ TEST(extract, wa) { osr::extract(false, "test/map.osm", "/tmp/osr_test"); auto w = osr::ways{"/tmp/osr_test", cista::mmap::protection::READ}; - auto l = osr::lookup{w}; + auto l = osr::lookup{w, "/tmp/osr_test", cista::mmap::protection::READ}; auto const n = w.find_node_idx(osm_node_idx_t{528944}); auto const rhoenring = w.find_way(osm_way_idx_t{120682496}); @@ -35,4 +35,4 @@ TEST(extract, wa) { n.value(), w.r_->get_way_pos(n.value(), rhoenring.value()), w.r_->get_way_pos(n.value(), arheilger.value())); EXPECT_TRUE(is_restricted); -} \ No newline at end of file +}