Skip to content

Commit

Permalink
Bike transport (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohoch authored Jun 14, 2024
1 parent 46872c9 commit 050fa6c
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=cacfbecd4588f81acb897bc7810338f2864ef200
commit=90c5012f486458b5e3a7e5d73d23f4b91810558a
[osr]
[email protected]:motis-project/osr.git
branch=master
Expand Down
8 changes: 4 additions & 4 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
2923910640934473736
cista bec8bca4e6a38e38236a99ca4d4b767690fc01a1
3559145096142957776
cista 259ee7fbdc622e8f796081337ea842c5b152791c
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost 60cae66449fa3c9599b2b7d3d5d44c65301ed3a3
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
context 797dd16e2b5e959997ddcd5bdeac4f80931169b6
fmt 3503709ac2ba2a938676e6b2071f1362294e278b
fmt 09e6cf8fa61ff44509595005631f9da5d917ed3f
googletest 34a46558609e05865c197f0260ab36daa7cbbb6e
utl fd7425b1a57a4b887318ba8c41a3184f8c4a50c5
ctx d514aa0b0001596b0317abaa17a5a689dc601a55
Expand All @@ -24,7 +24,7 @@ abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e
protobuf d8136b9c6a62db6ce09900ecdeb82bb793096cbd
unordered_dense c11595a7743d20622637584bddf77243d72ae152
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri cacfbecd4588f81acb897bc7810338f2864ef200
nigiri 90c5012f486458b5e3a7e5d73d23f4b91810558a
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium d5cc2a02d997c2b464d37d37c3a75cd9efa23dc4
protozero 8c9f3fa97c2cfdceef86d0b61818ae98e9328f29
Expand Down
6 changes: 6 additions & 0 deletions docs/api/schemas/motis/intermodal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,9 @@ IntermodalRoutingRequest:
The maximum number of transfers allowed per journey.
If set to `-1`, the internal default value is used.
bike_transport:
description: |
Whether only journeys where bike transport is allowed should be considered.
If set to `true`, only trips where bike transport is allowed can be
used.
6 changes: 6 additions & 0 deletions docs/api/schemas/motis/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ RoutingRequest:
The maximum number of transfers allowed per journey.
If set to `-1`, the internal default value is used.
bike_transport:
description: |
Whether only journeys where bike transport is allowed should be considered.
If set to `true`, only trips where bike transport is allowed can be
used.
RoutingResponse:
description: TODO
fields:
Expand Down
2 changes: 1 addition & 1 deletion modules/intermodal/src/intermodal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
? 0
: mc.CreateVector(req->allowed_claszes()->Data(),
req->allowed_claszes()->size()),
req->max_transfers())
req->max_transfers(), req->bike_transport())
.Union(),
router);

Expand Down
1 change: 1 addition & 0 deletions modules/nigiri/include/motis/nigiri/nigiri.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct nigiri : public motis::module::module {
unsigned gtfsrt_update_interval_sec_{60U};
bool gtfsrt_incremental_{false};
bool debug_{false};
bool bikes_allowed_default_{false};
};

} // namespace motis::nigiri
14 changes: 11 additions & 3 deletions modules/nigiri/src/nigiri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ nigiri::nigiri() : module("Next Generation Routing", "nigiri") {
param(gtfsrt_incremental_, "gtfsrt_incremental",
"true=incremental updates, false=forget all prev. RT updates");
param(debug_, "debug", "write protobuf JSON files for debugging");
param(bikes_allowed_default_, "bikes_allowed_default",
"whether bikes are allowed in trips where no information is "
"available");
}

nigiri::~nigiri() = default;
Expand Down Expand Up @@ -391,6 +394,7 @@ void nigiri::import(motis::module::import_dispatcher& reg) {
adjust_footpaths_, link_stop_distance_,
cista::hash(default_timezone_));

