Skip to content

Commit

Permalink
Fix stairs lvl, change fastest direct, ELEVATORS, STAIRS step descrip…
Browse files Browse the repository at this point in the history
…tion (#640)

* use fastest direct to filter offsets, add debug output

* fix stair level changes, add ELEVATOR and STAIRS output

* wip

* wip

* wip

* wip
  • Loading branch information
felixguendling authored Nov 3, 2024
1 parent 2291c01 commit b1b7ed7
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .pkg
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=a983abd836d83116d35e2f2ff7d4073b90784f2a
commit=fe8663ead336cb0bb98b0d6a9a9ff7032985781b
[cista]
[email protected]:felixguendling/cista.git
branch=master
commit=5b6808fd7d7a7c1c7e4cb152b563dbf71e3efba4
[osr]
[email protected]:motis-project/osr.git
branch=master
commit=02c6782ecb882a8beab6396608c6a5a279db3cbc
commit=06ddcbb6ca05a9636373f015c2c852a11874bc79
[utl]
[email protected]:motis-project/utl.git
branch=master
commit=9a6f1ef3ef8f5e764ce87ec446141c64ee6dcd73
commit=f76f70812be09d88b260e398ddd43fc7345f9fb9
[adr]
[email protected]:triptix-tech/adr.git
branch=master
Expand All @@ -29,7 +29,7 @@
[openapi-cpp]
[email protected]:triptix-tech/openapi-cpp.git
branch=master
commit=7c760e7c7ea7b6ffdda1befbf4fea96a786c7531
commit=6b5fd40a2b552fc5656aeff56f203a34c1d9e9af
[unordered_dense]
[email protected]:motis-project/unordered_dense.git
branch=master
Expand Down
10 changes: 5 additions & 5 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
6189593023066036854
521520066768043934
cista 5b6808fd7d7a7c1c7e4cb152b563dbf71e3efba4
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 73549ebca677fe6214202a1ab580362b4f80e653
googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c
libressl 24acd9e710fbe842e863572da9d738715fbc74b8
fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2
utl 8bfa7fc4edc23f716173bdfbcab8294fcc31e457
utl f76f70812be09d88b260e398ddd43fc7345f9fb9
net 7b089e022471bb5adf716d0c7b0cdb57a23c7adc
PEGTL 1c1aa6e650e4d26f10fa398f148ec0cdc5f0808d
res b759b93316afeb529b6cb5b2548b24c41e382fb0
Expand All @@ -23,7 +23,7 @@ opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414
pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50
unordered_dense b33b037377ca966bbdd9cccc3417e46e88f83bfb
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri a983abd836d83116d35e2f2ff7d4073b90784f2a
nigiri fe8663ead336cb0bb98b0d6a9a9ff7032985781b
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
Expand All @@ -39,11 +39,11 @@ sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles 6b6dc45bc904966640c7207ab91950848a8b3f6c
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
osr 02c6782ecb882a8beab6396608c6a5a279db3cbc
osr 06ddcbb6ca05a9636373f015c2c852a11874bc79
yaml-cpp 1d8ca1f35eb3a9c9142462b28282a848e5d29a91
reflect-cpp c54fe66de4650b60c23aadd4a06d9db4ffeda22f
FTXUI dd6a5d371fd7a3e2937bb579955003c54b727233
tg 20c0f298b8ce58de29a790290f44dca7c4ecc364
utf8proc 779b780da3b99d123133eb99707b65c7e4324cc8
adr b54517837bdf6d5ac4967858c2c4011f29e5789f
openapi-cpp 7c760e7c7ea7b6ffdda1befbf4fea96a786c7531
openapi-cpp 6b5fd40a2b552fc5656aeff56f203a34c1d9e9af
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", 5U};
return meta_entry_t{"osr_bin_ver", 6U};
};
constexpr auto const adr_version = []() {
return meta_entry_t{"adr_bin_ver", 1U};
Expand Down
22 changes: 4 additions & 18 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ paths:
description: "debug statistics"
type: object
additionalProperties:
type: string
type: integer
from:
$ref: '#/components/schemas/Place'
to:
Expand Down Expand Up @@ -1045,7 +1045,7 @@ components:
description: Google polyline encoded coordinate sequence (with precision 7) where the trip travels on this segment.
type: string

RelativeDirection:
Direction:
type: string
enum:
- DEPART
Expand All @@ -1058,22 +1058,11 @@ components:
- HARD_RIGHT
- CIRCLE_CLOCKWISE
- CIRCLE_COUNTERCLOCKWISE
- STAIRS
- ELEVATOR
- UTURN_LEFT
- UTURN_RIGHT

AbsoluteDirection:
type: string
enum:
- NORTH
- NORTHEAST
- EAST
- SOUTHEAST
- SOUTH
- SOUTHWEST
- WEST
- NORTHWEST

EncodedPolyline:
type: object
required:
Expand All @@ -1094,7 +1083,6 @@ components:
- toLevel
- polyline
- relativeDirection
- absoluteDirection
- distance
- streetName
- exit
Expand All @@ -1104,9 +1092,7 @@ components:
- lat
properties:
relativeDirection:
$ref: '#/components/schemas/RelativeDirection'
absoluteDirection:
$ref: '#/components/schemas/AbsoluteDirection'
$ref: '#/components/schemas/Direction'
distance:
description: The distance in meters that this step takes.
type: number
Expand Down
54 changes: 54 additions & 0 deletions src/endpoints/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,58 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
return {itineraries, fastest_direct};
}

