Skip to content

Commit

Permalink
use max matching distance (#743)
Browse files Browse the repository at this point in the history
* use max matching distance

* fix formatting

* Update include/motis/odm/meta_router.h
  • Loading branch information
felixguendling authored Feb 16, 2025
1 parent 514e2f2 commit 2167a3b
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 26 deletions.
3 changes: 2 additions & 1 deletion include/motis/compute_footpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ elevator_footpath_map_t compute_footpaths(osr::ways const&,
nigiri::timetable&,
bool update_coordinates,
bool extend_missing,
std::chrono::seconds max_duration);
std::chrono::seconds max_duration,
double max_matching_distance);

} // namespace motis
1 change: 1 addition & 0 deletions include/motis/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct config {
bool use_osm_stop_coordinates_{false};
bool extend_missing_footpaths_{false};
std::uint16_t max_footpath_length_{15};
double max_matching_distance_{25.0};
std::optional<std::string> default_timezone_{};
std::map<std::string, dataset> datasets_{};
std::optional<std::filesystem::path> assistance_times_{};
Expand Down
3 changes: 2 additions & 1 deletion include/motis/endpoints/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ struct routing {
std::optional<std::vector<std::string>> const& rental_providers,
nigiri::unixtime_t start_time,
bool wheelchair,
std::chrono::seconds max) const;
std::chrono::seconds max,
double max_matching_distance) const;

config const& config_;
osr::ways const* w_;
Expand Down
1 change: 1 addition & 0 deletions include/motis/endpoints/trip.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace motis::ep {
struct trip {
api::Itinerary operator()(boost::urls::url_view const&) const;

config const& config_;
osr::ways const* w_;
osr::lookup const* l_;
osr::platforms const* pl_;
Expand Down
4 changes: 3 additions & 1 deletion include/motis/journey_to_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ api::Itinerary journey_to_response(osr::ways const*,
place_t const& dest,
street_routing_cache_t&,
osr::bitvec<osr::node_idx_t>& blocked_mem,
bool detailed_transfers);
bool detailed_transfers,
double timetable_max_matching_distance,
double max_matching_distance);

} // namespace motis
1 change: 1 addition & 0 deletions include/motis/street_routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ api::Itinerary route(osr::ways const&,
bool wheelchair,
nigiri::unixtime_t start_time,
std::optional<nigiri::unixtime_t> end_time,
double max_matching_distance,
gbfs::gbfs_products_ref,
street_routing_cache_t&,
osr::bitvec<osr::node_idx_t>& blocked_mem,
Expand Down
16 changes: 10 additions & 6 deletions src/compute_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ vector_map<n::location_idx_t, osr::match_t> lookup_locations(
osr::platforms const& pl,
n::timetable const& tt,
platform_matches_t const& matches,
osr::search_profile const profile) {
osr::search_profile const profile,
double const max_matching_distance) {
auto const timer = utl::scoped_timer{fmt::format(
"matching timetable locations for profile={}", to_str(profile))};

Expand All @@ -43,7 +44,7 @@ vector_map<n::location_idx_t, osr::match_t> lookup_locations(
// - fixed `reverse=false` only works because foot/wheelchair can use ways
// in both directions.
ret[l] = lookup.match(get_loc(tt, w, pl, matches, l), false,
osr::direction::kForward, kMaxMatchingDistance,
osr::direction::kForward, max_matching_distance,
nullptr, profile);
});

Expand All @@ -57,7 +58,8 @@ elevator_footpath_map_t compute_footpaths(
nigiri::timetable& tt,
bool const update_coordinates,
bool const extend_missing,
std::chrono::seconds const max_duration) {
std::chrono::seconds const max_duration,
double const max_matching_distance) {
fmt::println(std::clog, "creating matches");
auto const matches = get_matches(tt, pl, w);

Expand Down Expand Up @@ -101,9 +103,11 @@ elevator_footpath_map_t compute_footpaths(
};

auto const foot_candidates =
lookup_locations(w, lookup, pl, tt, matches, osr::search_profile::kFoot);
auto const wheelchair_candidates = lookup_locations(
w, lookup, pl, tt, matches, osr::search_profile::kWheelchair);
lookup_locations(w, lookup, pl, tt, matches, osr::search_profile::kFoot,
max_matching_distance);
auto const wheelchair_candidates =
lookup_locations(w, lookup, pl, tt, matches,
osr::search_profile::kWheelchair, max_matching_distance);

struct state {
std::vector<n::footpath> sorted_tt_fps_;
Expand Down
25 changes: 17 additions & 8 deletions src/endpoints/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
std::optional<std::vector<std::string>> const& rental_providers,
n::unixtime_t const start_time,
bool wheelchair,
std::chrono::seconds max) const {
std::chrono::seconds max,
double const max_matching_distance) const {
if (!w_ || !l_) {
return {};
}
Expand All @@ -279,7 +280,7 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
(!omit_walk && m == api::ModeEnum::WALK)) {
auto itinerary =
route(*w_, *l_, gbfs_rd, e, from, to, m, wheelchair, start_time,
std::nullopt, {}, cache, *blocked, max);
std::nullopt, max_matching_distance, {}, cache, *blocked, max);
if (itinerary.legs_.empty()) {
continue;
}
Expand Down Expand Up @@ -307,10 +308,11 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
if (!gbfs::products_match(prod, form_factors, propulsion_types)) {
continue;
}
auto itinerary = route(
*w_, *l_, gbfs_rd, e, from, to, m, wheelchair, start_time,
std::nullopt, gbfs::gbfs_products_ref{provider->idx_, prod.idx_},
cache, *blocked, max);
auto itinerary =
route(*w_, *l_, gbfs_rd, e, from, to, m, wheelchair, start_time,
std::nullopt, max_matching_distance,
gbfs::gbfs_products_ref{provider->idx_, prod.idx_}, cache,
*blocked, max);
if (itinerary.legs_.empty()) {
continue;
}
Expand Down Expand Up @@ -453,7 +455,8 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
query.directRentalProviders_, *t,
query.pedestrianProfile_ ==
api::PedestrianProfileEnum::WHEELCHAIR,
std::chrono::seconds{query.maxDirectTime_})
std::chrono::seconds{query.maxDirectTime_},
query.maxMatchingDistance_)
: std::pair{std::vector<api::Itinerary>{}, kInfinityDuration};
UTL_STOP_TIMING(direct);

