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

Allow to set a timeout for searches #445

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
1 change: 1 addition & 0 deletions modules/intermodal/include/motis/intermodal/intermodal.h
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ struct intermodal : public motis::module::module {

std::string router_{"routing"};
bool revise_{false};
unsigned timeout_{0};
ppr_profiles ppr_profiles_;
};

4 changes: 3 additions & 1 deletion modules/intermodal/src/intermodal.cc
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ namespace motis::intermodal {
intermodal::intermodal() : module("Intermodal Options", "intermodal") {
param(router_, "router", "routing module");
param(revise_, "revise", "revise connections");
param(timeout_, "timeout", "routing timeout in seconds (0 = no timeout)");
}

intermodal::~intermodal() = default;
@@ -535,7 +536,8 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
CreateRoutingRequest(mc, start.start_type_, start.start_, dest.station_,
req->search_type(), req->search_dir(),
mc.CreateVector(std::vector<Offset<Via>>{}),
mc.CreateVector(edges))
mc.CreateVector(edges), true, true, true, 0,
timeout_)
.Union(),
router);

23 changes: 16 additions & 7 deletions modules/nigiri/src/routing.cc
Original file line number Diff line number Diff line change
@@ -129,16 +129,18 @@ std::vector<n::routing::offset> get_offsets(
template <n::direction SearchDir>
auto run_search(n::routing::search_state& search_state,
n::routing::raptor_state& raptor_state, n::timetable const& tt,
n::rt_timetable const* rtt, n::routing::query&& q) {
n::rt_timetable const* rtt,
std::optional<std::chrono::seconds> timeout,
n::routing::query&& q) {
if (rtt == nullptr) {
using algo_t = n::routing::raptor<SearchDir, false>;
return n::routing::search<SearchDir, algo_t>{tt, nullptr, search_state,
raptor_state, std::move(q)}
return n::routing::search<SearchDir, algo_t>{
tt, nullptr, search_state, raptor_state, std::move(q), timeout}
.execute();
} else {
using algo_t = n::routing::raptor<SearchDir, true>;
return n::routing::search<SearchDir, algo_t>{tt, rtt, search_state,
raptor_state, std::move(q)}
return n::routing::search<SearchDir, algo_t>{
tt, rtt, search_state, raptor_state, std::move(q), timeout}
.execute();
}
}
@@ -155,6 +157,13 @@ motis::module::msg_ptr route(tag_lookup const& tags, n::timetable const& tt,
auto extend_interval_later = false;
auto start_time = n::routing::start_time_t{};
auto start_station = n::location_idx_t::invalid();
auto timeout = [&]() -> std::optional<std::chrono::seconds> {
if (req->timeout() == 0) {
return std::nullopt;
} else {
return {std::chrono::seconds(req->timeout())};
}
}();

if (req->start_type() == routing::Start_PretripStart) {
auto const start =
@@ -309,14 +318,14 @@ motis::module::msg_ptr route(tag_lookup const& tags, n::timetable const& tt,
n::routing::raptor_stats raptor_stats;
if (req->search_dir() == SearchDir_Forward) {
auto const r = run_search<n::direction::kForward>(
*search_state, *raptor_state, tt, rtt, std::move(q));
*search_state, *raptor_state, tt, rtt, timeout, std::move(q));
journeys = r.journeys_;
search_stats = r.search_stats_;
raptor_stats = r.algo_stats_;
search_interval = r.interval_;
} else {
auto const r = run_search<n::direction::kBackward>(
*search_state, *raptor_state, tt, rtt, std::move(q));
*search_state, *raptor_state, tt, rtt, timeout, std::move(q));
journeys = r.journeys_;
search_stats = r.search_stats_;
raptor_stats = r.algo_stats_;
1 change: 1 addition & 0 deletions protocol/routing/RoutingRequest.fbs
Original file line number Diff line number Diff line change
@@ -114,4 +114,5 @@ table RoutingRequest {
use_dest_metas: bool = true;
use_start_footpaths: bool = true;
schedule: ulong; // schedule id (0 = default)
timeout: int = 0; // 0 = none
}