Skip to content

Commit

Permalink
update osr, railviz bugfix (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling authored Apr 16, 2024
1 parent 93b075d commit 5ee023f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
[osr]
[email protected]:motis-project/osr.git
branch=master
commit=0ec618deffbc251063f76b2a29d98beab86c1cd7
commit=4666c6ca17375ffc5591987d9eb426fb6b33c22c
[adr]
[email protected]:triptix-tech/adr.git
branch=master
Expand Down
6 changes: 3 additions & 3 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
5800182487558556983
cista 251a73b51768bea0a23c538e3aa7f47648411a87
5622279301642490618
cista 715692faa0d6dea6c878e2e1a64cdbd1324274f7
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost 1c3f21c1fa8b149da89e2f6bcb48b28fff30fa5e
cereal 5afa46f98d1c22627777c3f9d048fffe3f9763dc
Expand Down Expand Up @@ -38,7 +38,7 @@ sol2 fdb0f8a60e48aa737f0a8d73edede48627f0c984
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles 64f297ea0f782d04c89e82c6d478a1dd453e5f70
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
osr 0ec618deffbc251063f76b2a29d98beab86c1cd7
osr 4666c6ca17375ffc5591987d9eb426fb6b33c22c
luabind b5d39b6f7511930115964304a423f0e6336e0eb2
tbb b3011be5060ec1be43c76d4a8cc80d5550adb31d
osrm-backend a7fe58cf3b6a54968d1248e0b4299d49db02ff2e
Expand Down
9 changes: 5 additions & 4 deletions modules/nigiri/src/railviz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ struct railviz::impl {

auto const fr = n::rt::frun{tt_, rtt_.get(), r};
for (auto const [from, to] : utl::pairwise(fr)) {
runs.emplace_back(
stop_pair{.r_ = fr, // NOLINT(cppcoreguidelines-slicing)
.from_ = from.stop_idx_,
.to_ = to.stop_idx_});
runs.emplace_back(stop_pair{.r_ = r,
.from_ = static_cast<n::stop_idx_t>(
from.stop_idx_ - fr.stop_range_.from_),
.to_ = static_cast<n::stop_idx_t>(
to.stop_idx_ - fr.stop_range_.from_)});
}
}
return create_response(runs);
Expand Down
93 changes: 71 additions & 22 deletions modules/osr/src/osr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#include "cista/reflection/comparable.h"

#include "osr/extract.h"
#include "osr/extract/extract.h"
#include "osr/lookup.h"
#include "osr/route.h"
#include "osr/routing/profiles/bike.h"
#include "osr/routing/profiles/car.h"
#include "osr/routing/profiles/foot.h"
#include "osr/routing/route.h"
#include "osr/ways.h"

#include "motis/core/common/logging.h"
Expand All @@ -25,7 +28,7 @@ namespace o = osr;

namespace motis::osr {

constexpr auto const kMaxDist = o::dist_t{3600}; // = 1h
constexpr auto const kMaxDist = o::cost_t{3600U}; // = 1h

struct import_state {
CISTA_COMPARABLE()
Expand All @@ -39,16 +42,17 @@ struct osr::impl {
impl(std::unique_ptr<o::ways> w, std::unique_ptr<o::lookup> l)
: w_{std::move(w)}, l_{std::move(l)} {}

o::dijkstra_state& get_dijkstra_state() {
if (s_.get() == nullptr) {
s_.reset(new o::dijkstra_state{});
template <typename Profile>
o::dijkstra<Profile>& get_dijkstra() {
static auto s = boost::thread_specific_ptr<o::dijkstra<Profile>>{};
if (s.get() == nullptr) {
s.reset(new o::dijkstra<Profile>{});
}
return *s_;
return *s;
}

std::unique_ptr<o::ways> w_;
std::unique_ptr<o::lookup> l_;
boost::thread_specific_ptr<o::dijkstra_state> s_;
};

osr::osr() : module("Open Street Router", "osr") {
Expand Down Expand Up @@ -79,18 +83,34 @@ mm::msg_ptr osr::table(mm::msg_ptr const& msg) const {
});
auto const fut = utl::to_vec(*req->from(), [&](auto&& from) {
return mm::spawn_job([&]() {
return o::route(*impl_->w_, *impl_->l_,
{from_fbs(from), o::level_t::invalid()}, {to}, kMaxDist,
profile, o::direction::kForward,
impl_->get_dijkstra_state());
switch (profile) {
case o::search_profile::kFoot:
return o::route(*impl_->w_, *impl_->l_,
impl_->get_dijkstra<o::foot>(),
{from_fbs(from), o::level_t::invalid()}, {to},
kMaxDist, o::direction::kForward);
break;
case o::search_profile::kBike:
return o::route(*impl_->w_, *impl_->l_,
impl_->get_dijkstra<o::bike>(),
{from_fbs(from), o::level_t::invalid()}, {to},
kMaxDist, o::direction::kForward);
break;
case o::search_profile::kCar:
return o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::car>(),
{from_fbs(from), o::level_t::invalid()}, {to},
kMaxDist, o::direction::kForward);
break;
default: throw utl::fail("not implemented");
}
});
});

auto durations = std::vector<double>{};
for (auto const& row : fut) {
for (auto const& d : row->val()) {
durations.emplace_back(
d.has_value() ? d->time_ : std::numeric_limits<double>::max());
d.has_value() ? d->cost_ : std::numeric_limits<double>::max());
}
}

Expand All @@ -115,8 +135,22 @@ mm::msg_ptr osr::one_to_many(mm::msg_ptr const& msg) const {
auto const dir = req->direction() == SearchDir_Forward
? o::direction::kForward
: o::direction::kBackward;
auto const result = o::route(*impl_->w_, *impl_->l_, from, to, kMaxDist,
profile, dir, impl_->get_dijkstra_state());
auto result = std::vector<std::optional<o::path>>{};
switch (profile) {
case o::search_profile::kFoot:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::foot>(),
from, to, kMaxDist, dir);
break;
case o::search_profile::kBike:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::bike>(),
from, to, kMaxDist, dir);
break;
case o::search_profile::kCar:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::car>(),
from, to, kMaxDist, dir);
break;
default: throw utl::fail("not implemented");
}

mm::message_creator fbb;
fbb.create_and_finish(
Expand All @@ -127,7 +161,7 @@ mm::msg_ptr osr::one_to_many(mm::msg_ptr const& msg) const {
result,
[&](auto const& r) {
return r.has_value()
? motis::osrm::Cost{static_cast<double>(r->time_),
? motis::osrm::Cost{static_cast<double>(r->cost_),
static_cast<double>(r->dist_)}
: motis::osrm::Cost{
std::numeric_limits<double>::max(),
Expand All @@ -144,11 +178,26 @@ mm::msg_ptr osr::via(mm::msg_ptr const& msg) const {
utl::verify(req->waypoints()->size() == 2U, "no via points supported");

auto const profile = o::to_profile(req->profile()->view());
auto const result =
o::route(*impl_->w_, *impl_->l_,
{from_fbs(req->waypoints()->Get(0)), o::level_t::invalid()},
{from_fbs(req->waypoints()->Get(1)), o::level_t::invalid()},
kMaxDist, profile, impl_->get_dijkstra_state());
auto const from =
o::location{from_fbs(req->waypoints()->Get(0)), o::level_t::invalid()};
auto const to =
o::location{from_fbs(req->waypoints()->Get(1)), o::level_t::invalid()};
auto result = std::optional<o::path>{};
switch (profile) {
case o::search_profile::kFoot:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::foot>(),
from, to, kMaxDist, o::direction::kForward);
break;
case o::search_profile::kBike:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::bike>(),
from, to, kMaxDist, o::direction::kForward);
break;
case o::search_profile::kCar:
result = o::route(*impl_->w_, *impl_->l_, impl_->get_dijkstra<o::car>(),
from, to, kMaxDist, o::direction::kForward);
break;
default: throw utl::fail("not implemented");
}

utl::verify(result.has_value(), "no path found");

Expand All @@ -163,7 +212,7 @@ mm::msg_ptr osr::via(mm::msg_ptr const& msg) const {
fbb.create_and_finish(
MsgContent_OSRMViaRouteResponse,
osrm::CreateOSRMViaRouteResponse(
fbb, static_cast<int>(result->time_), result->dist_,
fbb, static_cast<int>(result->cost_), result->dist_,
CreatePolyline(fbb, fbb.CreateVector(doubles.data(), doubles.size())))
.Union());
return make_msg(fbb);
Expand Down

0 comments on commit 5ee023f

Please sign in to comment.