std::map<std::string, std::uint64_t> join(auto&&... maps) {
auto ret = std::map<std::string, std::uint64_t>{};
auto const add = [&](std::map<std::string, std::uint64_t> const& x) {
ret.insert(begin(x), end(x));
};
(add(maps), ...);
return ret;
}

void remove_slower_than_fastest_direct(n::routing::query& q) {
if (!q.fastest_direct_) {
return;
}

constexpr auto const kMaxDuration =
n::duration_t{std::numeric_limits<n::duration_t>::max()};

auto const worse_than_fastest_direct = [&](n::duration_t const min) {
return [&, min](auto const& o) {
return o.duration() + min >= q.fastest_direct_;
};
};
auto const get_min_duration = [&](auto&& x) {
return x.empty() ? kMaxDuration
: utl::max_element(x, [](auto&& a, auto&& b) {
return a.duration() < b.duration();
})->duration();
};

auto min_start = get_min_duration(q.start_);
for (auto const& [_, v] : q.td_start_) {
min_start = std::min(min_start, get_min_duration(v));
}

auto min_dest = get_min_duration(q.destination_);
for (auto const& [_, v] : q.td_dest_) {
min_dest = std::min(min_dest, get_min_duration(v));
}

utl::verify(min_start != kMaxDuration, "no valid start offset");
utl::verify(min_dest != kMaxDuration, "no valid dest offset");

utl::erase_if(q.start_, worse_than_fastest_direct(min_dest));
utl::erase_if(q.destination_, worse_than_fastest_direct(min_start));
for (auto& [k, v] : q.td_start_) {
utl::erase_if(v, worse_than_fastest_direct(min_dest));
}
for (auto& [k, v] : q.td_dest_) {
utl::erase_if(v, worse_than_fastest_direct(min_start));
}
}

api::plan_response routing::operator()(boost::urls::url_view const& url) const {
auto const rt = rt_;
auto const rtt = rt->rtt_.get();
Expand Down Expand Up @@ -464,6 +516,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
.fastest_direct_ = fastest_direct == kInfinityDuration
? std::nullopt
: std::optional{fastest_direct}};
remove_slower_than_fastest_direct(q);

if (tt_->locations_.footpaths_out_.at(q.prf_idx_).empty()) {
q.prf_idx_ = 0U;
Expand All @@ -482,6 +535,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
std::nullopt);

