diff --git a/.pkg.lock b/.pkg.lock index a12b9224f..08fa8f63b 100644 --- a/.pkg.lock +++ b/.pkg.lock @@ -1,28 +1,30 @@ -6383257829560100747 -cista 1fb6f1d9bb8ac9fdb4ca648df69695dd819dc07e +9718959010576347214 +cista abbbf9cfc1484b3a2737eff7a8f2f96d8dab85e4 PEGTL 0d37dcf8f02c12a84fdf521973801a5baab78e8f res b759b93316afeb529b6cb5b2548b24c41e382fb0 date ce88cc33b5551f66655614eeebb7c5b7189025fb googletest 9758d168fd1ccff2d76f3bd6ef802943d0f8f7e5 docs 75dc89a53e9c2d78574fc0ffda698e69f1682ed2 -fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2 -utl 9081181d194c45fb0c6840cefa7a3be7017d9dbc +fmt 34a5bee1df1f0d144de0e127807d161d08670472 +utl 3d6d0c626d124b8a1625be1c6cb6d5c76c140195 oh d9eb908452e808179afeb7954e8beaa5b3626c36 -LuaJIT f4bc3f109a4cc5bc262b2a2c683dae5a75f61377 +LuaJIT dfa894a9c571bedc26f3a45573917a8af07603e4 json ccc94522e752a13a0273dfb837ab36f7dbcda5ab sqlite3 04e60de4ab15c5072b8c7ee2ac7335eb06f2588b PROJ 27ed257526ddf6e2fd7a1a3c92a1d3de913ce34b zlib-ng d68e1d908e789c31c1f2fafe4bd8e09cb91e21c5 -boost f0eca85b563887be8f26c4856c53d4e5080e6976 +boost 77467bf580d98ea06716e2931cbe3b1f28e0cd37 doctest 832431f2d9dc77e51cc8b364337c186660bf267d -geo d862550fd867cd5435225b5f0998981ec4fc2ae3 +rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057 +tg 20c0f298b8ce58de29a790290f44dca7c4ecc364 +geo 1450091a6ee2d541e91d26bf06157342ec0599f6 miniz e857234a23de8e5a2d05d266e518220a495db0ce -libressl 24acd9e710fbe842e863572da9d738715fbc74b8 -curl 39c8a51e8ee0ab7ea712886df79c068405a2e008 +libressl 660f532fa29e1e934e530f22faa79cf7ea345a40 +curl 0743359585cf0d2bd15b9792c0460470a231d8d0 opentelemetry-proto 1624689398a3226c45994d70cb544a1e781dc032 abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e protobuf df2dd518c68b882c9dce5346393f8c388108e733 -opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414 +opentelemetry-cpp 57a4c01aff876e08d9d37a3dec2c9899f0606909 pugixml bb45e30c5bf21b3599eb5b4b7fa20547043c3e24 sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75 unordered_dense 2c7230ae7f9c30849a5b089fb4a5d11896b45dcf diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index 834fe0355..ed169ae5b 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -68,7 +68,8 @@ enum class search_mode { kOneToOne, kOneToAll }; template + search_mode SearchMode, + bool LbGreedy> struct raptor { using algo_state_t = raptor_state; using algo_stats_t = raptor_stats; @@ -86,6 +87,8 @@ struct raptor { a.fill(kInvalid); return a; }(); + static constexpr auto LbGreedyAcceptableLoss = 1.42; + static constexpr auto LbGreedyThreshold = std::uint16_t{60}; static bool is_better(auto a, auto b) { return kFwd ? a < b : a > b; } static bool is_better_or_eq(auto a, auto b) { return kFwd ? a <= b : a >= b; } @@ -166,6 +169,11 @@ struct raptor { if constexpr (Rt) { utl::fill(state_.rt_transport_mark_.blocks_, 0U); } + if constexpr (LbGreedy) { + utl::fill(state_.route_lb_, kUnreachable); + utl::fill(state_.rt_transport_lb_, kUnreachable); + start_lb_ = kUnreachable; + } } void add_start(location_idx_t const l, unixtime_t const t) { @@ -181,6 +189,11 @@ struct raptor { round_times_[0U][to_idx(l)][v] = get_best(unix_to_delta(base(), t), round_times_[0U][to_idx(l)][v]); state_.station_mark_.set(to_idx(l), true); + if constexpr (LbGreedy) { + start_lb_ = std::min( + start_lb_, + static_cast(lb_[to_idx(l)] * LbGreedyAcceptableLoss)); + } } void execute(unixtime_t const start_time, @@ -212,12 +225,22 @@ struct raptor { for (auto const& r : tt_.location_routes_[location_idx_t{i}]) { any_marked = true; state_.route_mark_.set(to_idx(r), true); + if constexpr (LbGreedy) { + state_.route_lb_[r] = std::min( + start_lb_, + static_cast(lb_[i] * LbGreedyAcceptableLoss)); + } } if constexpr (Rt) { for (auto const& rt_t : rtt_->location_rt_transports_[location_idx_t{i}]) { any_marked = true; state_.rt_transport_mark_.set(to_idx(rt_t), true); + if constexpr (LbGreedy) { + state_.rt_transport_lb_[rt_t] = std::min( + start_lb_, + static_cast(lb_[i] * LbGreedyAcceptableLoss)); + } } } }); @@ -802,6 +825,13 @@ struct raptor { auto const is_first = i == 0U; auto const is_last = i == stop_seq.size() - 1U; + if constexpr (LbGreedy) { + if (lb_[l_idx] > LbGreedyThreshold && + lb_[l_idx] > state_.rt_transport_lb_[rt_t]) { + continue; + } + } + if constexpr (WithSectionBikeFilter) { if (!is_first && !rtt_->rt_bikes_allowed_per_section_[rt_t][kFwd ? stop_idx - 1 @@ -906,6 +936,13 @@ struct raptor { auto const is_first = i == 0U; auto const is_last = i == stop_seq.size() - 1U; + if constexpr (LbGreedy) { + if (lb_[l_idx] > LbGreedyThreshold && + lb_[l_idx] > state_.route_lb_[r]) { + continue; + } + } + auto current_best = std::array{}; current_best.fill(kInvalid); @@ -1264,6 +1301,7 @@ struct raptor { bool require_car_transport_; bool is_wheelchair_; transfer_time_settings transfer_time_settings_; + std::uint16_t start_lb_; }; } // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor/raptor_state.h b/include/nigiri/routing/raptor/raptor_state.h index 278fcce4d..b1c351faa 100644 --- a/include/nigiri/routing/raptor/raptor_state.h +++ b/include/nigiri/routing/raptor/raptor_state.h @@ -89,6 +89,8 @@ struct raptor_state { bitvec prev_station_mark_; bitvec route_mark_; bitvec rt_transport_mark_; + vector_map route_lb_; + vector_map rt_transport_lb_; }; } // namespace nigiri::routing diff --git a/src/abi.cc b/src/abi.cc index f65a7abc3..17c6303a7 100644 --- a/src/abi.cc +++ b/src/abi.cc @@ -303,7 +303,7 @@ nigiri::pareto_set raptor_search( if (backward_search) { using algo_t = nigiri::routing::raptor; + nigiri::routing::search_mode::kOneToOne, false>; return *(nigiri::routing::search{ tt, rtt, search_state, algo_state, std::move(q)} .execute() @@ -311,7 +311,7 @@ nigiri::pareto_set raptor_search( } else { using algo_t = nigiri::routing::raptor; + nigiri::routing::search_mode::kOneToOne, false>; return *(nigiri::routing::search{ tt, rtt, search_state, algo_state, std::move(q)} .execute() diff --git a/src/routing/one_to_all.cc b/src/routing/one_to_all.cc index 9a253c3fd..169424522 100644 --- a/src/routing/one_to_all.cc +++ b/src/routing/one_to_all.cc @@ -24,10 +24,11 @@ day_idx_t make_base(timetable const& tt, unixtime_t start_time) { } template -void run_raptor(raptor&& algo, - timetable const& tt, - unixtime_t const& start_time, - query const& q) { +void run_raptor( + raptor&& algo, + timetable const& tt, + unixtime_t const& start_time, + query const& q) { auto results = pareto_set{}; algo.next_start_time(); for (auto const& s : q.start_) { @@ -69,7 +70,7 @@ raptor_state one_to_all(timetable const& tt, auto const base = make_base(tt, start_time); auto const is_wheelchair = q.prf_idx_ == kWheelchairProfile; - auto r = raptor{ + auto r = raptor{ tt, rtt, state, diff --git a/src/routing/raptor/pong.cc b/src/routing/raptor/pong.cc index 8ed571212..9e46445a2 100644 --- a/src/routing/raptor/pong.cc +++ b/src/routing/raptor/pong.cc @@ -304,7 +304,7 @@ routing_result pong(timetable const& tt, collect_via_destinations(tt, via.location_, ping_is_via[i]); } - auto ping = raptor{ + auto ping = raptor{ tt, rtt, r_state, @@ -350,7 +350,7 @@ routing_result pong(timetable const& tt, collect_via_destinations(tt, via.location_, pong_is_via[i]); } - auto pong = raptor{ + auto pong = raptor{ tt, rtt, r_state, diff --git a/src/routing/raptor/raptor_state.cc b/src/routing/raptor/raptor_state.cc index f364ce29e..7164b8709 100644 --- a/src/routing/raptor/raptor_state.cc +++ b/src/routing/raptor/raptor_state.cc @@ -23,6 +23,8 @@ raptor_state& raptor_state::resize(unsigned const n_locations, prev_station_mark_.resize(n_locations); route_mark_.resize(n_routes); rt_transport_mark_.resize(n_rt_transports); + route_lb_.resize(n_routes); + rt_transport_lb_.resize(n_rt_transports); return *this; } diff --git a/src/routing/raptor_search.cc b/src/routing/raptor_search.cc index 006eb96ed..ed9da3d72 100644 --- a/src/routing/raptor_search.cc +++ b/src/routing/raptor_search.cc @@ -29,12 +29,13 @@ routing_result raptor_search_with_vias( query q, std::optional const timeout) { if (rtt == nullptr) { - using algo_t = raptor; + using algo_t = + raptor; return search{tt, rtt, s_state, r_state, std::move(q), timeout} .execute(); } else { - using algo_t = raptor; + using algo_t = raptor; return search{tt, rtt, s_state, r_state, std::move(q), timeout} .execute();