diff --git a/modules/transfers/include/motis/transfers/storage/storage.h b/modules/transfers/include/motis/transfers/storage/storage.h index cc8c9bb18..d06aff8e9 100644 --- a/modules/transfers/include/motis/transfers/storage/storage.h +++ b/modules/transfers/include/motis/transfers/storage/storage.h @@ -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 const&, - hash_map 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; @@ -94,6 +95,8 @@ struct storage { hash_map profile_name_to_profile_key_; hash_map profile_key_to_profile_name_; + hash_map profile_key_to_profile_info_; + set used_profiles_; private: // Loads all transfers data from the database and stores it in the @@ -128,8 +131,6 @@ struct storage { transfer_results transfer_results_; } old_state_, update_state_; - set used_profiles_; - hash_map profile_key_to_profile_info_; database db_; }; diff --git a/modules/transfers/src/storage/storage.cc b/modules/transfers/src/storage/storage.cc index b4790de1e..624335592 100644 --- a/modules/transfers/src/storage/storage.cc +++ b/modules/transfers/src/storage/storage.cc @@ -16,14 +16,7 @@ namespace fs = std::filesystem; namespace motis::transfers { -void storage::initialize(set const& used_profiles, - hash_map 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); } diff --git a/modules/transfers/src/transfers.cc b/modules/transfers/src/transfers.cc index 3bd39468d..c15ce1af7 100644 --- a/modules/transfers/src/transfers.cc +++ b/modules/transfers/src/transfers.cc @@ -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() { @@ -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; @@ -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( - 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( + 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()}); @@ -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 location_key_to_idx_; - - hash_map ppr_profile_keys_; - hash_map ppr_profiles_; - set used_profiles_; - // initialize matching limits double max_matching_dist_{400}; double max_bus_stop_matching_dist_{120};