diff --git a/modules/intermodal/include/motis/intermodal/intermodal.h b/modules/intermodal/include/motis/intermodal/intermodal.h index 773041d1b..7798d9827 100644 --- a/modules/intermodal/include/motis/intermodal/intermodal.h +++ b/modules/intermodal/include/motis/intermodal/intermodal.h @@ -26,6 +26,7 @@ struct intermodal : public motis::module::module { std::string router_{"routing"}; bool revise_{false}; + unsigned timeout_{0}; ppr_profiles ppr_profiles_; }; diff --git a/modules/intermodal/src/intermodal.cc b/modules/intermodal/src/intermodal.cc index 0711e735d..39dd6dab1 100644 --- a/modules/intermodal/src/intermodal.cc +++ b/modules/intermodal/src/intermodal.cc @@ -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>{}), - mc.CreateVector(edges)) + mc.CreateVector(edges), true, true, true, 0, + timeout_) .Union(), router); diff --git a/modules/nigiri/src/routing.cc b/modules/nigiri/src/routing.cc index e42c1cafc..df2930ae5 100644 --- a/modules/nigiri/src/routing.cc +++ b/modules/nigiri/src/routing.cc @@ -129,16 +129,18 @@ std::vector get_offsets( template 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 timeout, + n::routing::query&& q) { if (rtt == nullptr) { using algo_t = n::routing::raptor; - return n::routing::search{tt, nullptr, search_state, - raptor_state, std::move(q)} + return n::routing::search{ + tt, nullptr, search_state, raptor_state, std::move(q), timeout} .execute(); } else { using algo_t = n::routing::raptor; - return n::routing::search{tt, rtt, search_state, - raptor_state, std::move(q)} + return n::routing::search{ + 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 { + 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( - *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( - *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_; diff --git a/protocol/routing/RoutingRequest.fbs b/protocol/routing/RoutingRequest.fbs index 833416779..05459e629 100644 --- a/protocol/routing/RoutingRequest.fbs +++ b/protocol/routing/RoutingRequest.fbs @@ -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 }