Expand Down Expand Up @@ -637,7 +640,13 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
w_, l_, pl_, *tt_, *tags_, e, rtt, matches_, shapes_, gbfs_rd,
query.pedestrianProfile_ ==
api::PedestrianProfileEnum::WHEELCHAIR,
j, start, dest, cache, *blocked, query.detailedTransfers_);
j, start, dest, cache, *blocked, query.detailedTransfers_,
config_.timetable_
.and_then([](config::timetable const& x) {
return std::optional{x.max_matching_distance_};
})
.value_or(kMaxMatchingDistance),
query.maxMatchingDistance_);
}),
.previousPageCursor_ =
fmt::format("EARLIER|{}", to_seconds(r.interval_.from_)),
Expand Down
4 changes: 3 additions & 1 deletion src/endpoints/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "nigiri/rt/gtfsrt_resolve_run.h"
#include "nigiri/timetable.h"

#include "motis/constants.h"
#include "motis/data.h"
#include "motis/gbfs/routing_data.h"
#include "motis/journey_to_response.h"
Expand Down Expand Up @@ -51,7 +52,8 @@ api::Itinerary trip::operator()(boost::urls::url_view const& url) const {
.transfers_ = 0U},
tt_location{from_l.get_location_idx(),
from_l.get_scheduled_location_idx()},
tt_location{to_l.get_location_idx()}, cache, blocked, false);
tt_location{to_l.get_location_idx()}, cache, blocked, false,
config_.timetable_.value().max_matching_distance_, kMaxMatchingDistance);
}

} // namespace motis::ep
3 changes: 2 additions & 1 deletion src/import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ data import(config const& c, fs::path const& data_path, bool const write) {
*d.w_, *d.l_, *d.pl_, *d.tt_,
c.timetable_->use_osm_stop_coordinates_,
c.timetable_->extend_missing_footpaths_,
std::chrono::seconds{c.timetable_->max_footpath_length_ * 60U});
std::chrono::seconds{c.timetable_->max_footpath_length_ * 60U},
c.timetable_->max_matching_distance_);

