Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .pkg
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[nigiri]
url=git@github.com:motis-project/nigiri.git
branch=master
commit=d09a28b696b0a765d29497c1d1ee827ac0063428
commit=c12f6827aa5649ec55e8a8caa1688ae3ff14d605
[cista]
url=git@github.com:felixguendling/cista.git
branch=master
commit=7bda4b158a87a4db73b5462b6c1821e891295d03
[osr]
url=git@github.com:motis-project/osr.git
branch=master
commit=34307eb0da3508b12de2b3568c916e9a72e98b6c
commit=9f2d528d3389a1ea5759b5288adb53bd38b37a90
[utl]
url=git@github.com:motis-project/utl.git
branch=master
Expand Down
6 changes: 3 additions & 3 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
9237175939260143388
4569470289789309275
cista 7bda4b158a87a4db73b5462b6c1821e891295d03
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost c590212cf9f10badecd5411a8ce11bc1016c74c4
Expand Down Expand Up @@ -31,7 +31,7 @@ pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50
sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75
unordered_dense 2c7230ae7f9c30849a5b089fb4a5d11896b45dcf
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri d09a28b696b0a765d29497c1d1ee827ac0063428
nigiri c12f6827aa5649ec55e8a8caa1688ae3ff14d605
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
Expand All @@ -45,7 +45,7 @@ pbf-sdf-fonts 66f0c760272c7bdd0efeaac5aab5520b9194225e
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles fb8187e7b1ff30f0fffa6e508575b6b1d6c33791
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
osr 34307eb0da3508b12de2b3568c916e9a72e98b6c
osr 9f2d528d3389a1ea5759b5288adb53bd38b37a90
prometheus-cpp e420cd7cf3995a994220b40a36c987ac8e67c0bf
reflect-cpp b1bc07262026260a1a1ae56e9c6503c9c34117a3
FTXUI dd6a5d371fd7a3e2937bb579955003c54b727233
Expand Down
13 changes: 8 additions & 5 deletions include/motis/compute_footpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ using elevator_footpath_map_t = hash_map<
osr::node_idx_t,
hash_set<std::pair<nigiri::location_idx_t, nigiri::location_idx_t>>>;

struct routed_transfers_settings {
struct transfer_routing_options {
osr::search_profile profile_;
nigiri::profile_idx_t profile_idx_;
double max_matching_distance_;
bool extend_missing_{false};
bool extend_missing_;
std::chrono::seconds max_duration_;
std::function<bool(nigiri::location_idx_t)> is_candidate_{};
};

nigiri::profile_idx_t get_profile_idx(osr::search_profile);

using transfer_routing_profiles_t =
std::array<std::optional<transfer_routing_options>, nigiri::kNProfiles>;

elevator_footpath_map_t compute_footpaths(
osr::ways const&,
osr::lookup const&,
osr::platforms const&,
nigiri::timetable&,
osr::elevation_storage const*,
bool update_coordinates,
std::vector<routed_transfers_settings> const& settings);
transfer_routing_profiles_t const& settings);

} // namespace motis
13 changes: 13 additions & 0 deletions include/motis/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "utl/verify.h"

#include "motis/compute_footpaths.h"

