Skip to content

Commit

Permalink
removed duplicates; updated storage
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenhagelgans committed Sep 14, 2023
1 parent bd27ced commit c0af24c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 39 deletions.
9 changes: 5 additions & 4 deletions modules/transfers/include/motis/transfers/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ struct storage {
: tt_(tt), db_{db_file_path, db_max_size} {}

// Initializes the storage for the footpath module.
void initialize(set<profile_key_t> const&,
hash_map<profile_key_t, ppr::profile_info> const&);
// Prerequisites:
// - used_profiles_ must already be set.
void initialize();

// Saves the current timetable in the specified file path.
void save_tt(std::filesystem::path const&) const;
Expand Down Expand Up @@ -94,6 +95,8 @@ struct storage {

hash_map<string, profile_key_t> profile_name_to_profile_key_;
hash_map<profile_key_t, string> profile_key_to_profile_name_;
hash_map<profile_key_t, ppr::profile_info> profile_key_to_profile_info_;
set<profile_key_t> used_profiles_;

private:
// Loads all transfers data from the database and stores it in the
Expand Down Expand Up @@ -128,8 +131,6 @@ struct storage {
transfer_results transfer_results_;
} old_state_, update_state_;

set<profile_key_t> used_profiles_;
hash_map<profile_key_t, ppr::profile_info> profile_key_to_profile_info_;
database db_;
};

Expand Down
9 changes: 1 addition & 8 deletions modules/transfers/src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ namespace fs = std::filesystem;

namespace motis::transfers {

void storage::initialize(set<profile_key_t> const& used_profiles,
hash_map<profile_key_t, ppr::profile_info> const&
profile_key_to_profile_info) {
used_profiles_ = used_profiles;
load_old_state_from_db(used_profiles_);
profile_key_to_profile_info_.insert(profile_key_to_profile_info.begin(),
profile_key_to_profile_info.end());
}
void storage::initialize() { load_old_state_from_db(used_profiles_); }

void storage::save_tt(fs::path const& save_to) const { tt_.write(save_to); }

Expand Down
41 changes: 14 additions & 27 deletions modules/transfers/src/transfers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct transfers::impl {
fs::path const& db_file_path, std::size_t db_max_size)
: storage_{db_file_path, db_max_size, tt} {
load_ppr_profiles(ppr_profiles);
storage_.initialize(used_profiles_, ppr_profiles_);
storage_.initialize();
};

void full_import() {
Expand Down Expand Up @@ -102,13 +102,16 @@ struct transfers::impl {
break;
}
rg = get_routing_ready_ppr_graph();
// route "new" transfer requests
route_and_save_results(rg, storage_.get_transfer_requests_keys(
data_request_type::kPartialUpdate));
break;
case routing_type::kFullRouting:
rg = get_routing_ready_ppr_graph();
route_and_update_results(rg, storage_.get_transfer_requests_keys(
data_request_type::kPartialOld));
// reroute "old" transfer requests
route_and_save_results(rg, storage_.get_transfer_requests_keys(
data_request_type::kPartialOld));
// route "new" transfer requests
route_and_save_results(rg, storage_.get_transfer_requests_keys(
data_request_type::kPartialUpdate));
break;
Expand Down Expand Up @@ -139,12 +142,14 @@ struct transfers::impl {

for (auto& [pname, pinfo] : ppr_profiles_by_name) {
auto pkey = storage_.profile_name_to_profile_key_.at(pname);
used_profiles_.insert(pkey);
storage_.used_profiles_.insert(pkey);

// convert walk_duration from minutes to seconds
ppr_profiles_.insert(std::pair<profile_key_t, ppr::profile_info>(
pkey, ppr_profiles_by_name.at(pname)));
ppr_profiles_.at(pkey).profile_.duration_limit_ = ::motis::MAX_WALK_TIME;
storage_.profile_key_to_profile_info_.insert(
std::pair<profile_key_t, ppr::profile_info>(
pkey, ppr_profiles_by_name.at(pname)));
storage_.profile_key_to_profile_info_.at(pkey).profile_.duration_limit_ =
::motis::MAX_WALK_TIME;

// build profile_name to idx map in nigiri::tt
storage_.tt_.profiles_.insert({pname, storage_.tt_.profiles_.size()});
Expand Down Expand Up @@ -247,31 +252,13 @@ struct transfers::impl {
auto matches = storage_.get_all_matchings();

auto treqs = to_transfer_requests(treqs_k, matches);
auto trs = route_multiple_requests(treqs, rg, ppr_profiles_);
storage_.add_new_transfer_results(trs);
}

// TODO (CARSTEN) route_and_update equals route_and_save
void route_and_update_results(::ppr::routing_graph const& rg,
transfer_requests_keys const& treqs_k) {
progress_tracker_->status("Updating Profilebased Transfers.");
ml::scoped_timer const timer{"Updating Profilebased Transfers."};

auto matches = storage_.get_all_matchings();

auto treqs = to_transfer_requests(treqs_k, matches);
auto trs = route_multiple_requests(treqs, rg, ppr_profiles_);
auto trs = route_multiple_requests(treqs, rg,
storage_.profile_key_to_profile_info_);
storage_.add_new_transfer_results(trs);
}

storage storage_;

hash_map<nlocation_key_t, n::location_idx_t> location_key_to_idx_;

hash_map<string, profile_key_t> ppr_profile_keys_;
hash_map<profile_key_t, ppr::profile_info> ppr_profiles_;
set<profile_key_t> used_profiles_;

// initialize matching limits
double max_matching_dist_{400};
double max_bus_stop_matching_dist_{120};
Expand Down

0 comments on commit c0af24c

Please sign in to comment.