Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update osr: no level propagation #639

Merged
merged 5 commits into from
Nov 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[osr]
[email protected]:motis-project/osr.git
branch=master
commit=03de6b4553e6d76b44a26b477dcd9343333f4f25
commit=02c6782ecb882a8beab6396608c6a5a279db3cbc
[utl]
[email protected]:motis-project/utl.git
branch=master
Expand Down
4 changes: 2 additions & 2 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
747451078969031840
6189593023066036854
cista 5b6808fd7d7a7c1c7e4cb152b563dbf71e3efba4
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 73549ebca677fe6214202a1ab580362b4f80e653
Expand Down Expand Up @@ -39,7 +39,7 @@ sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles 6b6dc45bc904966640c7207ab91950848a8b3f6c
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
osr 03de6b4553e6d76b44a26b477dcd9343333f4f25
osr 02c6782ecb882a8beab6396608c6a5a279db3cbc
yaml-cpp 1d8ca1f35eb3a9c9142462b28282a848e5d29a91
reflect-cpp c54fe66de4650b60c23aadd4a06d9db4ffeda22f
FTXUI dd6a5d371fd7a3e2937bb579955003c54b727233
Expand Down
2 changes: 1 addition & 1 deletion include/motis/get_loc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline osr::location get_loc(
}
}
auto const lvl = matches[l] == osr::platform_idx_t::invalid()
? osr::to_level(0.0F)
? osr::level_t{0.F}
: pl.get_level(w, matches[l]);
return {pos, lvl};
}
Expand Down
2 changes: 1 addition & 1 deletion include/motis/hashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using meta_entry_t = std::pair<std::string, std::uint64_t>;
using meta_t = std::map<std::string, std::uint64_t>;

constexpr auto const osr_version = []() {
return meta_entry_t{"osr_bin_ver", 4U};
return meta_entry_t{"osr_bin_ver", 5U};
};
constexpr auto const adr_version = []() {
return meta_entry_t{"adr_bin_ver", 1U};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ api::footpaths_response footpaths::operator()(
.stopId_ = std::string{l.id_},
.lat_ = l.pos_.lat(),
.lon_ = l.pos_.lng(),
.level_ = osr::to_float(pl_.get_level(w_, matches_[l.l_])),
.level_ = pl_.get_level(w_, matches_[l.l_]).to_float(),
.vertexType_ = api::VertexTypeEnum::NORMAL};
};

Expand Down
9 changes: 6 additions & 3 deletions src/endpoints/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ json::value graph::operator()(json::value const& query) const {
auto const min = geo::latlng{x[1].as_double(), x[0].as_double()};
auto const max = geo::latlng{x[3].as_double(), x[2].as_double()};
auto const level = q.contains("level")
? osr::to_level(q.at("level").to_number<float>())
? osr::level_t{q.at("level").to_number<float>()}
: osr::kNoLevel;

auto gj = osr::geojson_writer{.w_ = w_};
Expand All @@ -39,15 +39,18 @@ json::value graph::operator()(json::value const& query) const {
auto has_level = false;
utl::for_each_set_bit(
osr::foot<true>::get_elevator_multi_levels(*w_.r_, n),
[&](auto&& bit) { has_level |= (level == osr::level_t{bit}); });
[&](auto&& bit) {
has_level |=
(level == osr::level_t{static_cast<std::uint8_t>(bit)});
});
if (has_level) {
gj.write_way(w);
return;
}
}
}

