Skip to content

Commit

Permalink
nigiri: fix bugs in trip_to_connection and dep/arr tables (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling authored Jul 15, 2023
1 parent 6de8a56 commit fbdb131
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[cista]
[email protected]:felixguendling/cista.git
branch=master
commit=05ba0e6c74195bb7921e178e9f7d850407172772
commit=04f84b0490e0e91ead20ae6eabed5add8f243ba0
[conf]
[email protected]:motis-project/conf.git
branch=master
Expand Down Expand Up @@ -97,7 +97,7 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=374d03910c9e77a8db7ebb765bd097ff72df918b
commit=89f9409ffc1dcf85986cab8e6bf06679e50a41fd
[osmium]
[email protected]:motis-project/libosmium.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 @@
9967080728064150615
cista 05ba0e6c74195bb7921e178e9f7d850407172772
867181114681065305
cista 04f84b0490e0e91ead20ae6eabed5add8f243ba0
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost be5235eb2258d2ec19e32546ab767a62311d9b46
cereal 5afa46f98d1c22627777c3f9d048fffe3f9763dc
Expand Down Expand Up @@ -28,7 +28,7 @@ net 44674d2f3917e20b7019a0f7254d332522c36fb7
protobuf e4d1f574ea9793308da9a942b4d5c1d4628aaed6
unordered_dense 4f380fb1d64f1843ca2c993ed39a8342a8747e5d
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri 374d03910c9e77a8db7ebb765bd097ff72df918b
nigiri 89f9409ffc1dcf85986cab8e6bf06679e50a41fd
lua 7bb93325b26f84c7e8b51fcbd857361ce7605a1d
luabind 9223568bbcf818ecfb1001d49f567627ee10852a
tbb 2067af88257710d07253761655a802732a32496e
Expand Down
55 changes: 32 additions & 23 deletions modules/nigiri/src/get_station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ struct static_ev_iterator : public ev_iterator {
n::direction const dir)
: tt_{tt},
rtt_{rtt},
day_{tt_.day_idx_mam(start).first},
end_{tt.day_idx(tt.date_range_.to_)},
i_{0},
day_{to_idx(tt_.day_idx_mam(start).first)},
end_day_{dir == n::direction::kForward
? to_idx(tt.day_idx(tt.date_range_.to_))
: -1},
size_{static_cast<std::int32_t>(
to_idx(tt.route_transport_ranges_[r].size()))},
i_{dir == n::direction::kForward ? 0 : size_ - 1},
r_{r},
stop_idx_{stop_idx},
ev_type_{ev_type},
Expand Down Expand Up @@ -99,19 +101,19 @@ struct static_ev_iterator : public ev_iterator {
}
}

bool finished() const override {
return dir_ == n::direction::kForward ? day_ == end_ : day_ == -1;
}
bool finished() const override { return day_ == end_day_; }

n::unixtime_t time() const override {
return tt_.event_time(
n::transport{tt_.route_transport_ranges_[r_][i_], day_}, stop_idx_,
ev_type_);
n::transport{tt_.route_transport_ranges_[r_][i_], n::day_idx_t{day_}},
stop_idx_, ev_type_);
}

n::rt::run get() const override {
assert(is_active());
return n::rt::run{
.t_ = n::transport{tt_.route_transport_ranges_[r_][i_], day_},
.t_ = n::transport{tt_.route_transport_ranges_[r_][i_],
n::day_idx_t{day_}},
.stop_range_ = {stop_idx_, static_cast<n::stop_idx_t>(stop_idx_ + 1U)}};
}

