From ddff9b612f32136d231cfe33647fd9ab43b36d21 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Sat, 8 Aug 2015 15:28:05 +0200 Subject: [PATCH] Serialize out .core file containing core node markers --- contractor/contractor.hpp | 16 ++++++++++++++++ contractor/contractor_options.cpp | 1 + contractor/contractor_options.hpp | 1 + contractor/processing_chain.cpp | 21 +++++++++++++++++++-- contractor/processing_chain.hpp | 4 +++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/contractor/contractor.hpp b/contractor/contractor.hpp index dfdc0c2be..a2d7941ee 100644 --- a/contractor/contractor.hpp +++ b/contractor/contractor.hpp @@ -306,6 +306,7 @@ class Contractor std::vector remaining_nodes(number_of_nodes); std::vector node_priorities(number_of_nodes); std::vector node_data(number_of_nodes); + is_core_node.resize(number_of_nodes, false); // initialize priorities in parallel tbb::parallel_for(tbb::blocked_range(0, number_of_nodes, InitGrainSize), @@ -546,11 +547,25 @@ class Contractor p.printStatus(number_of_contracted_nodes); } + if (remaining_nodes.size() > 2) + { + for (const auto& node : remaining_nodes) + { + auto orig_id = orig_node_id_from_new_node_id_map[node.id]; + is_core_node[orig_id] = true; + } + } + SimpleLogger().Write() << "[core] " << remaining_nodes.size() << " nodes " << contractor_graph->GetNumberOfEdges() << " edges." << std::endl; thread_data_list.data.clear(); } + inline void GetCoreMarker(std::vector &out_is_core_node) + { + out_is_core_node.swap(is_core_node); + } + template inline void GetEdges(DeallocatingVector &edges) { Percent p(contractor_graph->GetNumberOfNodes()); @@ -960,6 +975,7 @@ class Contractor std::shared_ptr contractor_graph; stxxl::vector external_edge_list; std::vector orig_node_id_from_new_node_id_map; + std::vector is_core_node; XORFastHash fast_hash; }; diff --git a/contractor/contractor_options.cpp b/contractor/contractor_options.cpp index cd304bc3c..f0d434a91 100644 --- a/contractor/contractor_options.cpp +++ b/contractor/contractor_options.cpp @@ -131,6 +131,7 @@ ContractorOptions::ParseArguments(int argc, char *argv[], ContractorConfig &cont void ContractorOptions::GenerateOutputFilesNames(ContractorConfig &contractor_config) { contractor_config.node_output_path = contractor_config.osrm_input_path.string() + ".nodes"; + contractor_config.core_output_path = contractor_config.osrm_input_path.string() + ".core"; contractor_config.edge_output_path = contractor_config.osrm_input_path.string() + ".edges"; contractor_config.geometry_output_path = contractor_config.osrm_input_path.string() + ".geometry"; contractor_config.graph_output_path = contractor_config.osrm_input_path.string() + ".hsgr"; diff --git a/contractor/contractor_options.hpp b/contractor/contractor_options.hpp index 248659527..3836627d5 100644 --- a/contractor/contractor_options.hpp +++ b/contractor/contractor_options.hpp @@ -49,6 +49,7 @@ struct ContractorConfig boost::filesystem::path profile_path; std::string node_output_path; + std::string core_output_path; std::string edge_output_path; std::string geometry_output_path; std::string graph_output_path; diff --git a/contractor/processing_chain.cpp b/contractor/processing_chain.cpp index 77e13b089..c205ac793 100644 --- a/contractor/processing_chain.cpp +++ b/contractor/processing_chain.cpp @@ -106,8 +106,9 @@ int Prepare::Run() // Contracting the edge-expanded graph TIMER_START(contraction); + std::vector is_core_node; auto contracted_edge_list = osrm::make_unique>(); - ContractGraph(max_edge_id, edge_based_edge_list, *contracted_edge_list); + ContractGraph(max_edge_id, edge_based_edge_list, *contracted_edge_list, is_core_node); TIMER_STOP(contraction); SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec"; @@ -115,6 +116,7 @@ int Prepare::Run() std::size_t number_of_used_edges = WriteContractedGraph(max_edge_id, std::move(node_based_edge_list), std::move(contracted_edge_list)); + WriteCoreNodeMarker(std::move(is_core_node)); TIMER_STOP(preparing); @@ -202,6 +204,19 @@ void Prepare::FindComponents(unsigned max_edge_id, const DeallocatingVector&& in_is_core_node) const +{ + std::vector is_core_node(in_is_core_node); + std::vector unpacked_bool_flags(is_core_node.size()); + for (auto i = 0u; i < is_core_node.size(); ++i) + { + unpacked_bool_flags[i] = is_core_node[i] ? 1 : 0; + } + + boost::filesystem::ofstream core_marker_output_stream(config.core_output_path, std::ios::binary); + core_marker_output_stream.write((char *)unpacked_bool_flags.data(), sizeof(char)*unpacked_bool_flags.size()); +} + std::size_t Prepare::WriteContractedGraph(unsigned max_node_id, std::unique_ptr> node_based_edge_list, std::unique_ptr> contracted_edge_list) @@ -482,11 +497,13 @@ Prepare::BuildEdgeExpandedGraph(std::vector &internal_to_external_nod */ void Prepare::ContractGraph(const unsigned max_edge_id, DeallocatingVector& edge_based_edge_list, - DeallocatingVector& contracted_edge_list) + DeallocatingVector& contracted_edge_list, + std::vector& is_core_node) { Contractor contractor(max_edge_id + 1, edge_based_edge_list); contractor.Run(config.core_factor); contractor.GetEdges(contracted_edge_list); + contractor.GetCoreMarker(is_core_node); } /** diff --git a/contractor/processing_chain.hpp b/contractor/processing_chain.hpp index 33dbe917d..63560ebf9 100644 --- a/contractor/processing_chain.hpp +++ b/contractor/processing_chain.hpp @@ -63,7 +63,9 @@ class Prepare unsigned CalculateEdgeChecksum(std::unique_ptr> node_based_edge_list); void ContractGraph(const unsigned max_edge_id, DeallocatingVector& edge_based_edge_list, - DeallocatingVector& contracted_edge_list); + DeallocatingVector& contracted_edge_list, + std::vector& is_core_node); + void WriteCoreNodeMarker(std::vector&& is_core_node) const; std::size_t WriteContractedGraph(unsigned number_of_edge_based_nodes, std::unique_ptr> node_based_edge_list, std::unique_ptr> contracted_edge_list);