From 275808d0d569a69a7e5516e167d76a2fc2779965 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 16:54:49 +0100 Subject: [PATCH 01/11] Adding 'designated' to list of recognized access tags --- DataStructures/ExtractorCallBacks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 5dfc69d96..464a11dc0 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -135,7 +135,7 @@ public: } } - if("yes" == accessClass) + if("yes" == accessClass || "designated" == accessClass) w.access = true; else if("no" == accessClass) w.access = false; From e8d52c0f014d35cf913928992dbff083289bb834 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 16:58:44 +0100 Subject: [PATCH 02/11] Fixes issue #38 --- README.TXT | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.TXT b/README.TXT index a6f940396..e909f5a65 100644 --- a/README.TXT +++ b/README.TXT @@ -6,7 +6,7 @@ installing dependencies and running make should suffice. Make sure the following dependencies are installed: - Boost 1.41+ - - sparsehash 1.4+ + - sparsehash 1.4+ - g++ 4.2+ - libxml2 2.7+ - scons 2.10+ @@ -77,11 +77,12 @@ preprocessing runs in three steps, all done by seperate programs. necessary, because the osm data is not made to support fast routing out of the box. The output of the step is a file called 'file.osrm' -'osrm-prepare file.osrm' preprocesses the road network and computes additional -information that is exploited later to speed up the path computation. The output -of this step consists of two file 'file.osrm.hsgr' and 'file.osrm.nodes'. The first -file is the so-called hierarchy that speeds up the path computation while the -latter one carries (among other things) geographical information. +'osrm-prepare file.osrm file.restrictions' preprocesses the road network and +computes additional information that is exploited later to speed up the path +computation. The output of this step consists of two file 'file.osrm.hsgr' and +'file.osrm.nodes'. The first file is the so-called hierarchy that speeds up the +path computation while the latter one carries (among other things) geographical +information. 'osrm-routed' starts the server on TCP Port 5000. The server communicates over http and can be queried by any browser or http-capable From ff5e34ee70775e51915e7d40abf51ff0e644e6e1 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 18:48:38 +0100 Subject: [PATCH 03/11] Fixing segfaults when restrictions list was empty. See ticket #34 --- Contractor/EdgeBasedGraphFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index e7499c722..b461ddf24 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -103,7 +103,7 @@ void EdgeBasedGraphFactory::Run() { //Loop over all nodes u. Three nested loop look super-linear, but we are dealing with a number linear in the turns only. for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { //loop over all adjacent edge (u,v) - while(restrictionIterator->fromNode < u && inputRestrictions.end() != restrictionIterator) { + while(inputRestrictions.end() != restrictionIterator && restrictionIterator->fromNode < u) { ++restrictionIterator; } for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { @@ -115,7 +115,7 @@ void EdgeBasedGraphFactory::Run() { //if (u,v,w) is a forbidden turn, continue bool isTurnProhibited = false; if( u != w ) { //only add an edge if turn is not a U-turn - if(u == restrictionIterator->fromNode) { + if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; do { if( v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) { From 928e1178b1e4db04b36578d2d4e7fdff27d76c6c Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 19:33:03 +0100 Subject: [PATCH 04/11] Removed VERBOSE macro since it was superflous --- Util/GraphLoader.h | 68 ++++++++++++++++++---------------------------- typedefs.h | 2 -- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index e1d4d9464..3ed93033a 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -48,17 +48,17 @@ NodeID readOSRMGraphFromStream(istream &in, vector& edgeList, vector> n; - VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) - for (NodeID i=0; i> id >> ycoord >> xcoord; int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); ext2IntNodeMap.insert(make_pair(id, i)); } in >> m; - VERBOSE(cout << " and " << m << " edges ..." << flush;) + DEBUG(" and " << m << " edges ..."); edgeList.reserve(m); - for (EdgeID i=0; i& edgeList, vector" << source << "," << target << "," << length << "," << dir << "," << weight << endl; - cerr << "unresolved source NodeID: " << source << endl; exit(0); + if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { + ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source ); } source = intNodeID->second; intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } + if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); } target = intNodeID->second; - if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } + if(source == UINT_MAX || target == UINT_MAX) { ERR( "nonexisting source or target" ); } EdgeT inputEdge(source, target, nameID, weight, forward, backward, type ); edgeList.push_back(inputEdge); @@ -107,7 +103,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; in.read((char*)&n, sizeof(NodeID)); - VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) + DEBUG("Importing n = " << n << " nodes "); for (NodeID i=0; i& edgeList, vecto ext2IntNodeMap.insert(make_pair(id, i)); } in.read((char*)&m, sizeof(unsigned)); - VERBOSE(cout << " and " << m << " edges ..." << flush;) + DEBUG(" and " << m << " edges "); for(unsigned i = 0; i < inputRestrictions.size(); ++i) { ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); @@ -167,13 +163,13 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto if (1 == dir) { backward = false; } if (2 == dir) { forward = false; } - if(length == 0) { cerr << "loaded null length edge" << endl; exit(1); } + if(length == 0) { ERR("loaded null length edge" ); } // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { #ifndef NDEBUG - cerr << "[warning] unresolved source NodeID: " << source << endl; + WARN(" unresolved source NodeID: " << source ); #endif continue; } @@ -181,13 +177,13 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto intNodeID = ext2IntNodeMap.find(target); if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { #ifndef NDEBUG - cerr << "unresolved target NodeID : " << target << endl; + WARN("unresolved target NodeID : " << target ); #endif continue; } target = intNodeID->second; - if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } + if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target"); } EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout ); edgeList.push_back(inputEdge); @@ -204,17 +200,17 @@ NodeID readDTMPGraphFromStream(istream &in, vector& edgeList, vector> n; - VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) - for (NodeID i=0; i> id >> ycoord >> xcoord; int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); ext2IntNodeMap.insert(make_pair(id, i)); } in >> m; - VERBOSE(cout << " and " << m << " edges ..." << flush;) + DEBUG(" and " << m << " edges"); edgeList.reserve(m); - for (EdgeID i=0; i& edgeList, vector 0); assert(weight > 0); if(dir <0 || dir > 2) - std::cerr << "[error] direction bogus: " << dir << std::endl; + WARN("direction bogus: " << dir); assert(0<=dir && dir<=2); bool forward = true; @@ -287,23 +283,19 @@ NodeID readDTMPGraphFromStream(istream &in, vector& edgeList, vector" << source << "," << target << "," << length << "," << dir << "," << weight << endl; - cerr << "unresolved source NodeID: " << source << endl; exit(0); + if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { + ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source); } source = intNodeID->second; intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } + if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); } target = intNodeID->second; - if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } + if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); } EdgeT inputEdge(source, target, 0, weight, forward, backward, type ); edgeList.push_back(inputEdge); @@ -333,12 +325,9 @@ NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector> source >> target >> weight >> dir; - // if(dir == 3) - // dir = 0; - assert(weight > 0); if(dir <0 || dir > 3) - std::cerr << "[error] direction bogus: " << dir << std::endl; + ERR( "[error] direction bogus: " << dir ); assert(0<=dir && dir<=3); bool forward = true; @@ -347,8 +336,7 @@ NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector& edgeList, vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. - // cout << "ok" << endl; - // std::cout << "imported " << numberOfNodes << " nodes and " << edgeList.size() << " edges" << std::endl; nodeMap.clear(); return numberOfNodes; } diff --git a/typedefs.h b/typedefs.h index 9dacefff2..5f71a3ce5 100644 --- a/typedefs.h +++ b/typedefs.h @@ -31,8 +31,6 @@ or see http://www.gnu.org/licenses/agpl.txt. using namespace std; -#define VERBOSE(x) x -#define VERBOSE2(x) #ifdef STXXL_VERBOSE_LEVEL #undef STXXL_VERBOSE_LEVEL #endif From fd3ce305f40cc07f9d0a02962cb0dec503971720 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 19:48:01 +0100 Subject: [PATCH 05/11] Moved raw outputs to the appropriate macros --- createHierarchy.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index f2a1be972..108a11d9e 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -28,7 +28,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #undef VERBOSE2 #endif -#include +#include + #include #include #include @@ -60,8 +61,7 @@ std::vector<_Restriction> inputRestrictions; int main (int argc, char *argv[]) { if(argc < 3) { - cerr << "usage: " << std::endl << argv[0] << " " << std::endl; - exit(-1); + ERR("usage: " << std::endl << argv[0] << " "); } INFO("Using restrictions from file: " << argv[2]); ifstream restrictionsInstream(argv[2], ios::binary); @@ -83,17 +83,17 @@ int main (int argc, char *argv[]) { } omp_set_num_threads(numberOfThreads); - std::cout << "preprocessing data from input file " << argv[1]; + INFO("preprocessing data from input file " << argv[1] << " using STL" #ifdef _GLIBCXX_PARALLEL - std::cout << " using STL parallel mode" << std::endl; + "parallel (GCC)" #else - std::cout << " using STL serial mode" << std::endl; + "serial" #endif - + " mode"); ifstream in; in.open (argv[1], ifstream::in | ifstream::binary); if (!in.is_open()) { - cerr << "Cannot open " << argv[1] << std::endl; exit(-1); + ERR("Cannot open " << argv[1]); } char nodeOut[1024]; @@ -132,24 +132,23 @@ int main (int argc, char *argv[]) { DELETE(edgeBasedGraphFactory); WritableGrid * writeableGrid = new WritableGrid(); - std::cout << "building grid ..." << std::flush; + INFO("building grid ..."); writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut); DELETE( writeableGrid ); - std::cout << "writing node map ..." << std::flush; - ofstream mapOutFile(nodeOut, ios::binary); - for(NodeID i = 0; i < internalToExternaleNodeMapping.size(); i++) { - mapOutFile.write((char *)&(internalToExternaleNodeMapping.at(i)), sizeof(NodeInfo)); + INFO("writing node map ..."); + std::ofstream mapOutFile(nodeOut, ios::binary); + BOOST_FOREACH(NodeInfo & info, internalToExternaleNodeMapping) { + mapOutFile.write((char *)&(info), sizeof(NodeInfo)); } mapOutFile.close(); - std::cout << "ok" << std::endl; internalToExternaleNodeMapping.clear(); std::vector().swap(internalToExternaleNodeMapping); inputRestrictions.clear(); std::vector<_Restriction>().swap(inputRestrictions); - std::cout << "initializing contractor ..." << std::flush; + INFO("initializing contractor"); Contractor* contractor = new Contractor( n, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); @@ -160,24 +159,25 @@ int main (int argc, char *argv[]) { ContractionCleanup * cleanup = new ContractionCleanup(n, contractedEdges); contractedEdges.clear(); + std::vector().swap(contractedEdges); cleanup->Run(); std::vector< InputEdge> cleanedEdgeList; cleanup->GetData(cleanedEdgeList); DELETE( cleanup ); - std::cout << "Serializing edges " << std::flush; + INFO("Serializing edges "); ofstream edgeOutFile(edgeOut, ios::binary); Percent p(cleanedEdgeList.size()); - for(std::vector< InputEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) { + BOOST_FOREACH(InputEdge & edge, cleanedEdgeList) { p.printIncrement(); - edgeOutFile.write((char *)&(it->data), sizeof(EdgeData)); - edgeOutFile.write((char *)&(it->source), sizeof(NodeID)); - edgeOutFile.write((char *)&(it->target), sizeof(NodeID)); + edgeOutFile.write((char *)&(edge.data), sizeof(EdgeData)); + edgeOutFile.write((char *)&(edge.source), sizeof(NodeID)); + edgeOutFile.write((char *)&(edge.target), sizeof(NodeID)); } edgeOutFile.close(); cleanedEdgeList.clear(); - std::cout << "finished" << std::endl; + INFO("finished preprocessing"); return 0; } From eb1d629ea7879c6458d603652aa47531f8530a25 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 20:00:05 +0100 Subject: [PATCH 06/11] Doing swap trick to save RAM --- createHierarchy.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 108a11d9e..762a544c3 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -64,7 +64,7 @@ int main (int argc, char *argv[]) { ERR("usage: " << std::endl << argv[0] << " "); } INFO("Using restrictions from file: " << argv[2]); - ifstream restrictionsInstream(argv[2], ios::binary); + std::ifstream restrictionsInstream(argv[2], ios::binary); _Restriction restriction; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); @@ -96,23 +96,11 @@ int main (int argc, char *argv[]) { ERR("Cannot open " << argv[1]); } - char nodeOut[1024]; - char edgeOut[1024]; - char ramIndexOut[1024]; - char fileIndexOut[1024]; - char levelInfoOut[1024]; - - strcpy(nodeOut, argv[1]); - strcpy(edgeOut, argv[1]); - strcpy(ramIndexOut, argv[1]); - strcpy(fileIndexOut, argv[1]); - strcpy(levelInfoOut, argv[1]); - - strcat(nodeOut, ".nodes"); - strcat(edgeOut, ".hsgr"); - strcat(ramIndexOut, ".ramIndex"); - strcat(fileIndexOut, ".fileIndex"); - strcat(levelInfoOut, ".levels"); + char nodeOut[1024]; strcpy(nodeOut, argv[1]); strcat(nodeOut, ".nodes"); + char edgeOut[1024]; strcpy(edgeOut, argv[1]); strcat(edgeOut, ".hsgr"); + char ramIndexOut[1024]; strcpy(ramIndexOut, argv[1]); strcat(ramIndexOut, ".ramIndex"); + char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex"); + char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); std::vector edgeList; NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions); @@ -135,6 +123,8 @@ int main (int argc, char *argv[]) { INFO("building grid ..."); writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut); DELETE( writeableGrid ); + nodeBasedEdgeList.clear(); + std::vector().swap(nodeBasedEdgeList); INFO("writing node map ..."); std::ofstream mapOutFile(nodeOut, ios::binary); @@ -142,7 +132,6 @@ int main (int argc, char *argv[]) { mapOutFile.write((char *)&(info), sizeof(NodeInfo)); } mapOutFile.close(); - internalToExternaleNodeMapping.clear(); std::vector().swap(internalToExternaleNodeMapping); inputRestrictions.clear(); From 9d22fca5e7476bb2a874555ae1a0a8ae8d1f08c0 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 12:58:41 +0100 Subject: [PATCH 07/11] Moved GUARANTEE macro from debug to general scope --- typedefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typedefs.h b/typedefs.h index 5f71a3ce5..0fd300f4f 100644 --- a/typedefs.h +++ b/typedefs.h @@ -39,12 +39,12 @@ using namespace std; #define INFO(x) do {std::cout << "[info " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); #define ERR(x) do {std::cerr << "[error " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl; exit(-1);} while(0); #define WARN(x) do {std::cerr << "[warn " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); +#define GUARANTEE(x,y) do { {do{ if(false == (x)) { ERR(y) } } while(0);} } while(0); + #ifdef NDEBUG #define DEBUG(x) -#define GUARANTEE(x,y) #else #define DEBUG(x) do {std::cout << "[debug " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); -#define GUARANTEE(x,y) do { {do{ if(false == (x)) { ERR(y) } } while(0);} } while(0); #endif #define DELETE(x) do { if(NULL != x) { delete x; x = NULL; } }while(0); From fb661ab6f6044b7661bfe8459326d8bffc392899 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 13:00:09 +0100 Subject: [PATCH 08/11] Fixed typo in output --- createHierarchy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 762a544c3..4e3c5d655 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -83,7 +83,7 @@ int main (int argc, char *argv[]) { } omp_set_num_threads(numberOfThreads); - INFO("preprocessing data from input file " << argv[1] << " using STL" + INFO("preprocessing data from input file " << argv[1] << " using STL " #ifdef _GLIBCXX_PARALLEL "parallel (GCC)" #else From 5236fb8c0ec558dbd74ef8856a22f4ae04763d8f Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 14:48:06 +0100 Subject: [PATCH 09/11] Removed superflous member that saves about 10 percent of RAM --- Contractor/ContractionCleanup.h | 5 ++--- Contractor/Contractor.h | 2 +- DataStructures/ExtractorCallBacks.h | 2 +- DataStructures/SearchEngine.h | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index 2486a8e40..bc9f9c4e4 100644 --- a/Contractor/ContractionCleanup.h +++ b/Contractor/ContractionCleanup.h @@ -66,8 +66,7 @@ public: NodeID target; struct EdgeData { NodeID via; - unsigned nameID1; - unsigned nameID2; + unsigned nameID; int distance; bool shortcut; bool forward; @@ -91,7 +90,7 @@ public: bool operator== ( const Edge& right ) const { return ( source == right.source && target == right.target && data.distance == right.data.distance && data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward - && data.via == right.data.via && data.nameID1 == right.data.nameID1 && data.nameID2 == right.data.nameID2 + && data.via == right.data.via && data.nameID == right.data.nameID ); } }; diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 9daa36865..7d40e29ff 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -304,7 +304,7 @@ public: newEdge.data.distance = data.distance; newEdge.data.shortcut = data.shortcut; newEdge.data.via = data.via; - newEdge.data.nameID1 = data.nameID; + newEdge.data.nameID = data.nameID; newEdge.data.turnInstruction = data.turnInstruction; newEdge.data.forward = data.forward; newEdge.data.backward = data.backward; diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 464a11dc0..6d2c5442b 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -164,7 +164,7 @@ public: w.type = 1; //Get the unique identifier for the street name - StringMap::const_iterator strit = stringMap->find(w.name); + const StringMap::const_iterator strit = stringMap->find(w.name); if(strit == stringMap->end()) { w.nameID = externalMemory->nameVector.size(); externalMemory->nameVector.push_back(w.name); diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 26da8fc28..c26eff91d 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -256,7 +256,7 @@ private: return false; } else { assert(!ed.shortcut); - path.push_back(_PathData(ed.via, ed.nameID1, ed.turnInstruction, ed.distance) ); + path.push_back(_PathData(ed.via, ed.nameID, ed.turnInstruction, ed.distance) ); return true; } } From 9abb317e6dd2aa9ff9826282a00e6129a6e1481c Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 15:12:30 +0100 Subject: [PATCH 10/11] Minor changes --- Plugins/ObjectForPluginStruct.h | 2 +- Util/GraphLoader.h | 33 +++++++++++------------ extractor.cpp | 47 +++++++++++++-------------------- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h index a6c05c17b..945ae7fc8 100644 --- a/Plugins/ObjectForPluginStruct.h +++ b/Plugins/ObjectForPluginStruct.h @@ -58,7 +58,7 @@ struct ObjectsForQueryStruct { names = new std::vector(); char buf[1024]; - for(unsigned i = 0; i < size; i++) { + for(unsigned i = 0; i < size; ++i) { unsigned sizeOfString = 0; namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); memset(buf, 0, 1024*sizeof(char)); diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 3ed93033a..30074d577 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -104,7 +104,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto ExternalNodeMap ext2IntNodeMap; in.read((char*)&n, sizeof(NodeID)); DEBUG("Importing n = " << n << " nodes "); - for (NodeID i=0; i& edgeList, vecto } in.read((char*)&m, sizeof(unsigned)); DEBUG(" and " << m << " edges "); - for(unsigned i = 0; i < inputRestrictions.size(); ++i) { ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped restriction") - continue; + DEBUG("Unmapped from Node of restriction"); + continue; + } inputRestrictions[i].fromNode = intNodeID->second; intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped restriction") - continue; + DEBUG("Unmapped via node of restriction"); + continue; } inputRestrictions[i].viaNode = intNodeID->second; intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped restriction") - continue; + DEBUG("Unmapped to node of restriction"); + continue; } inputRestrictions[i].toNode = intNodeID->second; } @@ -144,7 +144,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto int length; bool isRoundabout; - for (EdgeID i=0; i& edgeList, vecto in.read((char*)&nameID, sizeof(unsigned)); in.read((char*)&isRoundabout, sizeof(bool)); - assert(length > 0); - assert(weight > 0); - assert(0<=dir && dir<=2); + GUARANTEE(length > 0, "loaded null length edge" ); + GUARANTEE(weight > 0, "loaded null weight"); + GUARANTEE(0<=dir && dir<=2, "loaded bogus direction"); bool forward = true; bool backward = true; if (1 == dir) { backward = false; } if (2 == dir) { forward = false; } - if(length == 0) { ERR("loaded null length edge" ); } - // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { @@ -177,20 +175,19 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto intNodeID = ext2IntNodeMap.find(target); if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { #ifndef NDEBUG - WARN("unresolved target NodeID : " << target ); + WARN("unresolved target NodeID : " << target ); #endif continue; } target = intNodeID->second; - - if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target"); } + GUARANTEE(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target"); EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout ); edgeList.push_back(inputEdge); } ext2IntNodeMap.clear(); vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. - cout << "ok" << endl; + INFO("Graph loaded ok"); return n; } template diff --git a/extractor.cpp b/extractor.cpp index d919ba897..a9e098c16 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -70,19 +70,16 @@ bool removeIfUnused(ClassT n) { return (false == n.used); } int main (int argc, char *argv[]) { - if(argc <= 1) { - cerr << "usage: " << endl << argv[0] << " " << endl; - exit(-1); - } + GUARANTEE((argc > 1) ,"usage: \n" << argv[0] << " "); - cout << "[extractor] extracting data from input file " << argv[1] << endl; - bool isPBF = false; - string outputFileName(argv[1]); - string restrictionsFileName(argv[1]); - string::size_type pos = outputFileName.find(".osm.bz2"); - if(pos==string::npos) { + INFO("extracting data from input file " << argv[1]); + bool isPBF(false); + std::string outputFileName(argv[1]); + std::string restrictionsFileName(argv[1]); + std::string::size_type pos = outputFileName.find(".osm.bz2"); + if(pos==std::string::npos) { pos = outputFileName.find(".osm.pbf"); - if(pos!=string::npos) { + if(pos!=std::string::npos) { isPBF = true; } } @@ -99,7 +96,7 @@ int main (int argc, char *argv[]) { restrictionsFileName.append(".osrm.restrictions"); } } - string adressFileName(outputFileName); + std::string adressFileName(outputFileName); Settings settings; boost::property_tree::ptree pt; @@ -109,15 +106,15 @@ int main (int argc, char *argv[]) { INFO("Found the following speed profiles: "); int profileCounter(0); BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) { - string name = v.first; + std::string name = v.first; cout << " [" << profileCounter << "]" << name << endl; ++profileCounter; } - string usedSpeedProfile(pt.get_child("").begin()->first); + std::string usedSpeedProfile(pt.get_child("").begin()->first); INFO("Using profile \"" << usedSpeedProfile << "\"") BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(usedSpeedProfile)) { - string name = v.first; - string value = v.second.get(""); + std::string name = v.first; + std::string value = v.second.get(""); DEBUG("inserting " << name << "=" << value); if(name == "obeyOneways") { if(value == "no") @@ -150,23 +147,21 @@ int main (int argc, char *argv[]) { unsigned amountOfRAM = 1; unsigned installedRAM = GetPhysicalmemory(); if(installedRAM < 2048264) { - cout << "[Warning] Machine has less than 2GB RAM." << endl; + WARN("Machine has less than 2GB RAM."); } if(testDataFile("extractor.ini")) { ExtractorConfiguration extractorConfig("extractor.ini"); unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str()); if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024)) amountOfRAM = memoryAmountFromFile; - cout << "[extractor] using " << amountOfRAM << " GB of RAM for buffers" << endl; + INFO("Using " << amountOfRAM << " GB of RAM for buffers"); } + StringMap stringMap; STXXLContainers externalMemory; unsigned usedNodeCounter = 0; unsigned usedEdgeCounter = 0; - - StringMap stringMap; - double time = get_timestamp(); stringMap[""] = 0; @@ -178,13 +173,9 @@ int main (int argc, char *argv[]) { parser = new XMLParser(argv[1]); } parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction, &adressFunction); - if(parser->Init()) { - parser->Parse(); - } else { - cerr << "[error] parser not initialized!" << endl; - exit(-1); - } - delete parser; + GUARANTEE(parser->Init(), "Parser not initialized!"); + parser->Parse(); + DELETE(parser); stringMap.clear(); try { From 21c913290217df4b96634b02a1b47ad40528a03f Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 15:13:35 +0100 Subject: [PATCH 11/11] Flushing vectors by swap tricks smoothes memory requirements --- Contractor/Contractor.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 7d40e29ff..c8d9568e8 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -495,6 +495,7 @@ private: bool _UpdateNeighbours( std::vector< double >* priorities, std::vector< _PriorityData >* const nodeData, _ThreadData* const data, NodeID node ) { std::vector< NodeID >& neighbours = data->neighbours; neighbours.clear(); + std::vector< NodeID>().swap(neighbours); //find all neighbours for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { @@ -521,6 +522,7 @@ private: std::vector< NodeID >& neighbours = data->neighbours; neighbours.clear(); + std::vector< NodeID>().swap(neighbours); for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { const NodeID target = _graph->GetTarget( e );