namespace motis {

using headers_t = std::map<std::string, std::string>;
Expand Down Expand Up @@ -59,6 +61,14 @@ struct config {
std::optional<tiles> tiles_{};

struct timetable {
struct transfer_profile {
bool operator==(transfer_profile const&) const = default;
std::string profile_;
double max_matching_distance_meters_;
unsigned max_duration_seconds_;
bool extend_missing_;
};

struct dataset {
struct rt {
bool operator==(rt const&) const = default;
Expand Down Expand Up @@ -87,6 +97,8 @@ struct config {

bool operator==(timetable const&) const = default;

transfer_routing_profiles_t get_profiles() const;

std::string first_day_{"TODAY"};
std::uint16_t num_days_{365U};
bool railviz_{true};
Expand All @@ -105,6 +117,7 @@ struct config {
double preprocess_max_matching_distance_{0.0};
std::optional<std::string> default_timezone_{};
std::map<std::string, dataset> datasets_{};
std::optional<std::vector<transfer_profile>> transfer_profiles_{};
std::optional<std::filesystem::path> assistance_times_{};
};
std::optional<timetable> timetable_{};
Expand Down
2 changes: 2 additions & 0 deletions include/motis/endpoints/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct routing {
bool ignore_rental_return_constraints,
api::PedestrianProfileEnum,
api::ElevationCostsEnum,
bool fastest_bike,
std::chrono::seconds max,
double max_matching_distance,
gbfs::gbfs_routing_data&) const;
Expand Down Expand Up @@ -94,6 +95,7 @@ struct routing {
bool arrive_by,
api::PedestrianProfileEnum,
api::ElevationCostsEnum,
bool fastest_bike,
std::chrono::seconds max,
double max_matching_distance,
double fastest_direct_factor,
Expand Down
5 changes: 2 additions & 3 deletions include/motis/journey_to_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,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 car_transfers,
api::PedestrianProfileEnum,
api::ElevationCostsEnum,
nigiri::profile_idx_t,
transfer_routing_profiles_t const&,
bool join_interlined_legs,
bool detailed_transfers,
bool with_fares,
Expand Down
3 changes: 2 additions & 1 deletion include/motis/mode_to_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace motis {
api::ModeEnum to_mode(osr::mode);
osr::search_profile to_profile(api::ModeEnum,
api::PedestrianProfileEnum,
api::ElevationCostsEnum);
api::ElevationCostsEnum,
bool fastest_bike);

} // namespace motis
8 changes: 8 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ paths:
$ref: '#/components/schemas/ElevationCosts'
default: NONE

- name: fastestBike
in: query
required: false
description: Experimental. Optional. Default is `false`. Will probably be replaced by more fine-grained control (e.g. speed).
schema:
type: boolean
default: false

- name: useRoutedTransfers
in: query
required: false
Expand Down
55 changes: 44 additions & 11 deletions src/compute_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ namespace n = nigiri;

namespace motis {

n::profile_idx_t get_profile_idx(osr::search_profile const p) {
switch (p) {
case osr::search_profile::kFoot: return n::kFootProfile;
case osr::search_profile::kWheelchair: return n::kWheelchairProfile;
case osr::search_profile::kCar: return n::kCarProfile;
case osr::search_profile::kBike:
case osr::search_profile::kBikeFast:
case osr::search_profile::kBikeElevationHigh: [[fallthrough]];
case osr::search_profile::kBikeElevationLow: return n::kBikeProfile;
default: throw utl::fail("{} not supported for transfers", to_str(p));
}
}

elevator_footpath_map_t compute_footpaths(
osr::ways const& w,
osr::lookup const& lookup,
osr::platforms const& pl,
nigiri::timetable& tt,
osr::elevation_storage const* elevations,
bool const update_coordinates,
std::vector<routed_transfers_settings> const& settings) {
transfer_routing_profiles_t const& settings) {
fmt::println(std::clog, "creating matches");
auto const matches = get_matches(tt, pl, w);

Expand Down Expand Up @@ -80,15 +93,35 @@ elevator_footpath_map_t compute_footpaths(
auto candidates = vector_map<n::location_idx_t, osr::match_t>{};
auto transfers = n::vector_map<n::location_idx_t, std::vector<n::footpath>>(
tt.n_locations());
for (auto const& mode : settings) {
for (auto const [i, profile] : utl::enumerate(settings)) {
if (!profile.has_value()) {
continue;
}

auto const prf_idx = static_cast<n::profile_idx_t>(i);
auto const& mode = *profile;

candidates.clear();
candidates.resize(tt.n_locations());
for (auto& fps : transfers) {
fps.clear();
}

auto const is_candidate = [&](n::location_idx_t const l) {
return !mode.is_candidate_ || mode.is_candidate_(l);
switch (mode.profile_) {
case osr::search_profile::kBike:
case osr::search_profile::kBikeFast:
case osr::search_profile::kBikeElevationHigh: [[fallthrough]];
case osr::search_profile::kBikeElevationLow:
return utl::any_of(tt.location_routes_[l],
[&](auto r) { return tt.has_bike_transport(r); });

case osr::search_profile::kCar:
return utl::any_of(tt.location_routes_[l],
[&](auto r) { return tt.has_car_transport(r); });

default: return true;
}
};

{
Expand All @@ -113,10 +146,10 @@ elevator_footpath_map_t compute_footpaths(
}

utl::parallel_for_run_threadlocal<state>(
tt.n_locations(), [&](state& s, auto const i) {
tt.n_locations(), [&](state& s, auto const idx) {
cista::for_each_field(s, [](auto& f) { f.clear(); });

auto const l = n::location_idx_t{i};
auto const l = n::location_idx_t{idx};
if (!is_candidate(l)) {
pt->update_monotonic(n_done + i);
return;
Expand Down Expand Up @@ -202,22 +235,22 @@ elevator_footpath_map_t compute_footpaths(
auto transfers_in =
n::vector_map<n::location_idx_t, std::vector<n::footpath>>{};
transfers_in.resize(tt.n_locations());
for (auto const [i, out] : utl::enumerate(transfers)) {
auto const l = n::location_idx_t{i};
for (auto const [j, out] : utl::enumerate(transfers)) {
auto const l = n::location_idx_t{j};
for (auto const fp : out) {
assert(fp.target() < tt.n_locations());
transfers_in[fp.target()].push_back(n::footpath{l, fp.duration()});
}
}
for (auto const& x : transfers) {
tt.locations_.footpaths_out_[mode.profile_idx_].emplace_back(x);
tt.locations_.footpaths_out_[prf_idx].emplace_back(x);
}
for (auto const& x : transfers_in) {
tt.locations_.footpaths_in_[mode.profile_idx_].emplace_back(x);
tt.locations_.footpaths_in_[prf_idx].emplace_back(x);
}

n::loader::build_lb_graph<n::direction::kForward>(tt, mode.profile_idx_);
n::loader::build_lb_graph<n::direction::kBackward>(tt, mode.profile_idx_);
n::loader::build_lb_graph<n::direction::kForward>(tt, prf_idx);
n::loader::build_lb_graph<n::direction::kBackward>(tt, prf_idx);

n_done += tt.n_locations();
}
Expand Down
24 changes: 24 additions & 0 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "rfl.hpp"
#include "rfl/yaml.hpp"

#include "motis/compute_footpaths.h"

namespace fs = std::filesystem;

namespace motis {
Expand Down Expand Up @@ -123,6 +125,7 @@ void config::verify() const {
nigiri::routing::kMaxSearchIntervalSize.count());

if (timetable_) {
timetable_->get_profiles();
for (auto const& [id, d] : timetable_->datasets_) {
utl::verify(!id.contains("_"), "dataset identifier may not contain '_'");
if (d.rt_.has_value()) {
Expand Down Expand Up @@ -174,6 +177,27 @@ void config::verify_input_files_exist() const {
}
}

transfer_routing_profiles_t config::timetable::get_profiles() const {
if (!transfer_profiles_.has_value()) {
return {};
}

auto map = transfer_routing_profiles_t{};
for (auto const& p : *transfer_profiles_) {
auto const profile = osr::to_profile(p.profile_);
auto const prf_idx = get_profile_idx(profile);
utl_verify(!map[prf_idx].has_value(),
"adding transfer profile {}: index {} already taken by {}",
p.profile_, prf_idx, osr::to_str(map[prf_idx]->profile_));
map[prf_idx] = transfer_routing_options{
.profile_ = profile,
.max_matching_distance_ = p.max_matching_distance_meters_,
.extend_missing_ = p.extend_missing_,
.max_duration_ = p.max_duration_seconds_ * std::chrono::seconds{1}};
}
return map;
}

bool config::requires_rt_timetable_updates() const {
return timetable_.has_value() &&
((has_elevators() && get_elevators()->url_.has_value()) ||
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/one_to_all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ api::Reachable one_to_all::operator()(boost::urls::url_view const& url) const {
.start_ = r.get_offsets(
nullptr, one, one_dir, one_modes, std::nullopt, std::nullopt,
std::nullopt, false, query.pedestrianProfile_, query.elevationCosts_,
one_max_time, query.maxMatchingDistance_, gbfs_rd),
true, one_max_time, query.maxMatchingDistance_, gbfs_rd),
.td_start_ =
r.get_td_offsets(nullptr, nullptr, one, one_dir, one_modes,
query.pedestrianProfile_, query.elevationCosts_,
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/one_to_many.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ api::oneToMany_response one_to_many::operator()(
auto const paths = osr::route(
w_, l_,
to_profile(query.mode_, api::PedestrianProfileEnum::FOOT,
query.elevationCosts_),
query.elevationCosts_, true),
*one, many, query.max_,
query.arriveBy_ ? osr::direction::kBackward : osr::direction::kForward,
query.maxMatchingDistance_, nullptr, nullptr, elevations_);
Expand Down
Loading
Loading