Partial refactoring
This commit is contained in:
parent
c5db4dc15f
commit
0367399c89
@ -30,9 +30,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf;
|
||||
@ -40,10 +40,14 @@ typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf;
|
||||
class NodeInformationHelpDesk : boost::noncopyable{
|
||||
public:
|
||||
NodeInformationHelpDesk(
|
||||
const char* ramIndexInput,
|
||||
const char* fileIndexInput,
|
||||
const std::string & ramIndexInput,
|
||||
const std::string & fileIndexInput,
|
||||
const std::string & nodes_filename,
|
||||
const std::string & edges_filename,
|
||||
const unsigned number_of_nodes,
|
||||
const unsigned crc) : number_of_nodes(number_of_nodes), checkSum(crc) {
|
||||
const unsigned check_sum
|
||||
) : number_of_nodes(number_of_nodes), check_sum(check_sum)
|
||||
{
|
||||
read_only_rtree = new StaticRTree<RTreeLeaf>(
|
||||
ramIndexInput,
|
||||
fileIndexInput
|
||||
@ -52,6 +56,8 @@ public:
|
||||
0 == coordinateVector.size(),
|
||||
"Coordinate vector not empty"
|
||||
);
|
||||
|
||||
LoadNodesAndEdges(nodes_filename, edges_filename);
|
||||
}
|
||||
|
||||
//Todo: Shared memory mechanism
|
||||
@ -59,41 +65,6 @@ public:
|
||||
delete read_only_rtree;
|
||||
}
|
||||
|
||||
void initNNGrid(
|
||||
std::ifstream& nodesInstream,
|
||||
std::ifstream& edgesInStream
|
||||
) {
|
||||
DEBUG("Loading node data");
|
||||
NodeInfo b;
|
||||
while(!nodesInstream.eof()) {
|
||||
nodesInstream.read((char *)&b, sizeof(NodeInfo));
|
||||
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
||||
}
|
||||
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
||||
nodesInstream.close();
|
||||
|
||||
DEBUG("Loading edge data");
|
||||
unsigned numberOfOrigEdges(0);
|
||||
edgesInStream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
||||
origEdgeData_viaNode.resize(numberOfOrigEdges);
|
||||
origEdgeData_nameID.resize(numberOfOrigEdges);
|
||||
origEdgeData_turnInstruction.resize(numberOfOrigEdges);
|
||||
|
||||
OriginalEdgeData deserialized_originalEdgeData;
|
||||
for(unsigned i = 0; i < numberOfOrigEdges; ++i) {
|
||||
edgesInStream.read(
|
||||
(char*)&(deserialized_originalEdgeData),
|
||||
sizeof(OriginalEdgeData)
|
||||
);
|
||||
origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode;
|
||||
origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID;
|
||||
origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction;
|
||||
}
|
||||
edgesInStream.close();
|
||||
DEBUG("Loaded " << numberOfOrigEdges << " orig edges");
|
||||
DEBUG("Opening NN indices");
|
||||
}
|
||||
|
||||
inline int getLatitudeOfNode(const unsigned id) const {
|
||||
const NodeID node = origEdgeData_viaNode.at(id);
|
||||
return coordinateVector.at(node).lat;
|
||||
@ -147,10 +118,50 @@ public:
|
||||
}
|
||||
|
||||
inline unsigned GetCheckSum() const {
|
||||
return checkSum;
|
||||
return check_sum;
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadNodesAndEdges(
|
||||
const std::string & nodes_file,
|
||||
const std::string & edges_file
|
||||
) {
|
||||
std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary);
|
||||
if(!nodes_input_stream) { ERR(nodes_file << " not found"); }
|
||||
std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary);
|
||||
if(!edges_input_stream) { ERR(edges_file << " not found"); }
|
||||
|
||||
DEBUG("Loading node data");
|
||||
NodeInfo b;
|
||||
while(!nodes_input_stream.eof()) {
|
||||
nodes_input_stream.read((char *)&b, sizeof(NodeInfo));
|
||||
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
||||
}
|
||||
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
||||
nodes_input_stream.close();
|
||||
|
||||
DEBUG("Loading edge data");
|
||||
unsigned numberOfOrigEdges(0);
|
||||
edges_input_stream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
||||
origEdgeData_viaNode.resize(numberOfOrigEdges);
|
||||
origEdgeData_nameID.resize(numberOfOrigEdges);
|
||||
origEdgeData_turnInstruction.resize(numberOfOrigEdges);
|
||||
|
||||
OriginalEdgeData deserialized_originalEdgeData;
|
||||
for(unsigned i = 0; i < numberOfOrigEdges; ++i) {
|
||||
edges_input_stream.read(
|
||||
(char*)&(deserialized_originalEdgeData),
|
||||
sizeof(OriginalEdgeData)
|
||||
);
|
||||
origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode;
|
||||
origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID;
|
||||
origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction;
|
||||
}
|
||||
edges_input_stream.close();
|
||||
DEBUG("Loaded " << numberOfOrigEdges << " orig edges");
|
||||
DEBUG("Opening NN indices");
|
||||
}
|
||||
|
||||
std::vector<_Coordinate> coordinateVector;
|
||||
std::vector<NodeID> origEdgeData_viaNode;
|
||||
std::vector<unsigned> origEdgeData_nameID;
|
||||
@ -158,7 +169,7 @@ private:
|
||||
|
||||
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * read_only_rtree;
|
||||
const unsigned number_of_nodes;
|
||||
const unsigned checkSum;
|
||||
const unsigned check_sum;
|
||||
};
|
||||
|
||||
#endif /*NODEINFORMATIONHELPDESK_H_*/
|
||||
|
@ -45,6 +45,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//tuning parameters
|
||||
@ -275,17 +276,16 @@ private:
|
||||
std::vector<TreeNode> m_search_tree;
|
||||
uint64_t m_element_count;
|
||||
|
||||
std::string m_leaf_node_filename;
|
||||
const std::string m_leaf_node_filename;
|
||||
public:
|
||||
//Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
|
||||
explicit StaticRTree(
|
||||
std::vector<DataT> & input_data_vector,
|
||||
const char * tree_node_filename,
|
||||
const char * leaf_node_filename
|
||||
) :
|
||||
m_element_count(input_data_vector.size()),
|
||||
const std::string tree_node_filename,
|
||||
const std::string leaf_node_filename
|
||||
)
|
||||
: m_element_count(input_data_vector.size()),
|
||||
m_leaf_node_filename(leaf_node_filename)
|
||||
|
||||
{
|
||||
INFO("constructing r-tree of " << m_element_count << " elements");
|
||||
double time1 = get_timestamp();
|
||||
@ -305,7 +305,7 @@ public:
|
||||
|
||||
}
|
||||
//open leaf file
|
||||
std::ofstream leaf_node_file(leaf_node_filename, std::ios::binary);
|
||||
std::ofstream leaf_node_file(leaf_node_filename.c_str(), std::ios::binary);
|
||||
leaf_node_file.write((char*) &m_element_count, sizeof(uint64_t));
|
||||
|
||||
//sort the hilbert-value representatives
|
||||
@ -386,7 +386,7 @@ public:
|
||||
}
|
||||
|
||||
//open tree file
|
||||
std::ofstream tree_node_file(tree_node_filename, std::ios::binary);
|
||||
std::ofstream tree_node_file(tree_node_filename.c_str(), std::ios::binary);
|
||||
uint32_t size_of_tree = m_search_tree.size();
|
||||
BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty");
|
||||
tree_node_file.write((char *)&size_of_tree, sizeof(uint32_t));
|
||||
@ -399,13 +399,11 @@ public:
|
||||
|
||||
//Read-only operation for queries
|
||||
explicit StaticRTree(
|
||||
const char * node_filename,
|
||||
const char * leaf_filename
|
||||
const std::string & node_filename,
|
||||
const std::string & leaf_filename
|
||||
) : m_leaf_node_filename(leaf_filename) {
|
||||
//INFO("Loading nodes: " << node_filename);
|
||||
//INFO("opening leafs: " << leaf_filename);
|
||||
//open tree node file and load into RAM.
|
||||
std::ifstream tree_node_file(node_filename, std::ios::binary);
|
||||
std::ifstream tree_node_file(node_filename.c_str(), std::ios::binary);
|
||||
uint32_t tree_size = 0;
|
||||
tree_node_file.read((char*)&tree_size, sizeof(uint32_t));
|
||||
//INFO("reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes");
|
||||
@ -414,7 +412,7 @@ public:
|
||||
tree_node_file.close();
|
||||
|
||||
//open leaf node file and store thread specific pointer
|
||||
std::ifstream leaf_node_file(leaf_filename, std::ios::binary);
|
||||
std::ifstream leaf_node_file(leaf_filename.c_str(), std::ios::binary);
|
||||
leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t));
|
||||
leaf_node_file.close();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user