return {
.debugOutput_ = join(r.search_stats_.to_map(), r.algo_stats_.to_map()),
.from_ = from_p,
.to_ = to_p,
.direct_ = std::move(direct),
Expand Down
2 changes: 2 additions & 0 deletions src/journey_to_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ api::Itinerary journey_to_response(osr::ways const* w,
place_t const& dest,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem) {
utl::verify(!j.legs_.empty(), "journey without legs");

auto itinerary = api::Itinerary{
.duration_ = to_seconds(j.arrival_time() - j.departure_time()),
.startTime_ = j.legs_.front().dep_time_,
Expand Down
50 changes: 42 additions & 8 deletions src/street_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,34 @@ std::optional<osr::path> get_path(osr::ways const& w,
}

std::vector<api::StepInstruction> get_step_instructions(
osr::ways const& w, std::span<osr::path::segment const> segments) {
return utl::to_vec(segments, [&](osr::path::segment const& s) {
osr::ways const& w,
osr::location const& from,
osr::location const& to,
std::span<osr::path::segment const> segments) {
auto steps = std::vector<api::StepInstruction>{};
auto pred_lvl = from.lvl_.to_float();
for (auto const& s : segments) {
if (s.from_ != osr::node_idx_t::invalid() &&
w.r_->node_properties_[s.from_].is_elevator()) {
steps.push_back(api::StepInstruction{
.relativeDirection_ = api::DirectionEnum::ELEVATOR,
.fromLevel_ = pred_lvl,
.toLevel_ = s.from_level_.to_float()});
}

auto const way_name = s.way_ == osr::way_idx_t::invalid()
? osr::string_idx_t::invalid()
: w.way_names_[s.way_];
return api::StepInstruction{
.relativeDirection_ = api::RelativeDirectionEnum::CONTINUE, // TODO
.absoluteDirection_ = api::AbsoluteDirectionEnum::NORTH, // TODO
auto const props = s.way_ != osr::way_idx_t::invalid()
? w.r_->way_properties_[s.way_]
: osr::way_properties{};
steps.push_back(api::StepInstruction{
.relativeDirection_ =
s.way_ != osr::way_idx_t::invalid()
? (props.is_elevator() ? api::DirectionEnum::ELEVATOR
: props.is_steps() ? api::DirectionEnum::STAIRS
: api::DirectionEnum::CONTINUE)
: api::DirectionEnum::CONTINUE, // TODO entry/exit/u-turn
.distance_ = static_cast<double>(s.dist_),
.fromLevel_ = s.from_level_.to_float(),
.toLevel_ = s.to_level_.to_float(),
Expand All @@ -78,8 +98,21 @@ std::vector<api::StepInstruction> get_step_instructions(
.exit_ = {}, // TODO
.stayOn_ = false, // TODO
.area_ = false // TODO
};
});
});
}

if (!segments.empty()) {
auto& last = segments.back();
if (last.to_ != osr::node_idx_t::invalid() &&
w.r_->node_properties_[last.to_].is_elevator()) {
steps.push_back(api::StepInstruction{
.relativeDirection_ = api::DirectionEnum::ELEVATOR,
.fromLevel_ = pred_lvl,
.toLevel_ = to.lvl_.to_float()});
}
}

return steps;
}

struct sharing {
Expand Down Expand Up @@ -289,7 +322,8 @@ api::Itinerary route(osr::ways const& w,
.endTime_ = is_last_leg && end_time ? *end_time : t,
.distance_ = dist,
.legGeometry_ = to_polyline<7>(concat),
.steps_ = get_step_instructions(w, range),
.steps_ = get_step_instructions(w, get_location(from),
get_location(to), range),
.rental_ = is_rental ? std::optional{sharing_data->get_rental(
range.back().to_)}
: std::nullopt});
Expand Down
2 changes: 1 addition & 1 deletion test/routing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:30),
(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=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

0 comments on commit b1b7ed7

Please sign in to comment.