Skip to content

Commit

Permalink
revert intermodal ppr fallback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Dec 25, 2021
1 parent 9de5e5d commit d58a0fb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 103 deletions.
3 changes: 0 additions & 3 deletions base/module/src/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ msg_ptr dispatcher::api_desc(int const id) const {
}

void dispatcher::handle_no_target(msg_ptr const& msg, callback const& cb) {
LOG(logging::warn) << "target \""
<< msg->get()->destination()->target()->str()
<< "\" not found";
if (queue_no_target_msgs_) {
no_target_msg_queue_.emplace(msg, cb);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ struct direct_connection {

std::vector<direct_connection> get_direct_connections(
query_start const& q_start, query_dest const& q_dest,
IntermodalRoutingRequest const* req, ppr_profiles const& profiles,
bool const ppr_fallback);
IntermodalRoutingRequest const* req, ppr_profiles const& profiles);

std::size_t remove_dominated_journeys(
std::vector<journey>& journeys,
Expand Down
1 change: 0 additions & 1 deletion modules/intermodal/include/motis/intermodal/intermodal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct intermodal : public motis::module::module {

std::string router_{"routing"};
bool revise_{false};
bool ppr_fallback_{false};
ppr_profiles ppr_profiles_;
};

Expand Down
4 changes: 2 additions & 2 deletions modules/intermodal/include/motis/intermodal/mumo_edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ using mumo_stats_appender_fun = std::function<void(stats_category&&)>;

void make_starts(IntermodalRoutingRequest const*, geo::latlng const&,
appender_fun const&, mumo_stats_appender_fun const&,
ppr_profiles const&, bool ppr_fallback);
ppr_profiles const&);
void make_dests(IntermodalRoutingRequest const*, geo::latlng const&,
appender_fun const&, mumo_stats_appender_fun const&,
ppr_profiles const&, bool ppr_fallback);
ppr_profiles const&);

void remove_intersection(std::vector<mumo_edge>& starts,
std::vector<mumo_edge>& destinations,
Expand Down
44 changes: 13 additions & 31 deletions modules/intermodal/src/direct_connections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ msg_ptr make_direct_osrm_request(geo::latlng const& start,

std::vector<direct_connection> get_direct_connections(
query_start const& q_start, query_dest const& q_dest,
IntermodalRoutingRequest const* req, ppr_profiles const& profiles,
bool const ppr_fallback) {
IntermodalRoutingRequest const* req, ppr_profiles const& profiles) {
auto direct = std::vector<direct_connection>{};
auto const beeline = distance(q_start.pos_, q_dest.pos_);

Expand All @@ -199,35 +198,18 @@ std::vector<direct_connection> get_direct_connections(
auto const ppr_settings = get_direct_ppr_settings(req, profiles);
if (ppr_settings.max_duration_ > 0 && beeline <= ppr_settings.max_distance_) {
futures.emplace_back(spawn_job_void([&]() {
try {
auto const ppr_msg =
motis_call(make_direct_ppr_request(
q_start.pos_, q_dest.pos_, ppr_settings.profile_,
ppr_settings.max_duration_, req->search_dir()))
->val();
auto const ppr_resp = motis_content(FootRoutingResponse, ppr_msg);
auto const routes = ppr_resp->routes();

if (routes->size() == 1) {
std::lock_guard guard{direct_mutex};
for (auto const& route : *routes->Get(0)->routes()) {
direct.emplace_back(mumo_type::FOOT, route->duration(),
route->accessibility());
}
} else if (ppr_fallback) {
std::lock_guard guard{direct_mutex};
auto const duration =
(beeline / profiles.get_walking_speed(ppr_settings.profile_)) /
60.0F * 1.5F;
direct.emplace_back(mumo_type::FOOT, duration, 0);
}
} catch (std::exception const& /* module not found */) {
if (ppr_fallback) {
std::lock_guard guard{direct_mutex};
auto const duration =
(beeline / profiles.get_walking_speed(ppr_settings.profile_)) /
60.0F * 1.5F;
direct.emplace_back(mumo_type::FOOT, duration, 0);
auto const ppr_msg =
motis_call(make_direct_ppr_request(
q_start.pos_, q_dest.pos_, ppr_settings.profile_,
ppr_settings.max_duration_, req->search_dir()))
->val();
auto const ppr_resp = motis_content(FootRoutingResponse, ppr_msg);
auto const routes = ppr_resp->routes();
if (routes->size() == 1) {
std::lock_guard guard{direct_mutex};
for (auto const& route : *routes->Get(0)->routes()) {
direct.emplace_back(mumo_type::FOOT, route->duration(),
route->accessibility());
}
}
}));
Expand Down
31 changes: 14 additions & 17 deletions modules/intermodal/src/intermodal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ namespace motis::intermodal {
intermodal::intermodal() : module("Intermodal Options", "intermodal") {
param(router_, "router", "routing module");
param(revise_, "revise", "revise connections");
param(ppr_fallback_, "ppr_fallback",
"use direct line as fallback if ppr is not available or results are "
"empty (useful if ppr doesn't cover the whole timetable area)");
}

intermodal::~intermodal() = default;
Expand Down Expand Up @@ -205,12 +202,14 @@ void apply_parking_patches(journey& j, std::vector<parking_patch>& patches) {
}
}

msg_ptr postprocess_response(
msg_ptr const& response_msg, query_start const& q_start,
query_dest const& q_dest, IntermodalRoutingRequest const* req,
std::vector<mumo_edge const*> const& edge_mapping, statistics& stats,
bool const revise, std::vector<stats_category> const& mumo_stats,
ppr_profiles const& profiles, bool const ppr_fallback) {
msg_ptr postprocess_response(msg_ptr const& response_msg,
query_start const& q_start,
query_dest const& q_dest,
IntermodalRoutingRequest const* req,
std::vector<mumo_edge const*> const& edge_mapping,
statistics& stats, bool const revise,
std::vector<stats_category> const& mumo_stats,
ppr_profiles const& profiles) {
auto const dir = req->search_dir();
auto routing_response = motis_content(RoutingResponse, response_msg);
auto journeys = message_to_journeys(routing_response);
Expand Down Expand Up @@ -260,8 +259,7 @@ msg_ptr postprocess_response(
}

MOTIS_START_TIMING(direct_connection_timing);
auto const direct =
get_direct_connections(q_start, q_dest, req, profiles, ppr_fallback);
auto const direct = get_direct_connections(q_start, q_dest, req, profiles);
stats.dominated_by_direct_connection_ =
remove_dominated_journeys(journeys, direct);
add_direct_connections(journeys, direct, q_start, q_dest, req);
Expand Down Expand Up @@ -366,15 +364,15 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
req, start.pos_,
std::bind(appender, std::ref(deps), // NOLINT
STATION_START, _1, start.pos_, _2, _3, _4, _5, _6),
mumo_stats_appender, ppr_profiles_, ppr_fallback_);
mumo_stats_appender, ppr_profiles_);
}));
}
if (dest.is_intermodal_) {
futures.emplace_back(spawn_job_void([&]() {
make_dests(req, dest.pos_,
std::bind(appender, std::ref(arrs), // NOLINT
_1, STATION_END, _2, dest.pos_, _3, _4, _5, _6),
mumo_stats_appender, ppr_profiles_, ppr_fallback_);
mumo_stats_appender, ppr_profiles_);
}));
}
} else {
Expand All @@ -384,15 +382,15 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
req, start.pos_,
std::bind(appender, std::ref(deps), // NOLINT
_1, STATION_START, _2, start.pos_, _3, _4, _5, _6),
mumo_stats_appender, ppr_profiles_, ppr_fallback_);
mumo_stats_appender, ppr_profiles_);
}));
}
if (dest.is_intermodal_) {
futures.emplace_back(spawn_job_void([&]() {
make_dests(req, dest.pos_,
std::bind(appender, std::ref(arrs), // NOLINT
STATION_END, _1, dest.pos_, _2, _3, _4, _5, _6),
mumo_stats_appender, ppr_profiles_, ppr_fallback_);
mumo_stats_appender, ppr_profiles_);
}));
}
}
Expand Down Expand Up @@ -435,8 +433,7 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
stats.routing_duration_ =
static_cast<uint64_t>(MOTIS_TIMING_MS(routing_timing));
return postprocess_response(resp, start, dest, req, edge_mapping, stats,
revise_, mumo_stats, ppr_profiles_,
ppr_fallback_);
revise_, mumo_stats, ppr_profiles_);
}

} // namespace motis::intermodal
68 changes: 21 additions & 47 deletions modules/intermodal/src/mumo_edge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ msg_ptr make_ppr_request(latlng const& pos,

void ppr_edges(latlng const& pos, SearchOptions const* search_options,
Direction direction, appender_fun const& appender,
ppr_profiles const& profiles, bool const ppr_fallback) {
ppr_profiles const& profiles) {
auto const max_dur = search_options->duration_limit();
if (max_dur == 0) {
return;
Expand All @@ -114,46 +114,21 @@ void ppr_edges(latlng const& pos, SearchOptions const* search_options,
auto const geo_resp = motis_content(LookupGeoStationResponse, geo_msg);
auto const stations = geo_resp->stations();

auto const make_direct_edges_fallback = [&]() {
for (auto const& s : *stations) {
auto const station_pos = to_latlng(s->pos());
auto const duration =
(distance(station_pos, pos) /
profiles.get_walking_speed(search_options->profile()->str())) /
60.0F * 1.5F;
if (duration <= search_options->duration_limit()) {
appender(s->id()->str(), station_pos, duration, 0, mumo_type::FOOT, 0);
}
}
};

try {
auto const ppr_msg =
motis_call(make_ppr_request(pos, stations, search_options, direction))
->val();
auto const ppr_resp = motis_content(FootRoutingResponse, ppr_msg);

auto const routes = ppr_resp->routes();
if (ppr_fallback && routes->size() == 0U) {
make_direct_edges_fallback();
return;
}

assert(routes->size() <= stations->size());
for (auto i = 0U; i < routes->size(); ++i) {
auto const dest_routes = routes->Get(i);
auto const dest_id = stations->Get(i)->id()->str();
auto const dest_pos = to_latlng(stations->Get(i)->pos());
for (auto const& route : *dest_routes->routes()) {
appender(dest_id, dest_pos, route->duration(), route->accessibility(),
mumo_type::FOOT, 0);
}
}
} catch (std::exception const& /* probably module not found */) {
if (!ppr_fallback) {
throw;
auto const ppr_msg =
motis_call(make_ppr_request(pos, stations, search_options, direction))
->val();
auto const ppr_resp = motis_content(FootRoutingResponse, ppr_msg);

auto const routes = ppr_resp->routes();
assert(routes->size() <= stations->size());
for (auto i = 0U; i < routes->size(); ++i) {
auto const dest_routes = routes->Get(i);
auto const dest_id = stations->Get(i)->id()->str();
auto const dest_pos = to_latlng(stations->Get(i)->pos());
for (auto const& route : *dest_routes->routes()) {
appender(dest_id, dest_pos, route->duration(), route->accessibility(),
mumo_type::FOOT, 0);
}
make_direct_edges_fallback();
}
}

Expand Down Expand Up @@ -200,7 +175,7 @@ void make_edges(Vector<Offset<ModeWrapper>> const* modes, latlng const& pos,
Direction const osrm_direction, appender_fun const& appender,
mumo_stats_appender_fun const& mumo_stats_appender,
std::string const& mumo_stats_prefix,
ppr_profiles const& profiles, bool const ppr_fallback) {
ppr_profiles const& profiles) {
for (auto const& wrapper : *modes) {
switch (wrapper->mode_type()) {
case Mode_Foot: {
Expand Down Expand Up @@ -233,8 +208,7 @@ void make_edges(Vector<Offset<ModeWrapper>> const* modes, latlng const& pos,
case Mode_FootPPR: {
auto const options =
reinterpret_cast<FootPPR const*>(wrapper->mode())->search_options();
ppr_edges(pos, options, osrm_direction, appender, profiles,
ppr_fallback);
ppr_edges(pos, options, osrm_direction, appender, profiles);
break;
}

Expand All @@ -254,17 +228,17 @@ void make_edges(Vector<Offset<ModeWrapper>> const* modes, latlng const& pos,
void make_starts(IntermodalRoutingRequest const* req, latlng const& pos,
appender_fun const& appender,
mumo_stats_appender_fun const& mumo_stats_appender,
ppr_profiles const& profiles, bool const ppr_fallback) {
ppr_profiles const& profiles) {
make_edges(req->start_modes(), pos, Direction_Forward, appender,
mumo_stats_appender, "intermodal.start.", profiles, ppr_fallback);
mumo_stats_appender, "intermodal.start.", profiles);
}

void make_dests(IntermodalRoutingRequest const* req, latlng const& pos,
appender_fun const& appender,
mumo_stats_appender_fun const& mumo_stats_appender,
ppr_profiles const& profiles, bool const ppr_fallback) {
ppr_profiles const& profiles) {
make_edges(req->destination_modes(), pos, Direction_Backward, appender,
mumo_stats_appender, "intermodal.dest.", profiles, ppr_fallback);
mumo_stats_appender, "intermodal.dest.", profiles);
}

void remove_intersection(std::vector<mumo_edge>& starts,
Expand Down

0 comments on commit d58a0fb

Please sign in to comment.