diff --git a/Contractor/Prepare.cpp b/Contractor/Prepare.cpp index eee1124b1..e12a61b42 100644 --- a/Contractor/Prepare.cpp +++ b/Contractor/Prepare.cpp @@ -170,7 +170,10 @@ int Prepare::Process(int argc, char *argv[]) TIMER_STOP(expansion); - BuildRTree(node_based_edge_list); + StaticRTree::Build(node_based_edge_list, + rtree_nodes_path.c_str(), + rtree_leafs_path.c_str(), + internal_to_external_node_map); IteratorbasedCRC32> crc32; const unsigned node_based_edge_list_CRC32 = @@ -544,16 +547,3 @@ void Prepare::WriteNodeMapping() internal_to_external_node_map.shrink_to_fit(); } -/** - \brief Building rtree-based nearest-neighbor data structure - - Saves info to files: '.ramIndex' and '.fileIndex'. - */ -void Prepare::BuildRTree(std::vector &node_based_edge_list) -{ - SimpleLogger().Write() << "building r-tree ..."; - StaticRTree(node_based_edge_list, - rtree_nodes_path.c_str(), - rtree_leafs_path.c_str(), - internal_to_external_node_map); -} diff --git a/Contractor/Prepare.h b/Contractor/Prepare.h index 0a5c35985..6386a5227 100644 --- a/Contractor/Prepare.h +++ b/Contractor/Prepare.h @@ -40,7 +40,6 @@ class Prepare DeallocatingVector &edgeBasedEdgeList, EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile); void WriteNodeMapping(); - void BuildRTree(std::vector &node_based_edge_list); private: std::vector internal_to_external_node_map; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 4b5ed0f53..1cea86e84 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -307,24 +307,24 @@ class StaticRTree StaticRTree(const StaticRTree &) = delete; // Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1] - explicit StaticRTree(std::vector &input_data_vector, + static void Build(std::vector &input_data_vector, const std::string tree_node_filename, const std::string leaf_node_filename, const std::vector &coordinate_list) - : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) { - SimpleLogger().Write() << "constructing r-tree of " << m_element_count + uint64_t element_count = input_data_vector.size(); + SimpleLogger().Write() << "constructing r-tree of " << element_count << " edge elements build on-top of " << coordinate_list.size() << " coordinates"; TIMER_START(construction); - std::vector input_wrapper_vector(m_element_count); + std::vector input_wrapper_vector(element_count); HilbertCode get_hilbert_number; // generate auxiliary vector of hilbert-values tbb::parallel_for( - tbb::blocked_range(0, m_element_count), + tbb::blocked_range(0, element_count), [&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list]( const tbb::blocked_range &range) { @@ -351,7 +351,7 @@ class StaticRTree // open leaf file boost::filesystem::ofstream leaf_node_file(leaf_node_filename, std::ios::binary); - leaf_node_file.write((char *)&m_element_count, sizeof(uint64_t)); + leaf_node_file.write((char *) &element_count, sizeof(uint64_t)); // sort the hilbert-value representatives tbb::parallel_sort(input_wrapper_vector.begin(), input_wrapper_vector.end()); @@ -359,7 +359,7 @@ class StaticRTree // pack M elements into leaf node and write to leaf file uint64_t processed_objects_count = 0; - while (processed_objects_count < m_element_count) + while (processed_objects_count < element_count) { LeafNode current_leaf; @@ -369,7 +369,7 @@ class StaticRTree for (uint32_t current_element_index = 0; LEAF_NODE_SIZE > current_element_index; ++current_element_index) { - if (m_element_count > (processed_objects_count + current_element_index)) + if (element_count > (processed_objects_count + current_element_index)) { uint32_t index_of_next_object = input_wrapper_vector[processed_objects_count + current_element_index] @@ -395,6 +395,8 @@ class StaticRTree // close leaf file leaf_node_file.close(); + typename ShM::vector search_tree; + uint32_t processing_level = 0; while (1 < tree_nodes_in_level.size()) { @@ -413,8 +415,8 @@ class StaticRTree TreeNode ¤t_child_node = tree_nodes_in_level[processed_tree_nodes_in_level]; // add tree node to parent entry - parent_node.children[current_child_node_index] = m_search_tree.size(); - m_search_tree.emplace_back(current_child_node); + parent_node.children[current_child_node_index] = search_tree.size(); + search_tree.emplace_back(current_child_node); // merge MBRs parent_node.minimum_bounding_rectangle.MergeBoundingBoxes( current_child_node.minimum_bounding_rectangle); @@ -430,18 +432,18 @@ class StaticRTree } BOOST_ASSERT_MSG(1 == tree_nodes_in_level.size(), "tree broken, more than one root node"); // last remaining entry is the root node, store it - m_search_tree.emplace_back(tree_nodes_in_level[0]); + search_tree.emplace_back(tree_nodes_in_level[0]); // reverse and renumber tree to have root at index 0 - std::reverse(m_search_tree.begin(), m_search_tree.end()); + std::reverse(search_tree.begin(), search_tree.end()); - uint32_t search_tree_size = m_search_tree.size(); + uint32_t search_tree_size = search_tree.size(); tbb::parallel_for(tbb::blocked_range(0, search_tree_size), - [this, &search_tree_size](const tbb::blocked_range &range) - { + [&search_tree, &search_tree_size](const tbb::blocked_range &range) + { for (uint32_t i = range.begin(); i != range.end(); ++i) { - TreeNode ¤t_tree_node = this->m_search_tree[i]; + TreeNode ¤t_tree_node = search_tree[i]; for (uint32_t j = 0; j < current_tree_node.child_count; ++j) { const uint32_t old_id = current_tree_node.children[j]; @@ -454,10 +456,10 @@ class StaticRTree // open tree file boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary); - uint32_t size_of_tree = m_search_tree.size(); + uint32_t size_of_tree = search_tree.size(); BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty"); - tree_node_file.write((char *)&size_of_tree, sizeof(uint32_t)); - tree_node_file.write((char *)&m_search_tree[0], sizeof(TreeNode) * size_of_tree); + tree_node_file.write((char *) &size_of_tree, sizeof(uint32_t)); + tree_node_file.write((char *) &search_tree[0], sizeof(TreeNode) * size_of_tree); // close tree node file. tree_node_file.close();