From c4a75bdd63ebd20bfc8c643d1c8d97bc8f7ccb98 Mon Sep 17 00:00:00 2001 From: mority Date: Fri, 29 Nov 2024 16:23:33 +0100 Subject: [PATCH 01/11] wip --- include/nigiri/routing/query.h | 1 + include/nigiri/routing/raptor/debug.h | 7 +++++++ include/nigiri/routing/raptor/raptor.h | 9 ++++++++- include/nigiri/routing/search.h | 28 ++++++++++++++++++++------ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/nigiri/routing/query.h b/include/nigiri/routing/query.h index 8958a3c13..34d513dad 100644 --- a/include/nigiri/routing/query.h +++ b/include/nigiri/routing/query.h @@ -82,6 +82,7 @@ struct query { transfer_time_settings transfer_time_settings_{}; std::vector via_stops_{}; std::optional fastest_direct_{}; + std::uint32_t id_{0U}; }; } // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index b55a21447..17d48cdb7 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -228,3 +228,10 @@ #define trace_upd(...) #define trace(...) #endif + +#ifdef NIGIRI_DUMP_ROUND_TIMES +#define dump_round_times(path, ptr, size) + +#else +#define dump_round_times(path, ptr, size) +#endif \ No newline at end of file diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index 60273027f..4b15c861c 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -151,7 +151,8 @@ struct raptor { std::uint8_t const max_transfers, unixtime_t const worst_time_at_dest, profile_idx_t const prf_idx, - pareto_set& results) { + pareto_set& results, + std::optional dbg_dir = std::nullopt) { auto const end_k = std::min(max_transfers, kMaxTransfers) + 1U; auto const d_worst_at_dest = unix_to_delta(base(), worst_time_at_dest); @@ -160,6 +161,10 @@ struct raptor { } trace_print_init_state(); + if (dbg_dir) { + std::filesystem::create_directory(*dbg_dir); + // serialize round_times init state + } for (auto k = 1U; k != end_k; ++k) { for (auto i = 0U; i != n_locations_; ++i) { @@ -382,6 +387,8 @@ struct raptor { } } }); + + dump_round_times(, round_times_[k], n_locations_); } void update_footpaths(unsigned const k, profile_idx_t const prf_idx) { diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index a55ae49be..b38271191 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -153,7 +153,8 @@ struct search { search_state& s, algo_state_t& algo_state, query q, - std::optional timeout = std::nullopt) + std::optional timeout = std::nullopt, + std::optional dbg_dir = std::nullopt) : tt_{tt}, rtt_{rtt}, state_{s}, @@ -172,7 +173,8 @@ struct search { q_.require_bike_transport_, q_.transfer_time_settings_, algo_state)}, - timeout_(timeout) { + timeout_(timeout), + dbg_dir_{dbg_dir} { utl::sort(q_.start_); utl::sort(q_.destination_); sanitize_via_stops(tt_, q_); @@ -182,6 +184,10 @@ struct search { auto span = get_otel_tracer()->StartSpan("search::execute"); auto scope = opentelemetry::trace::Scope{span}; + if (dbg_dir_) { + std::filesystem::create_directory(*dbg_dir_ / std::to_string(q_.id_)); + } + state_.results_.clear(); if (start_dest_overlap()) { @@ -210,10 +216,10 @@ struct search { return false; }; - while (true) { + for (auto i = 0U;; ++i) { trace("start_time={}\n", search_interval_); - search_interval(); + search_interval(i); if (is_ontrip() || n_results_in_interval() >= q_.min_connection_count_ || is_timeout_reached()) { @@ -383,10 +389,15 @@ struct search { }); } - void search_interval() { + void search_interval(std::uint32_t i) { auto span = get_otel_tracer()->StartSpan("search::search_interval"); auto scope = opentelemetry::trace::Scope{span}; + if (dbg_dir_) { + std::filesystem::create_directory(*dbg_dir_ / std::to_string(q_.id_) / + std::to_string(i)); + } + utl::equal_ranges_linear( state_.starts_, [](start const& a, start const& b) { @@ -405,7 +416,11 @@ struct search { start_time + (kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime); algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest, - q_.prf_idx_, state_.results_); + q_.prf_idx_, state_.results_, + dbg_dir_ + ? *dbg_dir_ / std::to_string(q_.id_) / + std::to_string(i) / std::to_string(start_time) + : std::nullopt); for (auto& j : state_.results_) { if (j.legs_.empty() && @@ -438,6 +453,7 @@ struct search { duration_t fastest_direct_; Algo algo_; std::optional timeout_; + std::optional dbg_dir_; }; } // namespace nigiri::routing From cdeaeb66e4f0e5c16cf283f741056279d40d3234 Mon Sep 17 00:00:00 2001 From: mority Date: Mon, 2 Dec 2024 13:14:31 +0100 Subject: [PATCH 02/11] wip --- include/nigiri/common/delta_t.h | 3 --- include/nigiri/routing/raptor/debug.h | 29 ++++++++++++++++++++++---- include/nigiri/routing/raptor/raptor.h | 15 +++++++------ include/nigiri/routing/search.h | 21 ++++++++----------- include/nigiri/types.h | 2 ++ 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/include/nigiri/common/delta_t.h b/include/nigiri/common/delta_t.h index 98a5eb0c7..2ec2984bb 100644 --- a/include/nigiri/common/delta_t.h +++ b/include/nigiri/common/delta_t.h @@ -5,9 +5,6 @@ namespace nigiri { -using delta_t = std::int16_t; -static_assert(sizeof(delta_t) == 2); - template inline constexpr auto const kInvalidDelta = SearchDir == direction::kForward ? std::numeric_limits::max() diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index 17d48cdb7..af0246b45 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -2,6 +2,9 @@ #include "fmt/core.h" +#include "nigiri/routing/raptor/raptor_state.h" +#include "nigiri/types.h" + // #define NIGIRI_TRACING #if defined(NIGIRI_TRACING) @@ -229,9 +232,27 @@ #define trace(...) #endif +#define NIGIRI_DUMP_ROUND_TIMES #ifdef NIGIRI_DUMP_ROUND_TIMES -#define dump_round_times(path, ptr, size) - +#define dump_round_times(dbg_dir, tag, state, k, Vias) \ + dump_round_times_fun(dbg_dir, tag, state, k) #else -#define dump_round_times(path, ptr, size) -#endif \ No newline at end of file +#define dump_round_times(dbg_dir, tag, state, k, Vias) +#endif + +namespace nigiri::routing { + +template +void dump_round_times_fun(std::optional const& dbg_dir, + std::string_view tag, + raptor_state const& rs, + unsigned const k) { + if (dbg_dir) { + auto ostrm = std::ofstream{std::format("{}/k{}_{}.bin", *dbg_dir, k, tag), + std::ios::binary}; + ostrm.write(reinterpret_cast(&rs.get_round_times()[k]), + rs.n_locations_ * (Vias + 1) * sizeof(delta_t)); + } +} + +} // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index 4b15c861c..bc9d0547a 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -151,8 +151,7 @@ struct raptor { std::uint8_t const max_transfers, unixtime_t const worst_time_at_dest, profile_idx_t const prf_idx, - pareto_set& results, - std::optional dbg_dir = std::nullopt) { + pareto_set& results) { auto const end_k = std::min(max_transfers, kMaxTransfers) + 1U; auto const d_worst_at_dest = unix_to_delta(base(), worst_time_at_dest); @@ -161,10 +160,7 @@ struct raptor { } trace_print_init_state(); - if (dbg_dir) { - std::filesystem::create_directory(*dbg_dir); - // serialize round_times init state - } + dump_round_times(dbg_dir_, "init", state_, 0U, Vias); for (auto k = 1U; k != end_k; ++k) { for (auto i = 0U; i != n_locations_; ++i) { @@ -387,8 +383,7 @@ struct raptor { } } }); - - dump_round_times(, round_times_[k], n_locations_); + dump_round_times(dbg_dir_, "update_transfers", state_, k, Vias); } void update_footpaths(unsigned const k, profile_idx_t const prf_idx) { @@ -484,6 +479,7 @@ struct raptor { } } }); + dump_round_times(dbg_dir_, "update_footpaths", state_, k, Vias); } void update_td_offsets(unsigned const k, profile_idx_t const prf_idx) { @@ -583,6 +579,7 @@ struct raptor { }); } }); + dump_round_times(dbg_dir_, "update_td_offsets", state_, k, Vias); } void update_intermodal_footpaths(unsigned const k) { @@ -635,6 +632,7 @@ struct raptor { } } }); + dump_round_times(dbg_dir_, "update_intermodal_footpaths", state_, k, Vias); } template @@ -1110,6 +1108,7 @@ struct raptor { bool require_bike_transport_; bool is_wheelchair_; transfer_time_settings transfer_time_settings_; + std::optional dbg_dir_{}; }; } // namespace nigiri::routing diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index b38271191..abe7699ef 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -145,7 +145,8 @@ struct search { allowed_claszes, require_bikes_allowed, q_.prf_idx_ == 2U, - tts}; + tts, + dbg_dir_}; } search(timetable const& tt, @@ -393,11 +394,6 @@ struct search { auto span = get_otel_tracer()->StartSpan("search::search_interval"); auto scope = opentelemetry::trace::Scope{span}; - if (dbg_dir_) { - std::filesystem::create_directory(*dbg_dir_ / std::to_string(q_.id_) / - std::to_string(i)); - } - utl::equal_ranges_linear( state_.starts_, [](start const& a, start const& b) { @@ -415,12 +411,13 @@ struct search { auto const worst_time_at_dest = start_time + (kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime); + if (dbg_dir_) { + algo_.dbg_dir_ = fmt::format("{}/query_{}/interval_{}/{}", + *dbg_dir_, q_.id_, i, start_time); + std::filesystem::create_directory(algo_.dbg_dir_); + } algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest, - q_.prf_idx_, state_.results_, - dbg_dir_ - ? *dbg_dir_ / std::to_string(q_.id_) / - std::to_string(i) / std::to_string(start_time) - : std::nullopt); + q_.prf_idx_, state_.results_); for (auto& j : state_.results_) { if (j.legs_.empty() && @@ -453,7 +450,7 @@ struct search { duration_t fastest_direct_; Algo algo_; std::optional timeout_; - std::optional dbg_dir_; + std::optional dbg_dir_; }; } // namespace nigiri::routing diff --git a/include/nigiri/types.h b/include/nigiri/types.h index a9ac87f0c..b41813850 100644 --- a/include/nigiri/types.h +++ b/include/nigiri/types.h @@ -350,6 +350,8 @@ using transport_mode_id_t = std::int32_t; using via_offset_t = std::uint8_t; +using delta_t = std::int16_t; +static_assert(sizeof(delta_t) == 2); } // namespace nigiri #include From e48b06d726f67bc58ccddbc57be31a3323756a43 Mon Sep 17 00:00:00 2001 From: mority Date: Tue, 3 Dec 2024 18:11:55 +0100 Subject: [PATCH 03/11] wip --- include/nigiri/routing/dump_round_times.h | 29 ++++++++++++++++++++ include/nigiri/routing/raptor/debug.h | 27 +------------------ include/nigiri/routing/raptor/raptor.h | 4 ++- include/nigiri/routing/raptor_search.h | 3 ++- include/nigiri/routing/search.h | 13 +++------ src/routing/raptor_search.cc | 33 ++++++++++++----------- 6 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 include/nigiri/routing/dump_round_times.h diff --git a/include/nigiri/routing/dump_round_times.h b/include/nigiri/routing/dump_round_times.h new file mode 100644 index 000000000..9cb7bd73e --- /dev/null +++ b/include/nigiri/routing/dump_round_times.h @@ -0,0 +1,29 @@ +#pragma once + +#include "nigiri/routing/raptor/raptor_state.h" +#include "nigiri/types.h" + +#define NIGIRI_DUMP_ROUND_TIMES +#ifdef NIGIRI_DUMP_ROUND_TIMES +#define dump_round_times(dbg_dir, tag, state, k, Vias) \ + dump_round_times_fun(dbg_dir, tag, state, k) +#else +#define dump_round_times(dbg_dir, tag, state, k, Vias) +#endif + +namespace nigiri::routing { + +template +void dump_round_times_fun(std::optional const& dbg_dir, + std::string_view tag, + raptor_state const& rs, + unsigned const k) { + if (dbg_dir) { + auto ostrm = std::ofstream{std::format("{}/k{}_{}.bin", *dbg_dir, k, tag), + std::ios::binary}; + ostrm.write(reinterpret_cast(rs.get_round_times()[k]), + rs.n_locations_ * (Vias + 1) * sizeof(delta_t)); + } +} + +} // namespace nigiri::routing \ No newline at end of file diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index af0246b45..991e75927 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -5,7 +5,7 @@ #include "nigiri/routing/raptor/raptor_state.h" #include "nigiri/types.h" -// #define NIGIRI_TRACING +#define NIGIRI_TRACING #if defined(NIGIRI_TRACING) // #define NIGIRI_RAPTOR_TRACING_ONLY_UPDATES @@ -231,28 +231,3 @@ #define trace_upd(...) #define trace(...) #endif - -#define NIGIRI_DUMP_ROUND_TIMES -#ifdef NIGIRI_DUMP_ROUND_TIMES -#define dump_round_times(dbg_dir, tag, state, k, Vias) \ - dump_round_times_fun(dbg_dir, tag, state, k) -#else -#define dump_round_times(dbg_dir, tag, state, k, Vias) -#endif - -namespace nigiri::routing { - -template -void dump_round_times_fun(std::optional const& dbg_dir, - std::string_view tag, - raptor_state const& rs, - unsigned const k) { - if (dbg_dir) { - auto ostrm = std::ofstream{std::format("{}/k{}_{}.bin", *dbg_dir, k, tag), - std::ios::binary}; - ostrm.write(reinterpret_cast(&rs.get_round_times()[k]), - rs.n_locations_ * (Vias + 1) * sizeof(delta_t)); - } -} - -} // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index bc9d0547a..1a4d7b5c0 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -4,6 +4,7 @@ #include "nigiri/common/delta_t.h" #include "nigiri/common/linear_lower_bound.h" +#include "nigiri/routing/dump_round_times.h" #include "nigiri/routing/journey.h" #include "nigiri/routing/limits.h" #include "nigiri/routing/pareto_set.h" @@ -255,6 +256,8 @@ struct raptor { reconstruct_journey(tt_, rtt_, q, state_, j, base(), base_); } + std::optional dbg_dir_; + private: date::sys_days base() const { return tt_.internal_interval_days().from_ + as_int(base_) * date::days{1}; @@ -1108,7 +1111,6 @@ struct raptor { bool require_bike_transport_; bool is_wheelchair_; transfer_time_settings transfer_time_settings_; - std::optional dbg_dir_{}; }; } // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor_search.h b/include/nigiri/routing/raptor_search.h index 104363a3d..d9a918a23 100644 --- a/include/nigiri/routing/raptor_search.h +++ b/include/nigiri/routing/raptor_search.h @@ -13,6 +13,7 @@ routing_result raptor_search( raptor_state& r_state, query q, direction search_dir, - std::optional timeout = std::nullopt); + std::optional timeout = std::nullopt, + std::string const* dbg_dir = nullptr); } // namespace nigiri::routing diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index abe7699ef..355ff9b77 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -145,8 +145,7 @@ struct search { allowed_claszes, require_bikes_allowed, q_.prf_idx_ == 2U, - tts, - dbg_dir_}; + tts}; } search(timetable const& tt, @@ -155,7 +154,7 @@ struct search { algo_state_t& algo_state, query q, std::optional timeout = std::nullopt, - std::optional dbg_dir = std::nullopt) + std::string const* dbg_dir = nullptr) : tt_{tt}, rtt_{rtt}, state_{s}, @@ -185,10 +184,6 @@ struct search { auto span = get_otel_tracer()->StartSpan("search::execute"); auto scope = opentelemetry::trace::Scope{span}; - if (dbg_dir_) { - std::filesystem::create_directory(*dbg_dir_ / std::to_string(q_.id_)); - } - state_.results_.clear(); if (start_dest_overlap()) { @@ -414,7 +409,7 @@ struct search { if (dbg_dir_) { algo_.dbg_dir_ = fmt::format("{}/query_{}/interval_{}/{}", *dbg_dir_, q_.id_, i, start_time); - std::filesystem::create_directory(algo_.dbg_dir_); + std::filesystem::create_directories(*algo_.dbg_dir_); } algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest, q_.prf_idx_, state_.results_); @@ -450,7 +445,7 @@ struct search { duration_t fastest_direct_; Algo algo_; std::optional timeout_; - std::optional dbg_dir_; + std::string const* dbg_dir_; }; } // namespace nigiri::routing diff --git a/src/routing/raptor_search.cc b/src/routing/raptor_search.cc index 176907c1c..282616379 100644 --- a/src/routing/raptor_search.cc +++ b/src/routing/raptor_search.cc @@ -27,17 +27,18 @@ routing_result raptor_search_with_vias( search_state& s_state, raptor_state& r_state, query q, - std::optional const timeout) { + std::optional const timeout, + std::string const* dbg_dir) { if (rtt == nullptr) { using algo_t = raptor; - return search{tt, rtt, s_state, - r_state, std::move(q), timeout} + return search{tt, rtt, s_state, r_state, + std::move(q), timeout, dbg_dir} .execute(); } else { using algo_t = raptor; - return search{tt, rtt, s_state, - r_state, std::move(q), timeout} + return search{tt, rtt, s_state, r_state, + std::move(q), timeout, dbg_dir} .execute(); } } @@ -49,7 +50,8 @@ routing_result raptor_search_with_dir( search_state& s_state, raptor_state& r_state, query q, - std::optional const timeout) { + std::optional const timeout, + std::string const* dbg_dir) { sanitize_via_stops(tt, q); utl::verify(q.via_stops_.size() <= kMaxVias, "too many via stops: {}, limit: {}", q.via_stops_.size(), @@ -60,14 +62,14 @@ routing_result raptor_search_with_dir( switch (q.via_stops_.size()) { case 0: - return raptor_search_with_vias(tt, rtt, s_state, r_state, - std::move(q), timeout); + return raptor_search_with_vias( + tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); case 1: - return raptor_search_with_vias(tt, rtt, s_state, r_state, - std::move(q), timeout); + return raptor_search_with_vias( + tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); case 2: - return raptor_search_with_vias(tt, rtt, s_state, r_state, - std::move(q), timeout); + return raptor_search_with_vias( + tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); } std::unreachable(); } @@ -92,7 +94,8 @@ routing_result raptor_search( raptor_state& r_state, query q, direction const search_dir, - std::optional const timeout) { + std::optional const timeout, + std::string const* dbg_dir) { auto span = get_otel_tracer()->StartSpan("raptor_search"); auto scope = opentelemetry::trace::Scope{span}; if (span->IsRecording()) { @@ -144,10 +147,10 @@ routing_result raptor_search( if (search_dir == direction::kForward) { return raptor_search_with_dir( - tt, rtt, s_state, r_state, std::move(q), timeout); + tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); } else { return raptor_search_with_dir( - tt, rtt, s_state, r_state, std::move(q), timeout); + tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); } } From d9a97d3ffdf2be19b46c7d2428538239526b7068 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 10:04:46 +0100 Subject: [PATCH 04/11] wip --- include/nigiri/routing/dump_round_times.h | 14 +- include/nigiri/routing/raptor/debug.h | 2 +- include/nigiri/routing/raptor_search.h | 3 +- include/nigiri/routing/search.h | 21 +- src/routing/raptor_search.cc | 33 ++-- test/routing/dump_round_times_test.cc | 223 ++++++++++++++++++++++ 6 files changed, 259 insertions(+), 37 deletions(-) create mode 100644 test/routing/dump_round_times_test.cc diff --git a/include/nigiri/routing/dump_round_times.h b/include/nigiri/routing/dump_round_times.h index 9cb7bd73e..c766ba061 100644 --- a/include/nigiri/routing/dump_round_times.h +++ b/include/nigiri/routing/dump_round_times.h @@ -3,13 +3,10 @@ #include "nigiri/routing/raptor/raptor_state.h" #include "nigiri/types.h" -#define NIGIRI_DUMP_ROUND_TIMES -#ifdef NIGIRI_DUMP_ROUND_TIMES +#define NIGIRI_DUMP_ROUND_TIMES_DIR "./round_times" +#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR #define dump_round_times(dbg_dir, tag, state, k, Vias) \ dump_round_times_fun(dbg_dir, tag, state, k) -#else -#define dump_round_times(dbg_dir, tag, state, k, Vias) -#endif namespace nigiri::routing { @@ -21,9 +18,14 @@ void dump_round_times_fun(std::optional const& dbg_dir, if (dbg_dir) { auto ostrm = std::ofstream{std::format("{}/k{}_{}.bin", *dbg_dir, k, tag), std::ios::binary}; - ostrm.write(reinterpret_cast(rs.get_round_times()[k]), + ostrm.write(reinterpret_cast( + &rs.round_times_storage_[k * rs.n_locations_ * (Vias + 1)]), rs.n_locations_ * (Vias + 1) * sizeof(delta_t)); } } +#else +#define dump_round_times(dbg_dir, tag, state, k, Vias) +#endif + } // namespace nigiri::routing \ No newline at end of file diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index 991e75927..8da169911 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -5,7 +5,7 @@ #include "nigiri/routing/raptor/raptor_state.h" #include "nigiri/types.h" -#define NIGIRI_TRACING +// #define NIGIRI_TRACING #if defined(NIGIRI_TRACING) // #define NIGIRI_RAPTOR_TRACING_ONLY_UPDATES diff --git a/include/nigiri/routing/raptor_search.h b/include/nigiri/routing/raptor_search.h index d9a918a23..104363a3d 100644 --- a/include/nigiri/routing/raptor_search.h +++ b/include/nigiri/routing/raptor_search.h @@ -13,7 +13,6 @@ routing_result raptor_search( raptor_state& r_state, query q, direction search_dir, - std::optional timeout = std::nullopt, - std::string const* dbg_dir = nullptr); + std::optional timeout = std::nullopt); } // namespace nigiri::routing diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index 355ff9b77..00461cf57 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -12,6 +12,7 @@ #include "nigiri/get_otel_tracer.h" #include "nigiri/logging.h" #include "nigiri/routing/dijkstra.h" +#include "nigiri/routing/dump_round_times.h" #include "nigiri/routing/get_fastest_direct.h" #include "nigiri/routing/interval_estimate.h" #include "nigiri/routing/journey.h" @@ -153,8 +154,7 @@ struct search { search_state& s, algo_state_t& algo_state, query q, - std::optional timeout = std::nullopt, - std::string const* dbg_dir = nullptr) + std::optional timeout = std::nullopt) : tt_{tt}, rtt_{rtt}, state_{s}, @@ -173,8 +173,7 @@ struct search { q_.require_bike_transport_, q_.transfer_time_settings_, algo_state)}, - timeout_(timeout), - dbg_dir_{dbg_dir} { + timeout_(timeout) { utl::sort(q_.start_); utl::sort(q_.destination_); sanitize_via_stops(tt_, q_); @@ -406,11 +405,14 @@ struct search { auto const worst_time_at_dest = start_time + (kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime); - if (dbg_dir_) { - algo_.dbg_dir_ = fmt::format("{}/query_{}/interval_{}/{}", - *dbg_dir_, q_.id_, i, start_time); - std::filesystem::create_directories(*algo_.dbg_dir_); - } + +#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR + algo_.dbg_dir_ = + fmt::format("{}/query_{}/interval_{}/{}", + NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_, i, start_time); + std::filesystem::create_directories(*algo_.dbg_dir_); + +#endif algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest, q_.prf_idx_, state_.results_); @@ -445,7 +447,6 @@ struct search { duration_t fastest_direct_; Algo algo_; std::optional timeout_; - std::string const* dbg_dir_; }; } // namespace nigiri::routing diff --git a/src/routing/raptor_search.cc b/src/routing/raptor_search.cc index 282616379..176907c1c 100644 --- a/src/routing/raptor_search.cc +++ b/src/routing/raptor_search.cc @@ -27,18 +27,17 @@ routing_result raptor_search_with_vias( search_state& s_state, raptor_state& r_state, query q, - std::optional const timeout, - std::string const* dbg_dir) { + std::optional const timeout) { if (rtt == nullptr) { using algo_t = raptor; - return search{tt, rtt, s_state, r_state, - std::move(q), timeout, dbg_dir} + return search{tt, rtt, s_state, + r_state, std::move(q), timeout} .execute(); } else { using algo_t = raptor; - return search{tt, rtt, s_state, r_state, - std::move(q), timeout, dbg_dir} + return search{tt, rtt, s_state, + r_state, std::move(q), timeout} .execute(); } } @@ -50,8 +49,7 @@ routing_result raptor_search_with_dir( search_state& s_state, raptor_state& r_state, query q, - std::optional const timeout, - std::string const* dbg_dir) { + std::optional const timeout) { sanitize_via_stops(tt, q); utl::verify(q.via_stops_.size() <= kMaxVias, "too many via stops: {}, limit: {}", q.via_stops_.size(), @@ -62,14 +60,14 @@ routing_result raptor_search_with_dir( switch (q.via_stops_.size()) { case 0: - return raptor_search_with_vias( - tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); + return raptor_search_with_vias(tt, rtt, s_state, r_state, + std::move(q), timeout); case 1: - return raptor_search_with_vias( - tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); + return raptor_search_with_vias(tt, rtt, s_state, r_state, + std::move(q), timeout); case 2: - return raptor_search_with_vias( - tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); + return raptor_search_with_vias(tt, rtt, s_state, r_state, + std::move(q), timeout); } std::unreachable(); } @@ -94,8 +92,7 @@ routing_result raptor_search( raptor_state& r_state, query q, direction const search_dir, - std::optional const timeout, - std::string const* dbg_dir) { + std::optional const timeout) { auto span = get_otel_tracer()->StartSpan("raptor_search"); auto scope = opentelemetry::trace::Scope{span}; if (span->IsRecording()) { @@ -147,10 +144,10 @@ routing_result raptor_search( if (search_dir == direction::kForward) { return raptor_search_with_dir( - tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); + tt, rtt, s_state, r_state, std::move(q), timeout); } else { return raptor_search_with_dir( - tt, rtt, s_state, r_state, std::move(q), timeout, dbg_dir); + tt, rtt, s_state, r_state, std::move(q), timeout); } } diff --git a/test/routing/dump_round_times_test.cc b/test/routing/dump_round_times_test.cc new file mode 100644 index 000000000..ce28d7105 --- /dev/null +++ b/test/routing/dump_round_times_test.cc @@ -0,0 +1,223 @@ +#include "gtest/gtest.h" + +#include "nigiri/loader/gtfs/files.h" +#include "nigiri/loader/gtfs/load_timetable.h" +#include "nigiri/loader/init_finish.h" +#include "nigiri/timetable.h" + +#include "../raptor_search.h" + +using namespace date; +using namespace nigiri; +using namespace nigiri::loader; +using namespace nigiri::routing; +using nigiri::test::raptor_intermodal_search; + +namespace { + +/* + * 3 min 5 min 10 min + * offset offset offset + * A0 -> A1 -> A2 -> A3 -> A4 -> A5 + * | | + * /----------5 min-------------/ | + * | /-------------10 min---------/ + * | | + * B0 -> B1 -> B2 -> B3 + * | | + * /-10 min-/ | + * | /-5 min--/ + * | | + * C0 -> C1 -> C2 -> C3 -> C4 -> C5 + * 30 min 20 min 10 min + * offset offset offset + */ +mem_dir shortest_fp_files() { + return mem_dir::read(R"__( +"( +# agency.txt +agency_id,agency_name,agency_url,agency_timezone +MTA,MOTIS Transit Authority,https://motis-project.de/,Europe/Berlin + +# calendar_dates.txt +service_id,date,exception_type +D,20240608,1 + +# stops.txt +stop_id,stop_name,stop_desc,stop_lat,stop_lon,stop_url,location_type,parent_station +A0,A0,start_offset0,,,,,, +A1,A1,start_offset1,,,,,, +A2,A2,start_offset2,,,,,, +A3,A3,first_transfer_to_B,,,,,, +A4,A4,second_transfer_to_B,,,,,, +A5,A5,final_stop_of_A,,,,,, +B0,B0,first_transfer_from_A,,,,,, +B1,B1,second_transfer_from_A,,,,,, +B2,B2,first_transfer_to_C,,,,,, +B3,B3,second_transfer_to_C,,,,,, +C0,C0,start_no_transfer,,,,,, +C1,C1,first_transfer_from_B,,,,,, +C2,C2,second_transfer_from_B,,,,,, +C3,C3,dest_offset0,,,,,, +C4,C4,dest_offset1,,,,,, +C5,C5,dest_offset2,,,,,, + +# routes.txt +route_id,agency_id,route_short_name,route_long_name,route_desc,route_type +A,MTA,A,A,A0 -> A5,0 +B,MTA,B,B,B0 -> B3,0 +C,MTA,C,C,C0 -> C5,0 + +# trips.txt +route_id,service_id,trip_id,trip_headsign,block_id +A,D,AWE,AWE,1 +B,D,BWE,BWE,2 +C,D,CWE,CWE,3 + +# stop_times.txt +trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type +AWE,02:00,02:00,A0,0,0,0 +AWE,02:01,02:02,A1,1,0,0 +AWE,02:06,02:07,A2,2,0,0 +AWE,02:15,02:16,A3,3,0,0 +AWE,02:20,02:21,A4,4,0,0 +AWE,02:25,02:26,A5,5,0,0 +BWE,02:58,03:00,B0,0,0,0 +BWE,03:20,03:22,B1,1,0,0 +BWE,03:30,03:32,B2,2,0,0 +BWE,03:40,03:42,B3,3,0,0 +CWE,03:58,04:00,C0,0,0,0 +CWE,04:08,04:10,C1,1,0,0 +CWE,04:18,04:20,C2,2,0,0 +CWE,04:30,04:32,C3,3,0,0 +CWE,04:40,04:42,C4,4,0,0 +CWE,04:50,04:52,C5,5,0,0 + +# transfers.txt +from_stop_id,to_stop_id,transfer_type,min_transfer_time +A3,B0,2,300 +A4,B1,2,600 +B2,C1,2,600 +B3,C2,2,300 +)__"); +} + +constexpr interval shortest_fp_period() { + using namespace date; + constexpr auto const from = (2024_y / June / 7).operator sys_days(); + constexpr auto const to = (2024_y / June / 9).operator sys_days(); + return {from, to}; +} + +constexpr auto const exp_fwd_journey = R"( +[2024-06-07 23:57, 2024-06-08 03:00] +TRANSFERS: 2 + FROM: (START, START) [2024-06-07 23:57] + TO: (END, END) [2024-06-08 03:00] +leg 0: (START, START) [2024-06-07 23:57] -> (A0, A0) [2024-06-08 00:00] + MUMO (id=23, duration=3) +leg 1: (A0, A0) [2024-06-08 00:00] -> (A3, A3) [2024-06-08 00:15] + 0: A0 A0.............................................. d: 08.06 00:00 [08.06 02:00] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] + 1: A1 A1.............................................. a: 08.06 00:01 [08.06 02:01] d: 08.06 00:02 [08.06 02:02] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] + 2: A2 A2.............................................. a: 08.06 00:06 [08.06 02:06] d: 08.06 00:07 [08.06 02:07] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] + 3: A3 A3.............................................. a: 08.06 00:15 [08.06 02:15] +leg 2: (A3, A3) [2024-06-08 00:15] -> (B0, B0) [2024-06-08 00:20] + FOOTPATH (duration=5) +leg 3: (B0, B0) [2024-06-08 01:00] -> (B3, B3) [2024-06-08 01:40] + 0: B0 B0.............................................. d: 08.06 01:00 [08.06 03:00] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] + 1: B1 B1.............................................. a: 08.06 01:20 [08.06 03:20] d: 08.06 01:22 [08.06 03:22] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] + 2: B2 B2.............................................. a: 08.06 01:30 [08.06 03:30] d: 08.06 01:32 [08.06 03:32] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] + 3: B3 B3.............................................. a: 08.06 01:40 [08.06 03:40] +leg 4: (B3, B3) [2024-06-08 01:40] -> (C2, C2) [2024-06-08 01:45] + FOOTPATH (duration=5) +leg 5: (C2, C2) [2024-06-08 02:20] -> (C5, C5) [2024-06-08 02:50] + 2: C2 C2.............................................. d: 08.06 02:20 [08.06 04:20] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] + 3: C3 C3.............................................. a: 08.06 02:30 [08.06 04:30] d: 08.06 02:32 [08.06 04:32] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] + 4: C4 C4.............................................. a: 08.06 02:40 [08.06 04:40] d: 08.06 02:42 [08.06 04:42] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] + 5: C5 C5.............................................. a: 08.06 02:50 [08.06 04:50] +leg 6: (C5, C5) [2024-06-08 02:50] -> (END, END) [2024-06-08 03:00] + MUMO (id=42, duration=10) + + +)"; + +TEST(routing, raptor_shortest_fp_forward) { + constexpr auto const src = source_idx_t{0U}; + auto const config = loader_config{}; + + timetable tt; + tt.date_range_ = shortest_fp_period(); + register_special_stations(tt); + gtfs::load_timetable(config, src, shortest_fp_files(), tt); + finalize(tt); + + auto const results = raptor_intermodal_search( + tt, nullptr, + {{tt.locations_.location_id_to_idx_.at({.id_ = "A0", .src_ = src}), + 3_minutes, 23U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "A1", .src_ = src}), + 5_minutes, 23U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "A2", .src_ = src}), + 10_minutes, 23U}}, + {{tt.locations_.location_id_to_idx_.at({.id_ = "C3", .src_ = src}), + 30_minutes, 42U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "C4", .src_ = src}), + 20_minutes, 42U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "C5", .src_ = src}), + 10_minutes, 42U}}, + interval{unixtime_t{sys_days{2024_y / June / 7}}, + unixtime_t{sys_days{2024_y / June / 8}}}, + direction::kForward); + + ASSERT_EQ(1U, results.size()); + + std::stringstream ss; + ss << "\n"; + for (auto const& x : results) { + x.print(ss, tt); + ss << "\n\n"; + } + EXPECT_EQ(std::string_view{exp_fwd_journey}, ss.str()); +} + +TEST(routing, raptor_shortest_fp_backward) { + constexpr auto const src = source_idx_t{0U}; + auto const config = loader_config{}; + + timetable tt; + tt.date_range_ = shortest_fp_period(); + register_special_stations(tt); + gtfs::load_timetable(config, src, shortest_fp_files(), tt); + finalize(tt); + + auto const results = raptor_intermodal_search( + tt, nullptr, + {{tt.locations_.location_id_to_idx_.at({.id_ = "C3", .src_ = src}), + 30_minutes, 42U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "C4", .src_ = src}), + 20_minutes, 42U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "C5", .src_ = src}), + 10_minutes, 42U}}, + {{tt.locations_.location_id_to_idx_.at({.id_ = "A0", .src_ = src}), + 3_minutes, 23U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "A1", .src_ = src}), + 5_minutes, 23U}, + {tt.locations_.location_id_to_idx_.at({.id_ = "A2", .src_ = src}), + 10_minutes, 23U}}, + interval{unixtime_t{sys_days{2024_y / June / 7}}, + unixtime_t{sys_days{2024_y / June / 9}}}, + direction::kBackward); + + ASSERT_EQ(1U, results.size()); + + std::stringstream ss; + ss << "\n"; + for (auto const& x : results) { + x.print(ss, tt); + ss << "\n\n"; + } + std::cout << ss.str(); + EXPECT_EQ(std::string_view{exp_bwd_journey}, ss.str()); +} + +} // namespace \ No newline at end of file From 5fa3fe60113548ed2c5f5b6eef94a53ab6552276 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 12:26:39 +0100 Subject: [PATCH 05/11] wip --- include/nigiri/routing/dump_round_times.h | 4 +- include/nigiri/routing/query.h | 2 +- include/nigiri/routing/raptor/raptor.h | 2 + include/nigiri/routing/search.h | 8 +- test/routing/dump_round_times_test.cc | 162 +++------------------- 5 files changed, 28 insertions(+), 150 deletions(-) diff --git a/include/nigiri/routing/dump_round_times.h b/include/nigiri/routing/dump_round_times.h index c766ba061..543c4c7fc 100644 --- a/include/nigiri/routing/dump_round_times.h +++ b/include/nigiri/routing/dump_round_times.h @@ -24,8 +24,8 @@ void dump_round_times_fun(std::optional const& dbg_dir, } } +} // namespace nigiri::routing + #else #define dump_round_times(dbg_dir, tag, state, k, Vias) #endif - -} // namespace nigiri::routing \ No newline at end of file diff --git a/include/nigiri/routing/query.h b/include/nigiri/routing/query.h index 34d513dad..6a6061edf 100644 --- a/include/nigiri/routing/query.h +++ b/include/nigiri/routing/query.h @@ -82,7 +82,7 @@ struct query { transfer_time_settings transfer_time_settings_{}; std::vector via_stops_{}; std::optional fastest_direct_{}; - std::uint32_t id_{0U}; + std::uint32_t id_{}; }; } // namespace nigiri::routing diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index 1a4d7b5c0..a83bc2043 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -124,6 +124,8 @@ struct raptor { algo_stats_t get_stats() const { return stats_; } + day_idx_t get_base() const { return base_; } + void reset_arrivals() { utl::fill(time_at_dest_, kInvalid); round_times_.reset(kInvalidArray); diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index 00461cf57..9e04db2ea 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -407,9 +407,11 @@ struct search { (kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime); #ifdef NIGIRI_DUMP_ROUND_TIMES_DIR - algo_.dbg_dir_ = - fmt::format("{}/query_{}/interval_{}/{}", - NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_, i, start_time); + algo_.dbg_dir_ = fmt::format( + "{}/query_{}_[{}]/interval_{}_[{}]-[{}]/{}", + NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_, + tt_.to_unixtime(algo_.get_base()), i, search_interval_.from_, + search_interval_.to_, start_time); std::filesystem::create_directories(*algo_.dbg_dir_); #endif diff --git a/test/routing/dump_round_times_test.cc b/test/routing/dump_round_times_test.cc index ce28d7105..62db881fc 100644 --- a/test/routing/dump_round_times_test.cc +++ b/test/routing/dump_round_times_test.cc @@ -15,24 +15,7 @@ using nigiri::test::raptor_intermodal_search; namespace { -/* - * 3 min 5 min 10 min - * offset offset offset - * A0 -> A1 -> A2 -> A3 -> A4 -> A5 - * | | - * /----------5 min-------------/ | - * | /-------------10 min---------/ - * | | - * B0 -> B1 -> B2 -> B3 - * | | - * /-10 min-/ | - * | /-5 min--/ - * | | - * C0 -> C1 -> C2 -> C3 -> C4 -> C5 - * 30 min 20 min 10 min - * offset offset offset - */ -mem_dir shortest_fp_files() { +mem_dir dump_round_times_files() { return mem_dir::read(R"__( "( # agency.txt @@ -45,125 +28,57 @@ D,20240608,1 # stops.txt stop_id,stop_name,stop_desc,stop_lat,stop_lon,stop_url,location_type,parent_station -A0,A0,start_offset0,,,,,, -A1,A1,start_offset1,,,,,, -A2,A2,start_offset2,,,,,, -A3,A3,first_transfer_to_B,,,,,, -A4,A4,second_transfer_to_B,,,,,, -A5,A5,final_stop_of_A,,,,,, -B0,B0,first_transfer_from_A,,,,,, -B1,B1,second_transfer_from_A,,,,,, -B2,B2,first_transfer_to_C,,,,,, -B3,B3,second_transfer_to_C,,,,,, -C0,C0,start_no_transfer,,,,,, -C1,C1,first_transfer_from_B,,,,,, -C2,C2,second_transfer_from_B,,,,,, -C3,C3,dest_offset0,,,,,, -C4,C4,dest_offset1,,,,,, -C5,C5,dest_offset2,,,,,, +A0,A0,A0,,,,,, +A1,A1,A1,,,,,, +B0,B0,B0,,,,,, +B1,B1,B1,,,,,, # routes.txt route_id,agency_id,route_short_name,route_long_name,route_desc,route_type -A,MTA,A,A,A0 -> A5,0 -B,MTA,B,B,B0 -> B3,0 -C,MTA,C,C,C0 -> C5,0 +A,MTA,A,A,A0 -> A1,0 +B,MTA,B,B,B0 -> B1,0 + # trips.txt route_id,service_id,trip_id,trip_headsign,block_id A,D,AWE,AWE,1 B,D,BWE,BWE,2 -C,D,CWE,CWE,3 # stop_times.txt trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type AWE,02:00,02:00,A0,0,0,0 -AWE,02:01,02:02,A1,1,0,0 -AWE,02:06,02:07,A2,2,0,0 -AWE,02:15,02:16,A3,3,0,0 -AWE,02:20,02:21,A4,4,0,0 -AWE,02:25,02:26,A5,5,0,0 -BWE,02:58,03:00,B0,0,0,0 -BWE,03:20,03:22,B1,1,0,0 -BWE,03:30,03:32,B2,2,0,0 -BWE,03:40,03:42,B3,3,0,0 -CWE,03:58,04:00,C0,0,0,0 -CWE,04:08,04:10,C1,1,0,0 -CWE,04:18,04:20,C2,2,0,0 -CWE,04:30,04:32,C3,3,0,0 -CWE,04:40,04:42,C4,4,0,0 -CWE,04:50,04:52,C5,5,0,0 +AWE,03:00,03:00,A1,1,0,0 +BWE,04:00,04:00,B0,0,0,0 +BWE,05:00,05:00,B1,1,0,0 # transfers.txt from_stop_id,to_stop_id,transfer_type,min_transfer_time -A3,B0,2,300 -A4,B1,2,600 -B2,C1,2,600 -B3,C2,2,300 +A1,B0,2,300 )__"); } -constexpr interval shortest_fp_period() { +constexpr interval dump_round_times_period() { using namespace date; constexpr auto const from = (2024_y / June / 7).operator sys_days(); constexpr auto const to = (2024_y / June / 9).operator sys_days(); return {from, to}; } -constexpr auto const exp_fwd_journey = R"( -[2024-06-07 23:57, 2024-06-08 03:00] -TRANSFERS: 2 - FROM: (START, START) [2024-06-07 23:57] - TO: (END, END) [2024-06-08 03:00] -leg 0: (START, START) [2024-06-07 23:57] -> (A0, A0) [2024-06-08 00:00] - MUMO (id=23, duration=3) -leg 1: (A0, A0) [2024-06-08 00:00] -> (A3, A3) [2024-06-08 00:15] - 0: A0 A0.............................................. d: 08.06 00:00 [08.06 02:00] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] - 1: A1 A1.............................................. a: 08.06 00:01 [08.06 02:01] d: 08.06 00:02 [08.06 02:02] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] - 2: A2 A2.............................................. a: 08.06 00:06 [08.06 02:06] d: 08.06 00:07 [08.06 02:07] [{name=Tram A, day=2024-06-08, id=AWE, src=0}] - 3: A3 A3.............................................. a: 08.06 00:15 [08.06 02:15] -leg 2: (A3, A3) [2024-06-08 00:15] -> (B0, B0) [2024-06-08 00:20] - FOOTPATH (duration=5) -leg 3: (B0, B0) [2024-06-08 01:00] -> (B3, B3) [2024-06-08 01:40] - 0: B0 B0.............................................. d: 08.06 01:00 [08.06 03:00] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] - 1: B1 B1.............................................. a: 08.06 01:20 [08.06 03:20] d: 08.06 01:22 [08.06 03:22] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] - 2: B2 B2.............................................. a: 08.06 01:30 [08.06 03:30] d: 08.06 01:32 [08.06 03:32] [{name=Tram B, day=2024-06-08, id=BWE, src=0}] - 3: B3 B3.............................................. a: 08.06 01:40 [08.06 03:40] -leg 4: (B3, B3) [2024-06-08 01:40] -> (C2, C2) [2024-06-08 01:45] - FOOTPATH (duration=5) -leg 5: (C2, C2) [2024-06-08 02:20] -> (C5, C5) [2024-06-08 02:50] - 2: C2 C2.............................................. d: 08.06 02:20 [08.06 04:20] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] - 3: C3 C3.............................................. a: 08.06 02:30 [08.06 04:30] d: 08.06 02:32 [08.06 04:32] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] - 4: C4 C4.............................................. a: 08.06 02:40 [08.06 04:40] d: 08.06 02:42 [08.06 04:42] [{name=Tram C, day=2024-06-08, id=CWE, src=0}] - 5: C5 C5.............................................. a: 08.06 02:50 [08.06 04:50] -leg 6: (C5, C5) [2024-06-08 02:50] -> (END, END) [2024-06-08 03:00] - MUMO (id=42, duration=10) - - -)"; - -TEST(routing, raptor_shortest_fp_forward) { +TEST(routing, dump_round_times) { constexpr auto const src = source_idx_t{0U}; auto const config = loader_config{}; timetable tt; - tt.date_range_ = shortest_fp_period(); + tt.date_range_ = dump_round_times_period(); register_special_stations(tt); - gtfs::load_timetable(config, src, shortest_fp_files(), tt); + gtfs::load_timetable(config, src, dump_round_times_files(), tt); finalize(tt); auto const results = raptor_intermodal_search( tt, nullptr, {{tt.locations_.location_id_to_idx_.at({.id_ = "A0", .src_ = src}), - 3_minutes, 23U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "A1", .src_ = src}), - 5_minutes, 23U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "A2", .src_ = src}), - 10_minutes, 23U}}, - {{tt.locations_.location_id_to_idx_.at({.id_ = "C3", .src_ = src}), - 30_minutes, 42U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "C4", .src_ = src}), - 20_minutes, 42U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "C5", .src_ = src}), + 3_minutes, 23U}}, + {{tt.locations_.location_id_to_idx_.at({.id_ = "B1", .src_ = src}), 10_minutes, 42U}}, interval{unixtime_t{sys_days{2024_y / June / 7}}, unixtime_t{sys_days{2024_y / June / 8}}}, @@ -177,47 +92,6 @@ TEST(routing, raptor_shortest_fp_forward) { x.print(ss, tt); ss << "\n\n"; } - EXPECT_EQ(std::string_view{exp_fwd_journey}, ss.str()); -} - -TEST(routing, raptor_shortest_fp_backward) { - constexpr auto const src = source_idx_t{0U}; - auto const config = loader_config{}; - - timetable tt; - tt.date_range_ = shortest_fp_period(); - register_special_stations(tt); - gtfs::load_timetable(config, src, shortest_fp_files(), tt); - finalize(tt); - - auto const results = raptor_intermodal_search( - tt, nullptr, - {{tt.locations_.location_id_to_idx_.at({.id_ = "C3", .src_ = src}), - 30_minutes, 42U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "C4", .src_ = src}), - 20_minutes, 42U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "C5", .src_ = src}), - 10_minutes, 42U}}, - {{tt.locations_.location_id_to_idx_.at({.id_ = "A0", .src_ = src}), - 3_minutes, 23U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "A1", .src_ = src}), - 5_minutes, 23U}, - {tt.locations_.location_id_to_idx_.at({.id_ = "A2", .src_ = src}), - 10_minutes, 23U}}, - interval{unixtime_t{sys_days{2024_y / June / 7}}, - unixtime_t{sys_days{2024_y / June / 9}}}, - direction::kBackward); - - ASSERT_EQ(1U, results.size()); - - std::stringstream ss; - ss << "\n"; - for (auto const& x : results) { - x.print(ss, tt); - ss << "\n\n"; - } - std::cout << ss.str(); - EXPECT_EQ(std::string_view{exp_bwd_journey}, ss.str()); } } // namespace \ No newline at end of file From b278756b4acd18397218039d01ca57c2f380687c Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 13:37:15 +0100 Subject: [PATCH 06/11] wip --- include/nigiri/routing/raptor/raptor.h | 9 +++++---- include/nigiri/routing/search.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index a83bc2043..6aa8b8a34 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -388,7 +388,7 @@ struct raptor { } } }); - dump_round_times(dbg_dir_, "update_transfers", state_, k, Vias); + dump_round_times(dbg_dir_, "1_update_transfers", state_, k, Vias); } void update_footpaths(unsigned const k, profile_idx_t const prf_idx) { @@ -484,7 +484,7 @@ struct raptor { } } }); - dump_round_times(dbg_dir_, "update_footpaths", state_, k, Vias); + dump_round_times(dbg_dir_, "3_update_footpaths", state_, k, Vias); } void update_td_offsets(unsigned const k, profile_idx_t const prf_idx) { @@ -584,7 +584,7 @@ struct raptor { }); } }); - dump_round_times(dbg_dir_, "update_td_offsets", state_, k, Vias); + dump_round_times(dbg_dir_, "4_update_td_offsets", state_, k, Vias); } void update_intermodal_footpaths(unsigned const k) { @@ -637,7 +637,8 @@ struct raptor { } } }); - dump_round_times(dbg_dir_, "update_intermodal_footpaths", state_, k, Vias); + dump_round_times(dbg_dir_, "2_update_intermodal_footpaths", state_, k, + Vias); } template diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index 9e04db2ea..05c6b6794 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -408,13 +408,13 @@ struct search { #ifdef NIGIRI_DUMP_ROUND_TIMES_DIR algo_.dbg_dir_ = fmt::format( - "{}/query_{}_[{}]/interval_{}_[{}]-[{}]/{}", + "{}/query_{}_[{}]/interval_{}_[{}]-[{}]/start_[{}]", NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_, tt_.to_unixtime(algo_.get_base()), i, search_interval_.from_, search_interval_.to_, start_time); std::filesystem::create_directories(*algo_.dbg_dir_); - #endif + algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest, q_.prf_idx_, state_.results_); From 194ca4cf999a3252f4a48b6875e60d18786ced71 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 14:01:25 +0100 Subject: [PATCH 07/11] wip --- exe/benchmark.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exe/benchmark.cc b/exe/benchmark.cc index 5f02f4f54..afc2fd294 100644 --- a/exe/benchmark.cc +++ b/exe/benchmark.cc @@ -115,8 +115,9 @@ void generate_queries( std::cout << "--- Query generator settings ---\n" << gs << "\n--- --- ---\n"; queries.reserve(n_queries); for (auto i = 0U; i != n_queries; ++i) { - auto const sdq = qg.random_query(); + auto sdq = qg.random_query(); if (sdq.has_value()) { + sdq.value().q_.id_ = i; queries.emplace_back(sdq.value()); } } From 0571f80dd7d8bc2a24ee33b5c6a02a9148c58956 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 14:10:14 +0100 Subject: [PATCH 08/11] cleanup --- include/nigiri/routing/raptor/debug.h | 3 --- include/nigiri/routing/search.h | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index 8da169911..b55a21447 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -2,9 +2,6 @@ #include "fmt/core.h" -#include "nigiri/routing/raptor/raptor_state.h" -#include "nigiri/types.h" - // #define NIGIRI_TRACING #if defined(NIGIRI_TRACING) diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index 05c6b6794..24bb7e374 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -211,10 +211,10 @@ struct search { return false; }; - for (auto i = 0U;; ++i) { + while (true) { trace("start_time={}\n", search_interval_); - search_interval(i); + search_interval(); if (is_ontrip() || n_results_in_interval() >= q_.min_connection_count_ || is_timeout_reached()) { @@ -384,7 +384,7 @@ struct search { }); } - void search_interval(std::uint32_t i) { + void search_interval() { auto span = get_otel_tracer()->StartSpan("search::search_interval"); auto scope = opentelemetry::trace::Scope{span}; @@ -410,8 +410,8 @@ struct search { algo_.dbg_dir_ = fmt::format( "{}/query_{}_[{}]/interval_{}_[{}]-[{}]/start_[{}]", NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_, - tt_.to_unixtime(algo_.get_base()), i, search_interval_.from_, - search_interval_.to_, start_time); + tt_.to_unixtime(algo_.get_base()), stats_.interval_extensions_, + search_interval_.from_, search_interval_.to_, start_time); std::filesystem::create_directories(*algo_.dbg_dir_); #endif From b9eb56c45af969454d71d3ce6c2819821c0f2d6c Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 14:17:00 +0100 Subject: [PATCH 09/11] cleanup --- include/nigiri/routing/dump_round_times.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nigiri/routing/dump_round_times.h b/include/nigiri/routing/dump_round_times.h index 543c4c7fc..63710153a 100644 --- a/include/nigiri/routing/dump_round_times.h +++ b/include/nigiri/routing/dump_round_times.h @@ -16,7 +16,7 @@ void dump_round_times_fun(std::optional const& dbg_dir, raptor_state const& rs, unsigned const k) { if (dbg_dir) { - auto ostrm = std::ofstream{std::format("{}/k{}_{}.bin", *dbg_dir, k, tag), + auto ostrm = std::ofstream{fmt::format("{}/k{}_{}.bin", *dbg_dir, k, tag), std::ios::binary}; ostrm.write(reinterpret_cast( &rs.round_times_storage_[k * rs.n_locations_ * (Vias + 1)]), From ce7903f2a0e1665ecda8db3268efb4a614118027 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 14:21:45 +0100 Subject: [PATCH 10/11] cleanup --- include/nigiri/routing/dump_round_times.h | 2 +- include/nigiri/routing/raptor/raptor.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/nigiri/routing/dump_round_times.h b/include/nigiri/routing/dump_round_times.h index 63710153a..e01b4f3c1 100644 --- a/include/nigiri/routing/dump_round_times.h +++ b/include/nigiri/routing/dump_round_times.h @@ -3,7 +3,7 @@ #include "nigiri/routing/raptor/raptor_state.h" #include "nigiri/types.h" -#define NIGIRI_DUMP_ROUND_TIMES_DIR "./round_times" +// #define NIGIRI_DUMP_ROUND_TIMES_DIR "./round_times" #ifdef NIGIRI_DUMP_ROUND_TIMES_DIR #define dump_round_times(dbg_dir, tag, state, k, Vias) \ dump_round_times_fun(dbg_dir, tag, state, k) diff --git a/include/nigiri/routing/raptor/raptor.h b/include/nigiri/routing/raptor/raptor.h index 6aa8b8a34..ce460db83 100644 --- a/include/nigiri/routing/raptor/raptor.h +++ b/include/nigiri/routing/raptor/raptor.h @@ -258,7 +258,9 @@ struct raptor { reconstruct_journey(tt_, rtt_, q, state_, j, base(), base_); } +#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR std::optional dbg_dir_; +#endif private: date::sys_days base() const { From c7762cc0aa3d98c514118ca41792ee6888880ca8 Mon Sep 17 00:00:00 2001 From: mority Date: Wed, 4 Dec 2024 14:26:43 +0100 Subject: [PATCH 11/11] cleanup --- test/routing/dump_round_times_test.cc | 97 --------------------------- 1 file changed, 97 deletions(-) delete mode 100644 test/routing/dump_round_times_test.cc diff --git a/test/routing/dump_round_times_test.cc b/test/routing/dump_round_times_test.cc deleted file mode 100644 index 62db881fc..000000000 --- a/test/routing/dump_round_times_test.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "gtest/gtest.h" - -#include "nigiri/loader/gtfs/files.h" -#include "nigiri/loader/gtfs/load_timetable.h" -#include "nigiri/loader/init_finish.h" -#include "nigiri/timetable.h" - -#include "../raptor_search.h" - -using namespace date; -using namespace nigiri; -using namespace nigiri::loader; -using namespace nigiri::routing; -using nigiri::test::raptor_intermodal_search; - -namespace { - -mem_dir dump_round_times_files() { - return mem_dir::read(R"__( -"( -# agency.txt -agency_id,agency_name,agency_url,agency_timezone -MTA,MOTIS Transit Authority,https://motis-project.de/,Europe/Berlin - -# calendar_dates.txt -service_id,date,exception_type -D,20240608,1 - -# stops.txt -stop_id,stop_name,stop_desc,stop_lat,stop_lon,stop_url,location_type,parent_station -A0,A0,A0,,,,,, -A1,A1,A1,,,,,, -B0,B0,B0,,,,,, -B1,B1,B1,,,,,, - -# routes.txt -route_id,agency_id,route_short_name,route_long_name,route_desc,route_type -A,MTA,A,A,A0 -> A1,0 -B,MTA,B,B,B0 -> B1,0 - - -# trips.txt -route_id,service_id,trip_id,trip_headsign,block_id -A,D,AWE,AWE,1 -B,D,BWE,BWE,2 - -# stop_times.txt -trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type -AWE,02:00,02:00,A0,0,0,0 -AWE,03:00,03:00,A1,1,0,0 -BWE,04:00,04:00,B0,0,0,0 -BWE,05:00,05:00,B1,1,0,0 - -# transfers.txt -from_stop_id,to_stop_id,transfer_type,min_transfer_time -A1,B0,2,300 -)__"); -} - -constexpr interval dump_round_times_period() { - using namespace date; - constexpr auto const from = (2024_y / June / 7).operator sys_days(); - constexpr auto const to = (2024_y / June / 9).operator sys_days(); - return {from, to}; -} - -TEST(routing, dump_round_times) { - constexpr auto const src = source_idx_t{0U}; - auto const config = loader_config{}; - - timetable tt; - tt.date_range_ = dump_round_times_period(); - register_special_stations(tt); - gtfs::load_timetable(config, src, dump_round_times_files(), tt); - finalize(tt); - - auto const results = raptor_intermodal_search( - tt, nullptr, - {{tt.locations_.location_id_to_idx_.at({.id_ = "A0", .src_ = src}), - 3_minutes, 23U}}, - {{tt.locations_.location_id_to_idx_.at({.id_ = "B1", .src_ = src}), - 10_minutes, 42U}}, - interval{unixtime_t{sys_days{2024_y / June / 7}}, - unixtime_t{sys_days{2024_y / June / 8}}}, - direction::kForward); - - ASSERT_EQ(1U, results.size()); - - std::stringstream ss; - ss << "\n"; - for (auto const& x : results) { - x.print(ss, tt); - ss << "\n\n"; - } -} - -} // namespace \ No newline at end of file