Skip to content

Commit

Permalink
Via search (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohoch authored Aug 15, 2024
1 parent ea0d02a commit 3077fd7
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[googletest]
[email protected]:motis-project/googletest.git
branch=master
commit=34a46558609e05865c197f0260ab36daa7cbbb6e
commit=7b64fca6ea0833628d6f86255a81424365f7cc0c
[lmdb]
[email protected]:motis-project/lmdb.git
branch=master
Expand Down Expand Up @@ -61,7 +61,7 @@
[utl]
[email protected]:motis-project/utl.git
branch=master
commit=930d194f32a5da6c7d00e69bc53090548611c735
commit=77aac494c45d2b070e65fe712abc34ac74a91d0f
[guess]
[email protected]:motis-project/guess.git
branch=master
Expand All @@ -77,7 +77,7 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=14dd54b7a25240c55586fc1c8e89aafab1f6b0d4
commit=6c19c9682bacd1d532afb24baa9bdc6a3ea36768
[osr]
[email protected]:motis-project/osr.git
branch=master
Expand Down
12 changes: 7 additions & 5 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
13514127881199516696
cista a25863155854a0a5555f7ce24b90d325780c0dd4
13996623562227606747
cista f52a62c4d83377acd398227ab4fcd6c946bdbd70
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost 60cae66449fa3c9599b2b7d3d5d44c65301ed3a3
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
context 797dd16e2b5e959997ddcd5bdeac4f80931169b6
fmt 09e6cf8fa61ff44509595005631f9da5d917ed3f
googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c
utl fd7425b1a57a4b887318ba8c41a3184f8c4a50c5
utl 77aac494c45d2b070e65fe712abc34ac74a91d0f
ctx d514aa0b0001596b0317abaa17a5a689dc601a55
res 7d97784ba785ce8a2677ea77164040fde484fb04
date 646ba5e2e76636d9e65aaa3cf32e3e3a43defa2c
date d84b23ca2432e17f3f04a3e0cc96b096b99c39a2
flatbuffers a2028f13ae6aafe855010b43a0c93f86e04d9717
doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0
geo 7eb4283bde68fc4fbb0bac2fd1d4fa28cba814af
Expand All @@ -20,11 +20,13 @@ mimalloc 2a557cafb2e9e7c872358a83a63c62a7e14330b3
miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4
libressl 39c1bf084d5c179d7bbce7ba902fffbebff0ee15
net 785b39c08212732e510305f0eef18de70f19b15e
PEGTL 0091112da4f0a0004186cab12eb3b2e866c71750
oh 469a148f731a0434dd34c4bc525f6f3c5bc43fda
abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e
protobuf d8136b9c6a62db6ce09900ecdeb82bb793096cbd
unordered_dense c11595a7743d20622637584bddf77243d72ae152
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri 14dd54b7a25240c55586fc1c8e89aafab1f6b0d4
nigiri 6c19c9682bacd1d532afb24baa9bdc6a3ea36768
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium d5cc2a02d997c2b464d37d37c3a75cd9efa23dc4
protozero 8c9f3fa97c2cfdceef86d0b61818ae98e9328f29
Expand Down
2 changes: 2 additions & 0 deletions docs/api/schemas/motis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Transport:
description: TODO
route_text_color:
description: TODO
provider_url:
description: TODO
Walk:
description: TODO
fields:
Expand Down
2 changes: 2 additions & 0 deletions docs/api/schemas/motis/intermodal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ IntermodalRoutingRequest:
Set to `1.0` (the default value if not specified) to use the default
transfer times from the timetable.
via:
description: TODO
11 changes: 9 additions & 2 deletions modules/intermodal/src/intermodal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,19 @@ msg_ptr intermodal::route(msg_ptr const& msg) {
: "/routing"
: req->router()->str();

auto const via = mc.CreateVector(
req->via() != nullptr
? utl::to_vec(*req->via(),
[&mc](Via const* via) {
return motis_copy_table(Via, mc, via);
})
: std::vector<Offset<Via>>{});

mc.create_and_finish(
MsgContent_RoutingRequest,
CreateRoutingRequest(
mc, start.start_type_, start.start_, dest.station_,
req->search_type(), req->search_dir(),
mc.CreateVector(std::vector<Offset<Via>>{}), mc.CreateVector(edges),
req->search_type(), req->search_dir(), via, mc.CreateVector(edges),
true, true, false, 0, timeout_,
req->allowed_claszes() == nullptr
? 0
Expand Down
3 changes: 2 additions & 1 deletion modules/nigiri/src/nigiri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ void nigiri::import(motis::module::import_dispatcher& reg) {
try {
(*loader)->load({.link_stop_distance_ = link_stop_distance_,
.default_tz_ = default_timezone_},
src, *dir, **impl_->tt_, traffic_day_bitfields);
src, *dir, **impl_->tt_, traffic_day_bitfields,
nullptr);
progress_tracker->status("FINISHED").show_progress(false);
} catch (std::exception const& e) {
progress_tracker->status(fmt::format("ERROR: {}", e.what()))
Expand Down
66 changes: 28 additions & 38 deletions modules/nigiri/src/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

#include "boost/thread/tss.hpp"

#include "utl/erase_if.h"
#include "utl/helpers/algorithm.h"
#include "utl/pipes.h"
#include "utl/to_vec.h"
#include "utl/verify.h"

#include "nigiri/routing/limits.h"
#include "nigiri/routing/query.h"
#include "nigiri/routing/raptor/raptor.h"
#include "nigiri/routing/raptor/raptor_state.h"
#include "nigiri/routing/raptor_search.h"
#include "nigiri/routing/search.h"
#include "nigiri/special_stations.h"

Expand Down Expand Up @@ -43,9 +44,14 @@ mm::msg_ptr to_routing_response(
mm::message_creator fbb;
MOTIS_START_TIMING(conversion);
auto const connections =
utl::to_vec(*journeys, [&](n::routing::journey const& j) {
return to_connection(fbb, nigiri_to_motis_journey(tt, rtt, tags, j));
});
utl::all(*journeys) //
| utl::remove_if([&](n::routing::journey const& j) { //
return j.error_;
}) //
| utl::transform([&](n::routing::journey const& j) {
return to_connection(fbb, nigiri_to_motis_journey(tt, rtt, tags, j));
}) //
| utl::vec();
MOTIS_STOP_TIMING(conversion);

auto entries = std::vector<fbs::Offset<StatisticsEntry>>{
Expand Down Expand Up @@ -126,25 +132,6 @@ std::vector<n::routing::offset> get_offsets(
| utl::vec();
}

template <n::direction SearchDir>
auto run_search(n::routing::search_state& search_state,
n::routing::raptor_state& raptor_state, n::timetable const& tt,
n::rt_timetable const* rtt,
std::optional<std::chrono::seconds> timeout,
n::routing::query&& q) {
if (rtt == nullptr) {
using algo_t = n::routing::raptor<SearchDir, false>;
return n::routing::search<SearchDir, algo_t>{
tt, nullptr, search_state, raptor_state, std::move(q), timeout}
.execute();
} else {
using algo_t = n::routing::raptor<SearchDir, true>;
return n::routing::search<SearchDir, algo_t>{
tt, rtt, search_state, raptor_state, std::move(q), timeout}
.execute();
}
}

n::routing::clasz_mask_t to_clasz_mask(fbs::Vector<std::uint8_t> const* v) {
if (v == nullptr) {
return n::routing::all_clasz_allowed();
Expand Down Expand Up @@ -330,6 +317,15 @@ motis::module::msg_ptr route(tag_lookup const& tags, n::timetable const& tt,
.min_transfer_time_ = n::duration_t{req->min_transfer_time()},
.factor_ = req->transfer_time_factor()}};

for (auto const& via : *req->via()) {
auto const station =
get_location_idx(tags, tt, via->station()->id()->view());
utl::verify(station != n::location_idx_t::invalid(),
"unknown via station {}", via->station()->id()->view());
q.via_stops_.emplace_back(n::routing::via_stop{
.location_ = station, .stay_ = n::duration_t{via->stay_duration()}});
}

utl::verify(!q.start_.empty(), "no start edges");
utl::verify(!q.destination_.empty(), "no destination edges");

Expand All @@ -345,21 +341,15 @@ motis::module::msg_ptr route(tag_lookup const& tags, n::timetable const& tt,
n::pareto_set<n::routing::journey> const* journeys{nullptr};
n::routing::search_stats search_stats;
n::routing::raptor_stats raptor_stats;
if (req->search_dir() == SearchDir_Forward) {
auto const r = run_search<n::direction::kForward>(
*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<n::direction::kBackward>(
*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_;
}
auto const dir = req->search_dir() == SearchDir_Forward
? n::direction::kForward
: n::direction::kBackward;
auto const r = n::routing::raptor_search(
tt, rtt, *search_state, *raptor_state, std::move(q), dir, timeout);
journeys = r.journeys_;
search_stats = r.search_stats_;
raptor_stats = r.algo_stats_;
search_interval = r.interval_;
MOTIS_STOP_TIMING(routing);

return to_routing_response(tt, rtt, tags, journeys, search_interval,
Expand Down
1 change: 1 addition & 0 deletions protocol/intermodal/IntermodalRoutingRequest.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ table IntermodalRoutingRequest {
start_modes: [ModeWrapper];
destination: IntermodalDestination;
destination_modes: [ModeWrapper];
via: [routing.Via] (optional);
search_type: routing.SearchType;
search_dir: motis.SearchDir;
router: string (optional);
Expand Down

0 comments on commit 3077fd7

Please sign in to comment.