if (write) {
cista::write(data_path / "elevator_footpath_map.bin",
Expand Down
10 changes: 7 additions & 3 deletions src/journey_to_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ api::Itinerary journey_to_response(osr::ways const* w,
place_t const& dest,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem,
bool const detailed_transfers) {
bool const detailed_transfers,
double const timetable_max_matching_distance,
double const max_matching_distance) {
utl::verify(!j.legs_.empty(), "journey without legs");

auto itinerary = api::Itinerary{
Expand Down Expand Up @@ -166,8 +168,9 @@ api::Itinerary journey_to_response(osr::ways const* w,
append(
w && l
? route(*w, *l, gbfs_rd, e, from, to, api::ModeEnum::WALK,
wheelchair, j_leg.dep_time_, j_leg.arr_time_, {},
cache, blocked_mem,
wheelchair, j_leg.dep_time_, j_leg.arr_time_,
timetable_max_matching_distance, {}, cache,
blocked_mem,
std::chrono::duration_cast<std::chrono::seconds>(
j_leg.arr_time_ - j_leg.dep_time_) +
std::chrono::minutes{10},
Expand All @@ -185,6 +188,7 @@ api::Itinerary journey_to_response(osr::ways const* w,
: to_mode(osr::search_profile{
static_cast<std::uint8_t>(x.transport_mode_id_)}),
wheelchair, j_leg.dep_time_, j_leg.arr_time_,
max_matching_distance,
x.transport_mode_id_ >= kGbfsTransportModeIdOffset
? gbfs_rd.get_products_ref(x.transport_mode_id_)
: gbfs::gbfs_products_ref{},
Expand Down
6 changes: 4 additions & 2 deletions src/odm/meta_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ n::duration_t init_direct(std::vector<direct_ride>& direct_rides,
e, gbfs, from_p, to_p, {api::ModeEnum::CAR}, std::nullopt, std::nullopt,
std::nullopt, intvl.from_,
query.pedestrianProfile_ == api::PedestrianProfileEnum::WHEELCHAIR,
std::chrono::seconds{query.maxDirectTime_});
std::chrono::seconds{query.maxDirectTime_}, query.maxMatchingDistance_);
direct_rides.clear();
if (query.arriveBy_) {
for (auto arr =
Expand Down Expand Up @@ -666,7 +666,9 @@ api::plan_response meta_router::run() {
query_.pedestrianProfile_ ==
api::PedestrianProfileEnum::WHEELCHAIR,
j, start_, dest_, cache, *ep::blocked,
query_.detailedTransfers_);
query_.detailedTransfers_,
r_.config_.timetable_->max_matching_distance_,
query_.maxMatchingDistance_);
}),
.previousPageCursor_ =
fmt::format("EARLIER|{}", to_seconds(pt_result.interval_.from_)),
Expand Down
6 changes: 4 additions & 2 deletions src/street_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ std::optional<osr::path> get_path(osr::ways const& w,
transport_mode_t const transport_mode,
osr::search_profile const profile,
nigiri::unixtime_t const start_time,
double const max_matching_distance,
osr::cost_t const max,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem) {
Expand All @@ -42,7 +43,7 @@ std::optional<osr::path> get_path(osr::ways const& w,
? it->second
: osr::route(
w, l, profile, from, to, max, osr::direction::kForward,
kMaxMatchingDistance,
max_matching_distance,
s ? &set_blocked(e_nodes, e_states, blocked_mem) : nullptr,
sharing);
if (it == end(cache)) {
Expand Down Expand Up @@ -282,6 +283,7 @@ api::Itinerary route(osr::ways const& w,
bool const wheelchair,
n::unixtime_t const start_time,
std::optional<n::unixtime_t> const end_time,
double const max_matching_distance,
gbfs::gbfs_products_ref const prod_ref,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem,
Expand Down Expand Up @@ -315,7 +317,7 @@ api::Itinerary route(osr::ways const& w,
w, l, e, sharing_data ? &sharing_data->sharing_data_ : nullptr,
get_location(from), get_location(to),
static_cast<transport_mode_t>(gbfs_rd.get_transport_mode(prod_ref)),
to_profile(mode, wheelchair), start_time,
to_profile(mode, wheelchair), start_time, max_matching_distance,
static_cast<osr::cost_t>(max.count()), cache, blocked_mem);

if (p.has_value() && profile == osr::search_profile::kBikeSharing) {
Expand Down
1 change: 1 addition & 0 deletions test/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ osm: europe-latest.osm.pbf
use_osm_stop_coordinates: false
extend_missing_footpaths: false
max_footpath_length: 15
max_matching_distance: 25
datasets:
de:
path: delfi.gtfs.zip
Expand Down

0 comments on commit 2167a3b

Please sign in to comment.