Graphloader translates external to internal node ids for binary osrm

files. Google sparsehash replaced by boost unordered map
This commit is contained in:
DennisOSRM 2011-10-12 17:31:18 +02:00
parent 3f49351d38
commit 77c6a06c15

View File

@ -28,7 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
#include <google/dense_hash_map> #include <boost/unordered_map.hpp>
#ifdef _GLIBCXX_PARALLEL #ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm> #include <parallel/algorithm>
@ -39,7 +39,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../DataStructures/ImportEdge.h" #include "../DataStructures/ImportEdge.h"
#include "../typedefs.h" #include "../typedefs.h"
typedef google::dense_hash_map<NodeID, NodeID> ExternalNodeMap; typedef boost::unordered_map<NodeID, NodeID> ExternalNodeMap;
template<typename EdgeT> template<typename EdgeT>
NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) { NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
@ -47,7 +47,6 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
EdgeID m; EdgeID m;
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext2IntNodeMap;
ext2IntNodeMap.set_empty_key(UINT_MAX);
in >> n; in >> n;
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;)
for (NodeID i=0; i<n;i++) { for (NodeID i=0; i<n;i++) {
@ -101,13 +100,12 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
return n; return n;
} }
template<typename EdgeT> template<typename EdgeT>
NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) { NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap, vector<_Restriction> & inputRestrictions) {
NodeID n, source, target, id; NodeID n, source, target, id;
EdgeID m; EdgeID m;
short dir; short dir;
int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext2IntNodeMap;
ext2IntNodeMap.set_empty_key(UINT_MAX);
in.read((char*)&n, sizeof(NodeID)); in.read((char*)&n, sizeof(NodeID));
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;)
for (NodeID i=0; i<n;i++) { for (NodeID i=0; i<n;i++) {
@ -120,6 +118,29 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
in.read((char*)&m, sizeof(unsigned)); in.read((char*)&m, sizeof(unsigned));
VERBOSE(cout << " and " << m << " edges ..." << flush;) VERBOSE(cout << " and " << m << " edges ..." << flush;)
for(unsigned i = 0; i < inputRestrictions.size(); ++i) {
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode);
if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction")
continue;
}
inputRestrictions[i].fromNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode);
if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction")
continue;
}
inputRestrictions[i].viaNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode);
if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction")
continue;
}
inputRestrictions[i].toNode = intNodeID->second;
}
edgeList.reserve(m); edgeList.reserve(m);
for (EdgeID i=0; i<m; i++) { for (EdgeID i=0; i<m; i++) {
EdgeWeight weight; EdgeWeight weight;
@ -179,7 +200,6 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
EdgeID m; EdgeID m;
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext2IntNodeMap;
ext2IntNodeMap.set_empty_key(UINT_MAX);
in >> n; in >> n;
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;)
for (NodeID i=0; i<n;i++) { for (NodeID i=0; i<n;i++) {
@ -293,7 +313,7 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
template<typename EdgeT> template<typename EdgeT>
NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeID> & int2ExtNodeMap) { NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeID> & int2ExtNodeMap) {
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX); ExternalNodeMap nodeMap;
NodeID n, source, target; NodeID n, source, target;
unsigned numberOfNodes = 0; unsigned numberOfNodes = 0;
char d; char d;
@ -351,7 +371,7 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
template<typename EdgeT> template<typename EdgeT>
unsigned readHSGRFromStream(istream &in, vector<EdgeT> & edgeList) { unsigned readHSGRFromStream(istream &in, vector<EdgeT> & edgeList) {
unsigned numberOfNodes = 0; unsigned numberOfNodes = 0;
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX); ExternalNodeMap nodeMap;
while(!in.eof()) { while(!in.eof()) {
EdgeT g; EdgeT g;
EdgeData e; EdgeData e;
@ -394,7 +414,7 @@ template<typename EdgeT>
unsigned readHSGRFromStreamWithOutEdgeData(const char * hsgrName, vector<EdgeT> * edgeList) { unsigned readHSGRFromStreamWithOutEdgeData(const char * hsgrName, vector<EdgeT> * edgeList) {
std::ifstream hsgrInStream(hsgrName, std::ios::binary); std::ifstream hsgrInStream(hsgrName, std::ios::binary);
unsigned numberOfNodes = 0; unsigned numberOfNodes = 0;
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX); ExternalNodeMap nodeMap;
while(!hsgrInStream.eof()) { while(!hsgrInStream.eof()) {
EdgeT g; EdgeT g;
// EdgeData e; // EdgeData e;