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

Dump round times #157

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion exe/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ void generate_queries(
std::cout << "--- Query generator settings ---\n" << gs << "\n--- --- ---\n";
queries.reserve(n_queries);
for (auto i = 0U; i != n_queries; ++i) {
auto const sdq = qg.random_query();
auto sdq = qg.random_query();
if (sdq.has_value()) {
sdq.value().q_.id_ = i;
queries.emplace_back(sdq.value());
}
}
Expand Down
3 changes: 0 additions & 3 deletions include/nigiri/common/delta_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

namespace nigiri {

using delta_t = std::int16_t;
static_assert(sizeof(delta_t) == 2);

template <direction SearchDir>
inline constexpr auto const kInvalidDelta =
SearchDir == direction::kForward ? std::numeric_limits<delta_t>::max()
Expand Down
31 changes: 31 additions & 0 deletions include/nigiri/routing/dump_round_times.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "nigiri/routing/raptor/raptor_state.h"
#include "nigiri/types.h"

// #define NIGIRI_DUMP_ROUND_TIMES_DIR "./round_times"
#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR
#define dump_round_times(dbg_dir, tag, state, k, Vias) \
dump_round_times_fun<Vias>(dbg_dir, tag, state, k)

namespace nigiri::routing {

template <via_offset_t Vias>
void dump_round_times_fun(std::optional<std::string> const& dbg_dir,
std::string_view tag,
raptor_state const& rs,
unsigned const k) {
if (dbg_dir) {
auto ostrm = std::ofstream{fmt::format("{}/k{}_{}.bin", *dbg_dir, k, tag),
std::ios::binary};
ostrm.write(reinterpret_cast<char const*>(
&rs.round_times_storage_[k * rs.n_locations_ * (Vias + 1)]),
rs.n_locations_ * (Vias + 1) * sizeof(delta_t));
}
}

} // namespace nigiri::routing

#else
#define dump_round_times(dbg_dir, tag, state, k, Vias)
#endif
1 change: 1 addition & 0 deletions include/nigiri/routing/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct query {
transfer_time_settings transfer_time_settings_{};
std::vector<via_stop> via_stops_{};
std::optional<duration_t> fastest_direct_{};
std::uint32_t id_{};
};

} // namespace nigiri::routing
13 changes: 13 additions & 0 deletions include/nigiri/routing/raptor/raptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "nigiri/common/delta_t.h"
#include "nigiri/common/linear_lower_bound.h"
#include "nigiri/routing/dump_round_times.h"
#include "nigiri/routing/journey.h"
#include "nigiri/routing/limits.h"
#include "nigiri/routing/pareto_set.h"
Expand Down Expand Up @@ -123,6 +124,8 @@ struct raptor {

algo_stats_t get_stats() const { return stats_; }

day_idx_t get_base() const { return base_; }

void reset_arrivals() {
utl::fill(time_at_dest_, kInvalid);
round_times_.reset(kInvalidArray);
Expand Down Expand Up @@ -160,6 +163,7 @@ struct raptor {
}

trace_print_init_state();
dump_round_times(dbg_dir_, "init", state_, 0U, Vias);

for (auto k = 1U; k != end_k; ++k) {
for (auto i = 0U; i != n_locations_; ++i) {
Expand Down Expand Up @@ -254,6 +258,10 @@ struct raptor {
reconstruct_journey<SearchDir>(tt_, rtt_, q, state_, j, base(), base_);
}

#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR
std::optional<std::string> dbg_dir_;
#endif

private:
date::sys_days base() const {
return tt_.internal_interval_days().from_ + as_int(base_) * date::days{1};
Expand Down Expand Up @@ -382,6 +390,7 @@ struct raptor {
}
}
});
dump_round_times(dbg_dir_, "1_update_transfers", state_, k, Vias);
}

void update_footpaths(unsigned const k, profile_idx_t const prf_idx) {
Expand Down Expand Up @@ -477,6 +486,7 @@ struct raptor {
}
}
});
dump_round_times(dbg_dir_, "3_update_footpaths", state_, k, Vias);
}

void update_td_offsets(unsigned const k, profile_idx_t const prf_idx) {
Expand Down Expand Up @@ -576,6 +586,7 @@ struct raptor {
});
}
});
dump_round_times(dbg_dir_, "4_update_td_offsets", state_, k, Vias);
}

void update_intermodal_footpaths(unsigned const k) {
Expand Down Expand Up @@ -628,6 +639,8 @@ struct raptor {
}
}
});
dump_round_times(dbg_dir_, "2_update_intermodal_footpaths", state_, k,
Vias);
}

template <bool WithSectionBikeFilter>
Expand Down
11 changes: 11 additions & 0 deletions include/nigiri/routing/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nigiri/get_otel_tracer.h"
#include "nigiri/logging.h"
#include "nigiri/routing/dijkstra.h"
#include "nigiri/routing/dump_round_times.h"
#include "nigiri/routing/get_fastest_direct.h"
#include "nigiri/routing/interval_estimate.h"
#include "nigiri/routing/journey.h"
Expand Down Expand Up @@ -404,6 +405,16 @@ struct search {
auto const worst_time_at_dest =
start_time +
(kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime);

#ifdef NIGIRI_DUMP_ROUND_TIMES_DIR
algo_.dbg_dir_ = fmt::format(
"{}/query_{}_[{}]/interval_{}_[{}]-[{}]/start_[{}]",
NIGIRI_DUMP_ROUND_TIMES_DIR, q_.id_,
tt_.to_unixtime(algo_.get_base()), stats_.interval_extensions_,
search_interval_.from_, search_interval_.to_, start_time);
std::filesystem::create_directories(*algo_.dbg_dir_);
#endif

algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest,
q_.prf_idx_, state_.results_);

Expand Down
2 changes: 2 additions & 0 deletions include/nigiri/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ using transport_mode_id_t = std::int32_t;

using via_offset_t = std::uint8_t;

using delta_t = std::int16_t;
static_assert(sizeof(delta_t) == 2);
} // namespace nigiri

#include <iomanip>
Expand Down
Loading