Skip to content

Commit

Permalink
Change StaticRTree serialization constructor to static function
Browse files Browse the repository at this point in the history
Since the constructor does not satisfy the requirements for a
constructor (the RTree is not properly initialized) make it a
static function instead.
  • Loading branch information
TheMarex committed Jul 10, 2014
1 parent c7eab4d commit d6dd669
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
18 changes: 4 additions & 14 deletions Contractor/Prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ int Prepare::Process(int argc, char *argv[])

TIMER_STOP(expansion);

BuildRTree(node_based_edge_list);
StaticRTree<EdgeBasedNode>::Build(node_based_edge_list,
rtree_nodes_path.c_str(),
rtree_leafs_path.c_str(),
internal_to_external_node_map);

IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32;
const unsigned node_based_edge_list_CRC32 =
Expand Down Expand Up @@ -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<EdgeBasedNode> &node_based_edge_list)
{
SimpleLogger().Write() << "building r-tree ...";
StaticRTree<EdgeBasedNode>(node_based_edge_list,
rtree_nodes_path.c_str(),
rtree_leafs_path.c_str(),
internal_to_external_node_map);
}
1 change: 0 additions & 1 deletion Contractor/Prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Prepare
DeallocatingVector<EdgeBasedEdge> &edgeBasedEdgeList,
EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile);
void WriteNodeMapping();
void BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list);

private:
std::vector<NodeInfo> internal_to_external_node_map;
Expand Down
40 changes: 21 additions & 19 deletions DataStructures/StaticRTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EdgeDataT> &input_data_vector,
static void Build(std::vector<EdgeDataT> &input_data_vector,
const std::string tree_node_filename,
const std::string leaf_node_filename,
const std::vector<NodeInfo> &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<WrappedInputElement> input_wrapper_vector(m_element_count);
std::vector<WrappedInputElement> input_wrapper_vector(element_count);

HilbertCode get_hilbert_number;

// generate auxiliary vector of hilbert-values
tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, m_element_count),
tbb::blocked_range<uint64_t>(0, element_count),
[&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list](
const tbb::blocked_range<uint64_t> &range)
{
Expand All @@ -351,15 +351,15 @@ 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());
std::vector<TreeNode> tree_nodes_in_level;

// 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;
Expand All @@ -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]
Expand All @@ -395,6 +395,8 @@ class StaticRTree
// close leaf file
leaf_node_file.close();

typename ShM<TreeNode, UseSharedMemory>::vector search_tree;

uint32_t processing_level = 0;
while (1 < tree_nodes_in_level.size())
{
Expand All @@ -413,8 +415,8 @@ class StaticRTree
TreeNode &current_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);
Expand All @@ -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<uint32_t>(0, search_tree_size),
[this, &search_tree_size](const tbb::blocked_range<uint32_t> &range)
{
[&search_tree, &search_tree_size](const tbb::blocked_range<uint32_t> &range)
{
for (uint32_t i = range.begin(); i != range.end(); ++i)
{
TreeNode &current_tree_node = this->m_search_tree[i];
TreeNode &current_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];
Expand All @@ -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();

Expand Down

0 comments on commit d6dd669

Please sign in to comment.