From eb5059e27e775c54649f427fe50a0100cdf975c6 Mon Sep 17 00:00:00 2001 From: Michael Kutzner <174690291+MichaelKutzner@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:43:50 +0100 Subject: [PATCH] Add setting for disposable time between transfers This adds an option to increase the time between transfers by a fixed duration. This setting can be used, if passengers want some time for orientation or to compensate small delays. --- include/nigiri/routing/search.h | 3 +- .../nigiri/routing/transfer_time_settings.h | 13 +++++--- test/routing/transfer_time_settings_test.cc | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/nigiri/routing/search.h b/include/nigiri/routing/search.h index 11c3e064d..e4116d339 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -86,7 +86,8 @@ struct search { kMaxVias); tts.factor_ = std::max(tts.factor_, 1.0F); - if (tts.factor_ == 1.0F && tts.min_transfer_time_ == 0_minutes) { + if (tts.factor_ == 1.0F && tts.min_transfer_time_ == 0_minutes && + tts.disposable_time_ == 0_minutes) { tts.default_ = true; } diff --git a/include/nigiri/routing/transfer_time_settings.h b/include/nigiri/routing/transfer_time_settings.h index 6f29700e2..8daf540ae 100644 --- a/include/nigiri/routing/transfer_time_settings.h +++ b/include/nigiri/routing/transfer_time_settings.h @@ -7,12 +7,13 @@ namespace nigiri::routing { struct transfer_time_settings { bool operator==(transfer_time_settings const& o) const { return default_ == o.default_ || - std::tie(min_transfer_time_, factor_) == - std::tie(o.min_transfer_time_, o.factor_); + std::tie(min_transfer_time_, disposable_time_, factor_) == + std::tie(o.min_transfer_time_, disposable_time_, o.factor_); } bool default_{true}; duration_t min_transfer_time_{0}; + duration_t disposable_time_{0}; float factor_{1.0F}; }; @@ -22,9 +23,10 @@ inline T adjusted_transfer_time(transfer_time_settings const& settings, if (settings.default_) { return duration; } else { - return std::max( - static_cast(settings.min_transfer_time_.count()), - static_cast(static_cast(duration) * settings.factor_)); + return static_cast(settings.disposable_time_.count()) + + std::max( + static_cast(settings.min_transfer_time_.count()), + static_cast(static_cast(duration) * settings.factor_)); } } @@ -36,6 +38,7 @@ inline std::chrono::duration> adjusted_transfer_time( return duration; } else { return std::chrono::duration>{ + static_cast(settings.disposable_time_.count()) + std::max(static_cast(settings.min_transfer_time_.count()), static_cast(static_cast(duration.count()) * settings.factor_))}; diff --git a/test/routing/transfer_time_settings_test.cc b/test/routing/transfer_time_settings_test.cc index 2f51c09e9..0b13179e0 100644 --- a/test/routing/transfer_time_settings_test.cc +++ b/test/routing/transfer_time_settings_test.cc @@ -215,5 +215,38 @@ TEST(routing, transfer_time_settings_test) { .factor_ = 2.0F}); EXPECT_EQ(expected_A_C_f20, results_to_str(results, tt)); } + { + // A -> C, default transfer time, 2 min disposable (= 4 min) + auto const results = + search(tt, nullptr, "A", "C", tt.date_range_, dir, + {.default_ = false, .disposable_time_ = duration_t{2}}); + EXPECT_EQ(expected_A_C_f20, results_to_str(results, tt)); + } + { + // A -> C, 1.5x transfer time, 1 min disposable (= 4 min) + auto const results = search(tt, nullptr, "A", "C", tt.date_range_, dir, + {.default_ = false, + .disposable_time_ = duration_t{1}, + .factor_ = 1.5F}); + EXPECT_EQ(expected_A_C_f20, results_to_str(results, tt)); + } + { + // A -> C, min 3 min transfer time, 1 min disposable (= 4 min) + auto const results = search(tt, nullptr, "A", "C", tt.date_range_, dir, + {.default_ = false, + .min_transfer_time_ = duration_t{3}, + .disposable_time_ = duration_t{1}}); + EXPECT_EQ(expected_A_C_f20, results_to_str(results, tt)); + } + { + // A -> C, min 3 min transfer time, 2.5x transfer time, 5 min disposable + // (= 10 min) + auto const results = search(tt, nullptr, "A", "C", tt.date_range_, dir, + {.default_ = false, + .min_transfer_time_ = duration_t{3}, + .disposable_time_ = duration_t{5}, + .factor_ = 2.5F}); + EXPECT_EQ(expected_A_C_min10, results_to_str(results, tt)); + } } }