if ((level == osr::to_level(0.0) &&
if ((level == osr::level_t{0.F} &&
way_prop.from_level() == osr::kNoLevel) ||
way_prop.from_level() == level || way_prop.to_level() == level) {
gj.write_way(w);
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/levels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ api::levels_response levels::operator()(
auto levels = hash_set<float>{};
l_.find({min->pos_, max->pos_}, [&](osr::way_idx_t const x) {
auto const p = w_.r_->way_properties_[x];
levels.emplace(to_float(p.from_level()));
levels.emplace(to_float(p.to_level()));
levels.emplace(p.from_level().to_float());
levels.emplace(p.to_level().to_float());
});
auto levels_sorted =
utl::to_vec(levels, [](float const l) { return static_cast<double>(l); });
Expand Down
29 changes: 15 additions & 14 deletions src/endpoints/matches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ json::value matches::operator()(json::value const& query) const {
{"type", "Feature"},
{"properties",
{{"type", "platform"},
{"level", to_float(pl_.get_level(w_, p))},
{"level", pl_.get_level(w_, p).to_float()},
{"platform_names", fmt::format("{}", get_names(pl_, p))}}},
{"geometry", osr::to_point(osr::point::from_latlng(*center))}});
});
Expand All @@ -54,19 +54,20 @@ json::value matches::operator()(json::value const& query) const {
if (match == osr::platform_idx_t::invalid()) {
props.emplace("level", "-");
} else {
std::visit(
utl::overloaded{
[&](osr::way_idx_t x) {
props.emplace("osm_way_id", to_idx(w_.way_osm_idx_[x]));
props.emplace("level",
to_float(w_.r_->way_properties_[x].from_level()));
},
[&](osr::node_idx_t x) {
props.emplace("osm_node_id", to_idx(w_.node_to_osm_[x]));
props.emplace(
"level", to_float(w_.r_->node_properties_[x].from_level()));
}},
osr::to_ref(pl_.platform_ref_[match][0]));
std::visit(utl::overloaded{
[&](osr::way_idx_t x) {
props.emplace("osm_way_id", to_idx(w_.way_osm_idx_[x]));
props.emplace(
"level",
w_.r_->way_properties_[x].from_level().to_float());
},
[&](osr::node_idx_t x) {
props.emplace("osm_node_id", to_idx(w_.node_to_osm_[x]));
props.emplace(
"level",
w_.r_->node_properties_[x].from_level().to_float());
}},
osr::to_ref(pl_.platform_ref_[match][0]));
}
matches.emplace_back(
json::value{{"type", "Feature"},
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/osr_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ osr::location parse_location(json::value const& v) {
auto const& obj = v.as_object();
return {{obj.at("lat").as_double(), obj.at("lng").as_double()},
obj.contains("level")
? osr::to_level(obj.at("level").to_number<float>())
? osr::level_t{obj.at("level").to_number<float>()}
: osr::kNoLevel};
}

Expand Down Expand Up @@ -54,7 +54,7 @@ json::value osr_routing::operator()(json::value const& query) const {
return json::value{
{"type", "Feature"},
{"properties",
{{"level", to_float(s.from_level_)},
{{"level", s.from_level_.to_float()},
{"way",
s.way_ == osr::way_idx_t::invalid()
? 0U
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/platforms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace motis::ep {
json::value platforms::operator()(json::value const& query) const {
auto const& q = query.as_object();
auto const level = q.contains("level")
? osr::to_level(query.at("level").to_number<float>())
? osr::level_t{query.at("level").to_number<float>()}
: osr::kNoLevel;
auto const waypoints = q.at("waypoints").as_array();
auto const min = osr::point::from_latlng(
Expand Down
2 changes: 1 addition & 1 deletion src/match_platforms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ osr::platform_idx_t get_match(n::timetable const& tt,
tt.locations_.names_[l].view());
auto const lvl = pl.get_level(w, x);
auto const lvl_bonus =
lvl != osr::kNoLevel && osr::to_float(lvl) != 0.0F ? 5 : 0;
lvl != osr::kNoLevel && lvl.to_float() != 0.0F ? 5 : 0;
auto const way_bonus = osr::is_way(pl.platform_ref_[x].front()) ? 20 : 0;
auto const routes_bonus = get_routes_bonus(tt, l, pl.platform_names_[x]);
auto const score =
Expand Down
2 changes: 1 addition & 1 deletion src/parse_location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::optional<osr::location> parse_location(std::string_view s,
return std::nullopt;
}

return osr::location{pos, osr::to_level(level)};
return osr::location{pos, osr::level_t{level}};
}

n::unixtime_t get_date_time(std::optional<std::string> const& date,
Expand Down
6 changes: 3 additions & 3 deletions src/place.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ api::Place to_place(osr::location const l, std::string_view name) {
.name_ = std::string{name},
.lat_ = l.pos_.lat_,
.lon_ = l.pos_.lng_,
.level_ = to_float(l.lvl_),
.level_ = l.lvl_.to_float(),
.vertexType_ = api::VertexTypeEnum::NORMAL,
};
}
Expand All @@ -42,11 +42,11 @@ double get_level(osr::ways const* w,
osr::platforms const* pl,
platform_matches_t const* matches,
n::location_idx_t const l) {
return to_float(get_lvl(w, pl, matches, l));
return get_lvl(w, pl, matches, l).to_float();
}

osr::location get_location(api::Place const& p) {
return {{p.lat_, p.lon_}, osr::to_level(static_cast<float>(p.level_))};
return {{p.lat_, p.lon_}, osr::level_t{static_cast<float>(p.level_)}};
}

osr::location get_location(n::timetable const* tt,
Expand Down
6 changes: 4 additions & 2 deletions src/street_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ std::vector<api::StepInstruction> get_step_instructions(
.relativeDirection_ = api::RelativeDirectionEnum::CONTINUE, // TODO
.absoluteDirection_ = api::AbsoluteDirectionEnum::NORTH, // TODO
.distance_ = static_cast<double>(s.dist_),
.fromLevel_ = to_float(s.from_level_),
.toLevel_ = to_float(s.to_level_),
.fromLevel_ = s.from_level_.to_float(),
.toLevel_ = s.to_level_.to_float(),
.osmWay_ = s.way_ == osr::way_idx_t ::invalid()
? std::nullopt
: std::optional{static_cast<std::int64_t>(
Expand Down Expand Up @@ -205,6 +205,8 @@ api::Itinerary route(osr::ways const& w,
return {};
}

std::cout << "ROUTING\n FROM: " << from << " \n TO: " << to
<< "\n -> CREATING DUMMY LEG\n";
auto itinerary = api::Itinerary{
.duration_ = std::chrono::duration_cast<std::chrono::seconds>(
*end_time - start_time)
Expand Down
4 changes: 2 additions & 2 deletions test/read_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ using namespace std::chrono_literals;
TEST(motis, parse_location_with_level) {
auto const parsed = parse_location("-123.1,44.2,-1.5");
ASSERT_TRUE(parsed.has_value());
EXPECT_EQ((osr::location{{-123.1, 44.2}, osr::to_level(-1.5F)}), *parsed);
EXPECT_EQ((osr::location{{-123.1, 44.2}, osr::level_t{-1.5F}}), *parsed);
}

TEST(motis, parse_location_no_level) {
auto const parsed = parse_location("-23.1,45.2");
ASSERT_TRUE(parsed.has_value());
EXPECT_EQ((osr::location{{-23.1, 45.2}, osr::to_level(0.F)}), *parsed);
EXPECT_EQ((osr::location{{-23.1, 45.2}, osr::level_t{0.F}}), *parsed);
}

TEST(motis, parse_date_time) {
Expand Down
6 changes: 3 additions & 3 deletions test/routing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,12 @@ TEST(motis, routing) {
}

EXPECT_EQ(
R"(date=2019-05-01, start=01:29, end=02:29, duration=01:04, transfers=1, legs=[
R"(date=2019-05-01, start=01:29, end=02:28, duration=01:03, transfers=1, legs=[
(from=- [track=-, scheduled_track=-, level=0], to=test_DA_10 [track=10, scheduled_track=10, level=-1], start=2019-05-01 01:29, mode="WALK", trip="-", end=2019-05-01 01:35),
(from=test_DA_10 [track=10, scheduled_track=10, level=-1], to=test_FFM_12 [track=12, scheduled_track=10, level=0], start=2019-05-01 01:35, mode="HIGHSPEED_RAIL", trip="ICE ", end=2019-05-01 01:55),
(from=test_FFM_12 [track=12, scheduled_track=10, level=0], to=test_FFM_101 [track=101, scheduled_track=101, level=-3], start=2019-05-01 01:55, mode="WALK", trip="-", end=2019-05-01 02:01),
(from=test_FFM_101 [track=101, scheduled_track=101, level=-3], to=test_FFM_HAUPT_S [track=-, scheduled_track=-, level=-3], start=2019-05-01 02:15, mode="METRO", trip="S3", end=2019-05-01 02:20),
(from=test_FFM_HAUPT_S [track=-, scheduled_track=-, level=-3], to=- [track=-, scheduled_track=-, level=0], start=2019-05-01 02:20, mode="WALK", trip="-", end=2019-05-01 02:29)
(from=test_FFM_HAUPT_S [track=-, scheduled_track=-, level=-3], to=- [track=-, scheduled_track=-, level=0], start=2019-05-01 02:20, mode="WALK", trip="-", end=2019-05-01 02:28)
])",
ss.str());
}
Expand All @@ -387,7 +387,7 @@ TEST(motis, routing) {

EXPECT_EQ(
R"(date=2019-05-01, start=01:25, end=02:14, duration=00:49, transfers=1, legs=[
(from=- [track=-, scheduled_track=-, level=0], to=test_DA_10 [track=10, scheduled_track=10, level=-1], start=2019-05-01 01:25, mode="WALK", trip="-", end=2019-05-01 01:28),
(from=- [track=-, scheduled_track=-, level=0], to=test_DA_10 [track=10, scheduled_track=10, level=-1], start=2019-05-01 01:25, mode="WALK", trip="-", end=2019-05-01 01:30),
(from=test_DA_10 [track=10, scheduled_track=10, level=-1], to=test_FFM_12 [track=12, scheduled_track=10, level=0], start=2019-05-01 01:35, mode="HIGHSPEED_RAIL", trip="ICE ", end=2019-05-01 01:55),
(from=test_FFM_12 [track=12, scheduled_track=10, level=0], to=test_de:6412:10:6:1 [track=U4, scheduled_track=U4, level=-2], start=2019-05-01 01:55, mode="WALK", trip="-", end=2019-05-01 01:59),
(from=test_de:6412:10:6:1 [track=U4, scheduled_track=U4, level=-2], to=test_FFM_HAUPT_U [track=-, scheduled_track=-, level=-4], start=2019-05-01 02:05, mode="SUBWAY", trip="U4", end=2019-05-01 02:10),
Expand Down