Expand All @@ -131,14 +133,14 @@ struct static_ev_iterator : public ev_iterator {

n::transport t() const {
auto const t = tt_.route_transport_ranges_[r_][i_];
auto const day_offset = tt_.event_mam(r_, t, stop_idx_, ev_type_).days_;
return n::transport{tt_.route_transport_ranges_[r_][i_], day_ - day_offset};
auto const day_offset = tt_.event_mam(r_, t, stop_idx_, ev_type_).days();
return n::transport{tt_.route_transport_ranges_[r_][i_],
n::day_idx_t{day_ - day_offset}};
}

n::timetable const& tt_;
n::rt_timetable const* rtt_;
n::day_idx_t day_, end_;
std::int32_t i_, size_;
std::int32_t day_, end_day_, size_, i_;
n::route_idx_t r_;
n::stop_idx_t stop_idx_;
n::event_type ev_type_;
Expand Down Expand Up @@ -191,9 +193,12 @@ std::vector<n::rt::run> get_events(
if (rtt != nullptr) {
for (auto const x : locations) {
for (auto const rt_t : rtt->location_rt_transports_[x]) {
for (auto const [stop_idx, s] :
utl::enumerate(rtt->rt_transport_location_seq_[rt_t])) {
if (n::stop{s}.location_idx() == x) {
auto const location_seq = rtt->rt_transport_location_seq_[rt_t];
for (auto const [stop_idx, s] : utl::enumerate(location_seq)) {
if (n::stop{s}.location_idx() == x &&
((ev_type == n::event_type::kDep &&
stop_idx != location_seq.size() - 1U) ||
(ev_type == n::event_type::kArr && stop_idx != 0U))) {
iterators.emplace_back(std::make_unique<rt_ev_iterator>(
*rtt, rt_t, static_cast<n::stop_idx_t>(stop_idx), time, ev_type,
dir));
Expand All @@ -206,9 +211,12 @@ std::vector<n::rt::run> get_events(
auto seen = n::hash_set<std::pair<n::route_idx_t, n::stop_idx_t>>{};
for (auto const x : locations) {
for (auto const r : tt.location_routes_[x]) {
for (auto const [stop_idx, s] :
utl::enumerate(tt.route_location_seq_[r])) {
auto const location_seq = tt.route_location_seq_[r];
for (auto const [stop_idx, s] : utl::enumerate(location_seq)) {
if (n::stop{s}.location_idx() == x &&
((ev_type == n::event_type::kDep &&
stop_idx != location_seq.size() - 1U) ||
(ev_type == n::event_type::kArr && stop_idx != 0U)) &&
seen.emplace(r, stop_idx).second) {
iterators.emplace_back(std::make_unique<static_ev_iterator>(
tt, rtt, r, stop_idx, time, ev_type, dir));
Expand Down Expand Up @@ -273,13 +281,14 @@ mm::msg_ptr get_station(tag_lookup const& tags, n::timetable const& tt,
fbb,
fbb.CreateVector(std::vector{CreateTripInfo(
fbb,
to_fbs(fbb, nigiri_trip_to_extern_trip(tags, tt, fr.trip_idx(),
fr.t_.day_)),
to_fbs(fbb, nigiri_trip_to_extern_trip(
tags, tt, fr[0].get_trip_idx(ev_type), fr.t_.day_)),
CreateTransport(
fbb, &range, static_cast<std::uint32_t>(fr[0].get_clasz()),
fbb.CreateString(fr[0].line()), fbb.CreateString(fr.name()),
fbb.CreateString(fr[0].get_provider().long_name_),
fbb.CreateString(fr[0].direction())))}),
fbb.CreateString(fr[0].line(ev_type)),
fbb.CreateString(fr.name()),
fbb.CreateString(fr[0].get_provider(ev_type).long_name_),
fbb.CreateString(fr[0].direction(ev_type))))}),
ev_type == n::event_type::kDep ? EventType_DEP : EventType_ARR,
CreateEventInfo(
fbb, to_motis_unixtime(fr[0].time(ev_type)),
Expand Down
13 changes: 11 additions & 2 deletions modules/nigiri/src/resolve_run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ n::rt::run resolve_run(tag_lookup const& tags, n::timetable const& tt,
for (auto i = lb; i != end(tt.trip_id_to_idx_) && id_matches(i->first); ++i) {
for (auto const [t_idx, stop_range] :
tt.trip_transport_ranges_[i->second]) {
auto const t = n::transport{t_idx, day_idx};
auto const day_offset =
tt.event_mam(t_idx, stop_range.from_, n::event_type::kDep).days();
auto const t = n::transport{t_idx, day_idx - day_offset};
if (dep_time != tt.event_time(t, stop_range.from_, n::event_type::kDep)) {
std::cout << "dep time no match: " << dep_time << ", "
<< tt.event_time(t, stop_range.from_, n::event_type::kDep)
<< "\n";
continue;
}

auto const& traffic_days =
tt.bitfields_[tt.transport_traffic_days_[t_idx]];
if (!traffic_days.test(to_idx(day_idx))) {
if (!traffic_days.test(to_idx(day_idx - day_offset))) {
std::cout << "traffic day not active: "
<< tt.internal_interval_days().from_ +
to_idx(day_idx) * date::days{1}
<< "\n";
continue;
}

Expand Down

0 comments on commit fbdb131

Please sign in to comment.