auto bitfield_indices = n::hash_map<n::bitfield, n::bitfield_idx_t>{};
auto datasets =
std::vector<std::tuple<n::source_idx_t,
decltype(impl_->loaders_)::const_iterator,
Expand Down Expand Up @@ -438,10 +442,14 @@ void nigiri::import(motis::module::import_dispatcher& reg) {
<< "loading nigiri timetable with configuration "
<< (*loader)->name();

auto config = n::loader::loader_config{
.link_stop_distance_ = link_stop_distance_,
.default_tz_ = default_timezone_};
config.bikes_allowed_default_.fill(bikes_allowed_default_);

try {
(*loader)->load({.link_stop_distance_ = link_stop_distance_,
.default_tz_ = default_timezone_},
src, *dir, **impl_->tt_);
(*loader)->load(config, src, *dir, **impl_->tt_,
bitfield_indices);
progress_tracker->status("FINISHED").show_progress(false);
} catch (std::exception const& e) {
progress_tracker->status(fmt::format("ERROR: {}", e.what()))
Expand Down
143 changes: 69 additions & 74 deletions modules/nigiri/src/nigiri_to_motis_journey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ motis::journey nigiri_to_motis_journey(n::timetable const& tt,
};

auto const add_walk = [&](n::routing::journey::leg const& leg,
n::duration_t const duration, int mumo_id,
bool const is_last) {
n::duration_t const duration, int mumo_id) {
auto const is_transfer =
leg.from_ == leg.to_ ||
(leg.from_ == tt.locations_.parents_.at(leg.to_)) ||
Expand All @@ -69,10 +68,6 @@ motis::journey nigiri_to_motis_journey(n::timetable const& tt,
(tt.locations_.types_.at(leg.to_) ==
n::location_type::kGeneratedTrack)));

if (is_transfer && is_last) {
return;
}

auto& from_stop =
mj.stops_.empty() ? mj.stops_.emplace_back() : mj.stops_.back();
auto const from_stop_idx = mj.stops_.size() - 1U;
Expand Down Expand Up @@ -215,74 +210,74 @@ motis::journey nigiri_to_motis_journey(n::timetable const& tt,
};

for (auto const [i, leg] : utl::enumerate(nj.legs_)) {
std::visit(
utl::overloaded{
[&](n::routing::journey::run_enter_exit const& t) {
auto const fr = n::rt::frun{tt, rtt, t.r_};
for (auto const& stop_idx : t.stop_range_) {
auto const stp = fr[stop_idx];
if (stp.is_canceled()) {
continue;
}

auto const exit = (stop_idx == t.stop_range_.to_ - 1U);
auto const enter = (stop_idx == t.stop_range_.from_);

auto const reuse_arrival = enter && !mj.stops_.empty();
auto& stop =
reuse_arrival ? mj.stops_.back() : mj.stops_.emplace_back();
auto const l = stp.get_location_idx();
fill_stop_info(stop, l);

if (exit) {
stop.exit_ = true;
}
if (enter) {
stop.enter_ = true;
}

if (!enter) {
stop.arrival_.valid_ = true;
stop.arrival_.timestamp_ =
to_motis_unixtime(stp.time(n::event_type::kArr));
stop.arrival_.schedule_timestamp_ = to_motis_unixtime(
stp.scheduled_time(n::event_type::kArr));
stop.arrival_.timestamp_reason_ =
fr.is_rt() ? timestamp_reason::FORECAST
: timestamp_reason::SCHEDULE;

auto const track = stp.track();
stop.arrival_.track_ = std::string{track};
stop.arrival_.schedule_track_ = std::string{track};
}

if (!exit) {
stop.departure_.valid_ = true;
stop.departure_.timestamp_ =
to_motis_unixtime(stp.time(n::event_type::kDep));
stop.departure_.schedule_timestamp_ = to_motis_unixtime(
stp.scheduled_time(n::event_type::kDep));
stop.departure_.timestamp_reason_ =
fr.is_rt() ? timestamp_reason::FORECAST
: timestamp_reason::SCHEDULE;

auto const track = stp.track();
stop.departure_.track_ = std::string{track};
stop.departure_.schedule_track_ = std::string{track};
}

if (!exit) {
add_transports(fr, stop_idx);
}
}
},
[&, i = i, leg = leg](n::footpath const fp) {
add_walk(leg, fp.duration(), -1, i == nj.legs_.size() - 1U);
},
[&, leg = leg](n::routing::offset const x) {
add_walk(leg, x.duration(), x.transport_mode_id_, false);
}},
leg.uses_);
std::visit(utl::overloaded{
[&](n::routing::journey::run_enter_exit const& t) {
auto const fr = n::rt::frun{tt, rtt, t.r_};
for (auto const& stop_idx : t.stop_range_) {
auto const stp = fr[stop_idx];
if (stp.is_canceled()) {
continue;
}

auto const exit = (stop_idx == t.stop_range_.to_ - 1U);
auto const enter = (stop_idx == t.stop_range_.from_);

auto const reuse_arrival = enter && !mj.stops_.empty();
auto& stop = reuse_arrival ? mj.stops_.back()
: mj.stops_.emplace_back();
auto const l = stp.get_location_idx();
fill_stop_info(stop, l);

if (exit) {
stop.exit_ = true;
}
if (enter) {
stop.enter_ = true;
}

if (!enter) {
stop.arrival_.valid_ = true;
stop.arrival_.timestamp_ =
to_motis_unixtime(stp.time(n::event_type::kArr));
stop.arrival_.schedule_timestamp_ = to_motis_unixtime(
stp.scheduled_time(n::event_type::kArr));
stop.arrival_.timestamp_reason_ =
fr.is_rt() ? timestamp_reason::FORECAST
: timestamp_reason::SCHEDULE;

auto const track = stp.track();
stop.arrival_.track_ = std::string{track};
stop.arrival_.schedule_track_ = std::string{track};
}

if (!exit) {
stop.departure_.valid_ = true;
stop.departure_.timestamp_ =
to_motis_unixtime(stp.time(n::event_type::kDep));
stop.departure_.schedule_timestamp_ =
to_motis_unixtime(
stp.scheduled_time(n::event_type::kDep));
stop.departure_.timestamp_reason_ =
fr.is_rt() ? timestamp_reason::FORECAST
: timestamp_reason::SCHEDULE;

auto const track = stp.track();
stop.departure_.track_ = std::string{track};
stop.departure_.schedule_track_ = std::string{track};
}

if (!exit) {
add_transports(fr, stop_idx);
}
}
},
[&, leg = leg](n::footpath const fp) {
add_walk(leg, fp.duration(), -1);
},
[&, leg = leg](n::routing::offset const x) {
add_walk(leg, x.duration(), x.transport_mode_id_);
}},
leg.uses_);
}

for (auto const& [x, ranges] : transports.get_attribute_ranges()) {
Expand Down
3 changes: 2 additions & 1 deletion modules/nigiri/src/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ motis::module::msg_ptr route(tag_lookup const& tags, n::timetable const& tt,
.extend_interval_earlier_ = extend_interval_earlier,
.extend_interval_later_ = extend_interval_later,
.prf_idx_ = prf_idx,
.allowed_claszes_ = to_clasz_mask(req->allowed_claszes())};
.allowed_claszes_ = to_clasz_mask(req->allowed_claszes()),
.require_bike_transport_ = req->bike_transport()};

utl::verify(!q.start_.empty(), "no start edges");
utl::verify(!q.destination_.empty(), "no destination edges");
Expand Down
1 change: 1 addition & 0 deletions protocol/intermodal/IntermodalRoutingRequest.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ table IntermodalRoutingRequest {
router: string (optional);
allowed_claszes: [ubyte] (optional);
max_transfers: int = -1 (optional); // -1 = use default value
bike_transport: bool = false (optional);
}
1 change: 1 addition & 0 deletions protocol/routing/RoutingRequest.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ table RoutingRequest {
timeout: int = 0; // 0 = none
allowed_claszes: [ubyte] (optional);
max_transfers: int = -1 (optional); // -1 = use default value
bike_transport: bool = false (optional);
}

0 comments on commit 050fa6c

Please sign in to comment.