From 275808d0d569a69a7e5516e167d76a2fc2779965 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 30 Nov 2011 16:54:49 +0100 Subject: [PATCH 01/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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 ); From b4585f24bba5e61c92d18968a65a22966c5ab282 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Dec 2011 18:30:13 +0100 Subject: [PATCH 12/26] Skipping awfully tagged ways in extraction --- DataStructures/ExtractorCallBacks.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 6d2c5442b..67c96689a 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -173,8 +173,14 @@ public: w.nameID = strit->second; } - GUARANTEE(w.id != UINT_MAX, "found way with unknown type"); - GUARANTEE(-1 != w.speed, "found way with unknown speed"); + if(-1 == w.speed){ + WARN("found way with bogus speed, id: " << w.id); + return true; + } + if(w.id == UINT_MAX) { + WARN("found way with unknown type" << w.id); + return true; + } if ( w.direction == _Way::opposite ){ std::reverse( w.path.begin(), w.path.end() ); From bd2080fdb565b6dec536142853ff8bdfc683f8fa Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 2 Dec 2011 11:52:56 +0100 Subject: [PATCH 13/26] Flickering of route was caused by rounding error in NNGrid. Fixes ticket #35. --- DataStructures/NNGrid.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index a83248a5b..61e3e9d30 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -310,10 +310,6 @@ public: double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) { resultNode.weight2 = candidate.weight; - /* if(resultNode.weight1 != resultNode.weight2) { - ERR("w1: " << resultNode.weight1 << ", w2: " << resultNode.weight2); - assert(false); - }*/ if(candidate.edgeBasedNode < resultNode.edgeBasedNode) { resultNode.edgeBasedNode = candidate.edgeBasedNode; std::swap(resultNode.weight1, resultNode.weight2); @@ -412,7 +408,7 @@ private: } inline bool DoubleEpsilonCompare(const double d1, const double d2) { - return (std::fabs(d1 - d2) < 0.000000001); + return (std::fabs(d1 - d2) < 0.0001); } unsigned FillCell(std::vector& entriesWithSameRAMIndex, unsigned fileOffset ) { From f601664620963ced9299a3c6e7c3da7d16241660 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 2 Dec 2011 15:06:49 +0100 Subject: [PATCH 14/26] Bringing XML parser up to speed and adding support for turn restriction parsing. Note that it will be removed after the release of 0.3 --- DataStructures/XMLParser.h | 80 ++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/DataStructures/XMLParser.h b/DataStructures/XMLParser.h index e50b4233f..010287ebe 100644 --- a/DataStructures/XMLParser.h +++ b/DataStructures/XMLParser.h @@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { public: - XMLParser(const char * filename) { + XMLParser(const char * filename) : nodeCallback(NULL), wayCallback(NULL), restrictionCallback(NULL){ WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf"); inputReader = inputReaderFactory(filename); } @@ -72,9 +72,12 @@ public: } } if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) { - _Relation r; - r.type = _Relation::unknown; - //todo: parse relation + _RawRestrictionContainer r = _ReadXMLRestriction(); + if(r.fromWay != UINT_MAX) { + if(!(*restrictionCallback)(r)) { + std::cerr << "[XMLParser] restriction not parsed" << std::endl; + } + } } xmlFree( currentName ); } @@ -82,11 +85,69 @@ public: } private: - _Relation _ReadXMLRelation ( ) { - _Relation relation; - relation.type = _Relation::unknown; + _RawRestrictionContainer _ReadXMLRestriction ( ) { + _RawRestrictionContainer restriction; - return relation; + if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) { + const int depth = xmlTextReaderDepth( inputReader );while ( xmlTextReaderRead( inputReader ) == 1 ) { + const int childType = xmlTextReaderNodeType( inputReader ); + if ( childType != 1 && childType != 15 ) + continue; + const int childDepth = xmlTextReaderDepth( inputReader ); + xmlChar* childName = xmlTextReaderName( inputReader ); + if ( childName == NULL ) + continue; + + if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "relation" ) == 1 ) { + xmlFree( childName ); + break; + } + if ( childType != 1 ) { + xmlFree( childName ); + continue; + } + + if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) { + xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" ); + xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" ); + if ( k != NULL && value != NULL ) { + if(xmlStrEqual(k, ( const xmlChar* ) "restriction" )){ + if(0 == std::string((const char *) value).find("only_")) + restriction.restriction.flags.isOnly = true; + } + + } + if ( k != NULL ) + xmlFree( k ); + if ( value != NULL ) + xmlFree( value ); + } else if ( xmlStrEqual( childName, ( const xmlChar* ) "member" ) == 1 ) { + xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" ); + if ( ref != NULL ) { + xmlChar * role = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "role" ); + xmlChar * type = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "type" ); + if(xmlStrEqual(role, (const xmlChar *) "to") && xmlStrEqual(type, (const xmlChar *) "way")) { + restriction.toWay = atoi((const char*) ref); + } + if(xmlStrEqual(role, (const xmlChar *) "from") && xmlStrEqual(type, (const xmlChar *) "way")) { + restriction.fromWay = atoi((const char*) ref); + } + if(xmlStrEqual(role, (const xmlChar *) "via") && xmlStrEqual(type, (const xmlChar *) "node")) { + restriction.restriction.viaNode = atoi((const char*) ref); + } + + if(NULL != type) + xmlFree( type ); + if(NULL != role) + xmlFree( role ); + if(NULL != ref) + xmlFree( ref ); + } + } + xmlFree( childName ); + } + } + return restriction; } _Way _ReadXMLWay( ) { @@ -109,6 +170,9 @@ private: continue; if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) { + xmlChar* id = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); + way.id = atoi((char*)id); + xmlFree(id); xmlFree( childName ); break; } From 7be723782a23bb3e122fa4cfecc0fd00fa3dcf4f Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 2 Dec 2011 16:38:10 +0100 Subject: [PATCH 15/26] Support for 'only_*'-typed turn restrictions. --- Contractor/ContractionCleanup.h | 25 +++++++++-------- Contractor/EdgeBasedGraphFactory.cpp | 41 +++++++++++++++++++++++----- DataStructures/ExtractorCallBacks.h | 5 ++-- DataStructures/ExtractorStructs.h | 8 +++--- DataStructures/PBFParser.h | 9 +++--- extractor.cpp | 9 +++--- 6 files changed, 62 insertions(+), 35 deletions(-) diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index bc9f9c4e4..e2b75e1ae 100644 --- a/Contractor/ContractionCleanup.h +++ b/Contractor/ContractionCleanup.h @@ -144,7 +144,7 @@ private: try { _firstEdge.resize( _numNodes + 1 ); } catch(...) { - cerr << "Not enough RAM on machine" << endl; + ERR("Not enough RAM on machine"); return; } _firstEdge[0] = 0; @@ -164,7 +164,7 @@ private: threadData.push_back( new _ThreadData( _numNodes ) ); } - cout << "Scanning for useless shortcuts" << endl; + INFO("Scanning for useless shortcuts"); BuildOutgoingGraph(); #pragma omp parallel for for ( int i = 0; i < ( int ) _graph.size(); i++ ) { @@ -202,7 +202,7 @@ private: } } - cout << "Removing edges" << endl; + INFO("Removing edges"); int useful = 0; for ( int i = 0; i < ( int ) _graph.size(); i++ ) { if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut ) @@ -210,7 +210,7 @@ private: _graph[useful] = _graph[i]; useful++; } - cout << "Removed " << _graph.size() - useful << " useless shortcuts" << endl; + INFO("Removed " << _graph.size() - useful << " useless shortcuts"); _graph.resize( useful ); for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) { @@ -223,6 +223,11 @@ private: const NodeID node = heapForward->DeleteMin(); const int distance = heapForward->GetKey( node ); + if ( distance > *targetDistance ) { + heapForward->DeleteAll(); + return; + } + if ( heapBackward->WasInserted( node ) ) { const int newDistance = heapBackward->GetKey( node ) + distance; if ( newDistance < *targetDistance ) { @@ -231,11 +236,7 @@ private: } } - if ( distance > *targetDistance ) { - heapForward->DeleteAll(); - return; - } - for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) { + for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) { const NodeID to = _graph[edge].target; const int edgeWeight = _graph[edge].data.distance; assert( edgeWeight > 0 ); @@ -256,15 +257,15 @@ private: } } - int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vector< NodeID >* path = NULL ) { + int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data ) { data->_heapForward->Clear(); data->_heapBackward->Clear(); //insert source into heap data->_heapForward->Insert( source, 0, source ); data->_heapBackward->Insert( target, 0, target ); - int targetDistance = (std::numeric_limits< int >::max)(); - NodeID middle = (std::numeric_limits::max)(); + int targetDistance = std::numeric_limits< int >::max(); + NodeID middle = std::numeric_limits::max(); while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) { if ( data->_heapForward->Size() > 0 ) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index b461ddf24..517e1337a 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -99,6 +99,7 @@ void EdgeBasedGraphFactory::Run() { Percent p(_nodeBasedGraph->GetNumberOfNodes()); int numberOfResolvedRestrictions(0); int nodeBasedEdgeCounter(0); + NodeID onlyToNode(0); //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 ) { @@ -110,29 +111,56 @@ void EdgeBasedGraphFactory::Run() { ++nodeBasedEdgeCounter; _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); //loop over all reachable edges (v,w) + bool isOnlyAllowed(false); + + //Check every turn restriction originating from this edge if it is an 'only_*'-turn. + if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { + std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; + do { + if(v == secondRestrictionIterator->viaNode) { + if(secondRestrictionIterator->flags.isOnly) { + isOnlyAllowed = true; + onlyToNode = secondRestrictionIterator->toNode; + } + } + ++secondRestrictionIterator; + } while(u == secondRestrictionIterator->fromNode); + } + for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2); //if (u,v,w) is a forbidden turn, continue - bool isTurnProhibited = false; + bool isTurnRestricted(false); + if(isOnlyAllowed && w != onlyToNode) { +// INFO("skipped turn <" << u << "," << v << "," << w << ">, only allowing <" << u << "," << v << "," << onlyToNode << ">"); + continue; + } + if( u != w ) { //only add an edge if turn is not a U-turn if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; do { - if( v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) { - isTurnProhibited = true; + if(v == secondRestrictionIterator->viaNode) { + if(w == secondRestrictionIterator->toNode) { + isTurnRestricted = true; + } } ++secondRestrictionIterator; } while(u == secondRestrictionIterator->fromNode); } - if( !isTurnProhibited ) { //only add an edge if turn is not prohibited + + if( !isTurnRestricted || (isOnlyAllowed && w == onlyToNode) ) { //only add an edge if turn is not prohibited + if(isOnlyAllowed && w == onlyToNode) { +// INFO("Adding 'only_*'-turn <" << u << "," << v << "," << w << ">"); + } else if(isOnlyAllowed && w != onlyToNode) { + assert(false); + } //new costs for edge based edge (e1, e2) = cost (e1) + tc(e1,e2) const _NodeBasedDynamicGraph::NodeIterator edgeBasedSource = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID; - // INFO("edgeBasedSource: " << edgeBasedSource); if(edgeBasedSource > _nodeBasedGraph->GetNumberOfEdges()) { ERR("edgeBasedTarget" << edgeBasedSource << ">" << _nodeBasedGraph->GetNumberOfEdges()); } const _NodeBasedDynamicGraph::NodeIterator edgeBasedTarget = _nodeBasedGraph->GetEdgeData(e2).edgeBasedNodeID; - // INFO("edgeBasedTarget: " << edgeBasedTarget); if(edgeBasedTarget > _nodeBasedGraph->GetNumberOfEdges()) { ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges()); } @@ -145,7 +173,6 @@ void EdgeBasedGraphFactory::Run() { short turnInstruction = AnalyzeTurn(u, v, w); //create edge-based graph edge - //EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty) EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); edgeBasedEdges.push_back(newEdge); EdgeBasedNode currentNode; diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 67c96689a..0face8d56 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -121,7 +121,7 @@ public: //Is the highway tag listed as usable way? if(0 < settings[highway]) { - if(0 != maxspeed) + if(0 < maxspeed) w.speed = maxspeed; else w.speed = settings[highway]; @@ -154,7 +154,6 @@ public: //Is the route tag listed as usable way in the profile? if(settings[route] > 0 || settings[man_made] > 0) { w.useful = true; - w.direction = _Way::oneway; w.speed = settings[route]; w.direction = _Way::bidirectional; } @@ -178,7 +177,7 @@ public: return true; } if(w.id == UINT_MAX) { - WARN("found way with unknown type" << w.id); + WARN("found way with unknown type: " << w.id); return true; } diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 0f5ead963..0cbd7d7f4 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -177,10 +177,10 @@ struct _RawRestrictionContainer { _Restriction restriction; EdgeID fromWay; EdgeID toWay; - unsigned viaWay; + unsigned viaNode; - _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaWay(vw) { restriction.viaNode = vn;} - _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaWay(UINT_MAX) { restriction.flags.isOnly = isOnly;} + _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;} + _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;} static _RawRestrictionContainer min_value() { return _RawRestrictionContainer((numeric_limits::min)(), (numeric_limits::min)(), (numeric_limits::min)(), (numeric_limits::min)()); @@ -233,7 +233,7 @@ struct _WayIDStartAndEndEdge { } }; -struct CmpWayStartAndEnd : public std::binary_function<_WayIDStartAndEndEdge, _WayIDStartAndEndEdge, bool> { +struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDStartAndEndEdge, bool> { typedef _WayIDStartAndEndEdge value_type; bool operator () (const _WayIDStartAndEndEdge & a, const _WayIDStartAndEndEdge & b) const { return a.wayID < b.wayID; diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index a211cb6e9..c76ba3ef7 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -270,9 +270,9 @@ private: if("from" == role || "to" == role) //Only via should be a node continue; assert("via" == role); - if(UINT_MAX != currentRestrictionContainer.viaWay) - currentRestrictionContainer.viaWay = UINT_MAX; - assert(UINT_MAX == currentRestrictionContainer.viaWay); + if(UINT_MAX != currentRestrictionContainer.viaNode) + currentRestrictionContainer.viaNode = UINT_MAX; + assert(UINT_MAX == currentRestrictionContainer.viaNode); currentRestrictionContainer.restriction.viaNode = lastRef; break; case 1: //way @@ -285,7 +285,7 @@ private: } if ("via" == role) { assert(currentRestrictionContainer.restriction.toNode == UINT_MAX); - currentRestrictionContainer.viaWay = lastRef; + currentRestrictionContainer.viaNode = lastRef; } break; case 2: //relation, not used. relations relating to relations are evil. @@ -315,7 +315,6 @@ private: for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways_size(); i++) { const OSMPBF::Way& inputWay = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways( i ); _Way w; - w.id = inputWay.id(); unsigned pathNode(0); for(int i = 0; i < inputWay.refs_size(); i++) { pathNode += inputWay.refs(i); diff --git a/extractor.cpp b/extractor.cpp index a9e098c16..a709016da 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -208,7 +208,7 @@ int main (int argc, char *argv[]) { time = get_timestamp(); cout << "[extractor] Sorting used ways ... " << flush; - stxxl::sort(externalMemory.wayStartEndVector.begin(), externalMemory.wayStartEndVector.end(), CmpWayStartAndEnd(), memory_to_use); + stxxl::sort(externalMemory.wayStartEndVector.begin(), externalMemory.wayStartEndVector.end(), CmpWayByID(), memory_to_use); cout << "ok, after " << get_timestamp() - time << "s" << endl; cout << "[extractor] Sorting restrctns. by from... " << flush; @@ -255,8 +255,7 @@ int main (int argc, char *argv[]) { cout << "[extractor] Fixing restriction ends ... " << flush; restrictionsIT = externalMemory.restrictionsVector.begin(); wayStartAndEndEdgeIT = externalMemory.wayStartEndVector.begin(); - while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && - restrictionsIT != externalMemory.restrictionsVector.end()) { + while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) { if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){ ++wayStartAndEndEdgeIT; continue; @@ -278,11 +277,13 @@ int main (int argc, char *argv[]) { if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { ++usableRestrictionsCounter; + } else { + INFO("Restriction from: " << restrictionsIT->restriction.fromNode << ", to: " << restrictionsIT->restriction.toNode); } ++restrictionsIT; } - cout << "ok, after " << get_timestamp() - time << "s" << endl; + INFO("usable restrictions: " << usableRestrictionsCounter); //serialize restrictions ofstream restrictionsOutstream; restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary); From 3986b30b003880289f3651ea445c0ef2ce5c211d Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 2 Dec 2011 16:43:44 +0100 Subject: [PATCH 16/26] way id needs to be set again --- DataStructures/PBFParser.h | 1 + 1 file changed, 1 insertion(+) diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index c76ba3ef7..ef0e4a4f2 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -315,6 +315,7 @@ private: for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways_size(); i++) { const OSMPBF::Way& inputWay = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways( i ); _Way w; + w.id = inputWay.id(); unsigned pathNode(0); for(int i = 0; i < inputWay.refs_size(); i++) { pathNode += inputWay.refs(i); From 4f5678fc95920d9338af6b7efd6cc5a15234dd58 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 2 Dec 2011 17:24:50 +0100 Subject: [PATCH 17/26] stale file streams get reset. fixes ticket 37. --- DataStructures/NNGrid.h | 21 +++++++++++++-------- Plugins/ViaRoutePlugin.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 61e3e9d30..fb79d3400 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -329,14 +329,14 @@ public: } } - // INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint); - // INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord)); - // INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint)); - // assert(!resultNode.isBidirected || (resultNode.weight1 == resultNode.weight2)); - // if(resultNode.weight1 != resultNode.weight2) { - // INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2); - // INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected ? "yes" : "no")); - // } +// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint); +// INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord)); +// INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint)); +// assert(!resultNode.isBidirected() || (resultNode.weight1 == resultNode.weight2)); +// if(resultNode.weight1 != resultNode.weight2) { +// INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2); +// INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected() ? "yes" : "no")); +// } double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) ); assert(ratio >= 0 && ratio <=1); @@ -547,6 +547,11 @@ private: if(!localStream.get() || !localStream->is_open()) { localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary)); } + if(!localStream->good()) { + localStream->clear(std::ios::goodbit); + DEBUG("Resetting stale filestream"); + } + localStream->seekg(startIndexInFile); localStream->read((char*) &cellIndex[0], 32*32*sizeof(unsigned)); assert(cellMap.find(fileIndex) != cellMap.end()); diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 4172214b0..99bb8f37a 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -140,7 +140,7 @@ public: distance = searchEngine->ComputeRoute(segmentPhantomNodes, path); if(INT_MAX == distance ) { - INFO( "Error occurred, single path not found" ); + DEBUG( "Error occurred, single path not found" ); } //put segments at correct position of routes raw data From 045922fb56c35368e70ccce6961f80ba86eb6d35 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 14:45:45 +0100 Subject: [PATCH 18/26] fixes ticket 43 --- Contractor/EdgeBasedGraphFactory.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 517e1337a..47b5376a9 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -58,8 +58,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vectorisBackward(); edge.data.edgeBasedNodeID = edges.size(); edges.push_back( edge ); - std::swap( edge.source, edge.target ); if( edge.data.backward ) { + std::swap( edge.source, edge.target ); edge.data.forward = i->isBackward(); edge.data.backward = i->isForward(); edge.data.edgeBasedNodeID = edges.size(); @@ -126,15 +126,25 @@ void EdgeBasedGraphFactory::Run() { ++secondRestrictionIterator; } while(u == secondRestrictionIterator->fromNode); } - + if(_nodeBasedGraph->EndEdges(v) == _nodeBasedGraph->BeginEdges(v) + 1 && _nodeBasedGraph->GetEdgeData(e1).type != 14 ) { + EdgeBasedNode currentNode; + currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; + currentNode.lat1 = inputNodeInfoList[u].lat; + currentNode.lon1 = inputNodeInfoList[u].lon; + currentNode.lat2 = inputNodeInfoList[v].lat; + currentNode.lon2 = inputNodeInfoList[v].lon; + currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;; + currentNode.weight = _nodeBasedGraph->GetEdgeData(e1).distance; + edgeBasedNodes.push_back(currentNode); + } for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2); //if (u,v,w) is a forbidden turn, continue bool isTurnRestricted(false); if(isOnlyAllowed && w != onlyToNode) { -// INFO("skipped turn <" << u << "," << v << "," << w << ">, only allowing <" << u << "," << v << "," << onlyToNode << ">"); - continue; - } + // INFO("skipped turn <" << u << "," << v << "," << w << ">, only allowing <" << u << "," << v << "," << onlyToNode << ">"); + continue; + } if( u != w ) { //only add an edge if turn is not a U-turn if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { @@ -151,7 +161,7 @@ void EdgeBasedGraphFactory::Run() { if( !isTurnRestricted || (isOnlyAllowed && w == onlyToNode) ) { //only add an edge if turn is not prohibited if(isOnlyAllowed && w == onlyToNode) { -// INFO("Adding 'only_*'-turn <" << u << "," << v << "," << w << ">"); + // INFO("Adding 'only_*'-turn <" << u << "," << v << "," << w << ">"); } else if(isOnlyAllowed && w != onlyToNode) { assert(false); } @@ -175,9 +185,10 @@ void EdgeBasedGraphFactory::Run() { //create edge-based graph edge EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); edgeBasedEdges.push_back(newEdge); - EdgeBasedNode currentNode; - if(_nodeBasedGraph->GetEdgeData(e1).type != 14) { + if(_nodeBasedGraph->GetEdgeData(e1).type != 14 ) { + EdgeBasedNode currentNode; + currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; currentNode.lat1 = inputNodeInfoList[u].lat; currentNode.lon1 = inputNodeInfoList[u].lon; From 4f54c90a95fc3314061531009432339410d3284a Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 15:14:23 +0100 Subject: [PATCH 19/26] Moving check to member function --- DataStructures/ExtractorStructs.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 0cbd7d7f4..864b05761 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -64,6 +64,13 @@ struct _Coordinate { bool isSet() const { return (INT_MIN != lat) && (INT_MIN != lon); } + inline bool isValid() const { + if(lat > 90*100000 || lat < -90*100000 || lon > 180*100000 || lon <-180*100000) { + return false; + } + return true; + } + }; inline ostream & operator<<(ostream & out, const _Coordinate & c){ From fe12ba23b0ee081bb5e37a6da785e024af01e810 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 15:14:43 +0100 Subject: [PATCH 20/26] Compare edge by edgebasednodeids --- DataStructures/GridEdge.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DataStructures/GridEdge.h b/DataStructures/GridEdge.h index e1865f6a7..aeb0539fa 100644 --- a/DataStructures/GridEdge.h +++ b/DataStructures/GridEdge.h @@ -29,6 +29,12 @@ struct _GridEdge { int weight; _Coordinate startCoord; _Coordinate targetCoord; + bool operator< ( const _GridEdge& right) const { + return edgeBasedNode < right.edgeBasedNode; + } + bool operator== ( const _GridEdge& right) const { + return edgeBasedNode == right.edgeBasedNode; + } }; struct GridEntry { From afe9157d6572563eee9638038768182bd5ccdbfb Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 15:22:19 +0100 Subject: [PATCH 21/26] Solves another case of flickery routes. --- DataStructures/NNGrid.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index fb79d3400..93cdfb4b2 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -315,7 +315,7 @@ public: std::swap(resultNode.weight1, resultNode.weight2); } } - if(tmpDist < dist) { + if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) { resultNode.Reset(); resultNode.edgeBasedNode = candidate.edgeBasedNode; resultNode.nodeBasedEdgeNameID = candidate.nameID; @@ -346,6 +346,7 @@ public: resultNode.weight2 *= (1-ratio); // INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2); } +// INFO("bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--") return foundNode; } From abfb49818fe22cc1a036dc62552b7957e82b71af Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 18:28:00 +0100 Subject: [PATCH 22/26] if =no then immediately return. Fixes ticket 41 --- DataStructures/ExtractorCallBacks.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 0face8d56..9d3c0eeb0 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -103,7 +103,7 @@ public: std::string route( w.keyVals.Find("route") ); double maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) ); std::string access( w.keyVals.Find("access") ); - std::string accessClass( w.keyVals.Find(settings.accessTag) ); + std::string accessTag( w.keyVals.Find(settings.accessTag) ); std::string man_made( w.keyVals.Find("man_made") ); std::string barrier( w.keyVals.Find("barrier") ); @@ -135,10 +135,11 @@ public: } } - if("yes" == accessClass || "designated" == accessClass) + if("yes" == accessTag || "designated" == accessTag) w.access = true; - else if("no" == accessClass) - w.access = false; + else if("no" == accessTag) { + return true; + } //Let's process oneway property, if speed profile obeys to it if(oneway != "no" && oneway != "false" && oneway != "0" && settings.obeyOneways) { From 0cad039615fde4f6040845590ead2bb68a07c211 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 18:39:40 +0100 Subject: [PATCH 23/26] implements ticket 41 --- DataStructures/ExtractorCallBacks.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 9d3c0eeb0..eb394493d 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -135,9 +135,10 @@ public: } } - if("yes" == accessTag || "designated" == accessTag) + if("yes" == accessTag || "designated" == accessTag) { w.access = true; - else if("no" == accessTag) { + } + if("no" == accessTag) { return true; } From 18abdd0cd614a230877ce17a909f2bcf187721de Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 6 Dec 2011 10:56:42 +0100 Subject: [PATCH 24/26] Fixes ticket 41. Speed is minimum of tagged maxspeed and definition from speedprofile.ini --- DataStructures/ExtractorCallBacks.h | 27 +++++++++++++++++---------- DataStructures/ExtractorStructs.h | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index eb394493d..d84a5ebfc 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -101,7 +101,7 @@ public: std::string oneway( w.keyVals.Find("oneway")); std::string junction( w.keyVals.Find("junction") ); std::string route( w.keyVals.Find("route") ); - double maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) ); + int maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) ); std::string access( w.keyVals.Find("access") ); std::string accessTag( w.keyVals.Find(settings.accessTag) ); std::string man_made( w.keyVals.Find("man_made") ); @@ -119,12 +119,17 @@ public: } //Is the highway tag listed as usable way? - if(0 < settings[highway]) { + if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) { - if(0 < maxspeed) - w.speed = maxspeed; - else - w.speed = settings[highway]; + if(0 < settings[highway]) { + if(0 < maxspeed) + w.speed = std::min(maxspeed, settings[highway]); + else + w.speed = settings[highway]; + } else { + w.speed = settings.defaultSpeed; + highway = "default"; + } w.useful = true; //Okay, do we have access to that way? @@ -135,9 +140,6 @@ public: } } - if("yes" == accessTag || "designated" == accessTag) { - w.access = true; - } if("no" == accessTag) { return true; } @@ -158,11 +160,16 @@ public: w.useful = true; w.speed = settings[route]; w.direction = _Way::bidirectional; + if(0 < settings[route]) + highway = route; + else if (0 < settings[man_made]) { + highway = man_made; + } } } if ( w.useful && w.access && (1 < w.path.size()) ) { //Only true if the way is specified by the speed profile //TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly? - w.type = 1; + w.type = settings.GetHighwayTypeID(highway); //Get the unique identifier for the street name const StringMap::const_iterator strit = stringMap->find(w.name); diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 864b05761..5abfd67cd 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -35,7 +35,8 @@ struct _PathData { short turnInstruction; }; -typedef boost::unordered_map StringMap; +typedef boost::unordered_map StringMap; +typedef boost::unordered_map > StringToIntPairMap; struct _Node : NodeInfo{ _Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {} @@ -254,19 +255,28 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta }; struct Settings { - Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar") {} - StringMap speedProfile; - int operator[](const string & param) const { + Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), excludeFromGrid("ferry") {} + StringToIntPairMap speedProfile; + int operator[](const std::string & param) const { if(speedProfile.find(param) == speedProfile.end()) return 0; else - return speedProfile.at(param); + return speedProfile.at(param).first; + } + int GetHighwayTypeID(const std::string & param) const { + if(speedProfile.find(param) == speedProfile.end()) { + DEBUG("There is a bug with highway \"" << param << "\""); + return -1; + } else { + return speedProfile.at(param).second; + } } bool obeyPollards; bool obeyOneways; bool useRestrictions; - string accessTag; - + std::string accessTag; + int defaultSpeed; + std::string excludeFromGrid; }; struct Cmp : public std::binary_function { From d81c632ef2fab9c4090535ca67edaa1ea74b4802 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 6 Dec 2011 11:36:16 +0100 Subject: [PATCH 25/26] Another changeset to reduce flickering --- DataStructures/NNGrid.h | 14 ++++++++++---- DataStructures/SearchEngine.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 93cdfb4b2..a446e20b7 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -304,18 +304,22 @@ public: _GridEdge smallestEdge; _Coordinate tmp, newEndpoint; - double dist = (numeric_limits::max)(); + double dist = numeric_limits::max(); BOOST_FOREACH(_GridEdge candidate, candidates) { double r = 0.; double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) { resultNode.weight2 = candidate.weight; +// INFO("b) " << candidate.edgeBasedNode << ", dist: " << tmpDist); if(candidate.edgeBasedNode < resultNode.edgeBasedNode) { resultNode.edgeBasedNode = candidate.edgeBasedNode; std::swap(resultNode.weight1, resultNode.weight2); } +// } else if(std::fabs(dist - tmpDist) < 1) { +// INFO("b) ignored " << candidate.edgeBasedNode << " at distance " << tmpDist); } if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) { +// INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist); resultNode.Reset(); resultNode.edgeBasedNode = candidate.edgeBasedNode; resultNode.nodeBasedEdgeNameID = candidate.nameID; @@ -326,6 +330,8 @@ public: foundNode = true; smallestEdge = candidate; newEndpoint = tmp; +// } else if(tmpDist < dist) { +// INFO("a) ignored " << candidate.edgeBasedNode << " at distance " << std::fabs(dist - tmpDist)); } } @@ -340,13 +346,13 @@ public: double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) ); assert(ratio >= 0 && ratio <=1); - // INFO("Old weight1: " << resultNode.weight1 << ", old weight2: " << resultNode.weight2); +// INFO("Old weight1: " << resultNode.weight1 << ", old weight2: " << resultNode.weight2); resultNode.weight1 *= ratio; if(INT_MAX != resultNode.weight2) { resultNode.weight2 *= (1-ratio); - // INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2); +// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2); } -// INFO("bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--") +// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--") return foundNode; } diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index c26eff91d..942927e90 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -91,14 +91,18 @@ public: //insert start and/or target node of start edge _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode, -phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.edgeBasedNode); +// INFO("a) forw insert " << phantomNodes.startPhantom.edgeBasedNode << ", weight: " << -phantomNodes.startPhantom.weight1); if(phantomNodes.startPhantom.isBidirected() ) { - _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1); +// INFO("b) forw insert " << phantomNodes.startPhantom.edgeBasedNode+1 << ", weight: " << -phantomNodes.startPhantom.weight2); + _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1); } //insert start and/or target node of target edge id - _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode); + _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode); +// INFO("c) back insert " << phantomNodes.targetPhantom.edgeBasedNode << ", weight: " << -phantomNodes.targetPhantom.weight2); if(phantomNodes.targetPhantom.isBidirected() ) { - _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode+1); - } + _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode+1); +// INFO("d) back insert " << phantomNodes.targetPhantom.edgeBasedNode+1 << ", weight: " << -phantomNodes.targetPhantom.weight1); + } while(_forwardHeap->Size() + _backwardHeap->Size() > 0){ if(_forwardHeap->Size() > 0){ From 3767ffd79ac8984df3648ffba61bf6e35ccd5c2e Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 6 Dec 2011 14:56:52 +0100 Subject: [PATCH 26/26] Forgotten in latest round of changes --- extractor.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/extractor.cpp b/extractor.cpp index a709016da..2ba0a35a3 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -102,7 +102,7 @@ int main (int argc, char *argv[]) { boost::property_tree::ptree pt; try { INFO("Loading speed profiles") - boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt); + boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt); INFO("Found the following speed profiles: "); int profileCounter(0); BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) { @@ -134,11 +134,20 @@ int main (int argc, char *argv[]) { if(name == "accessTag") { settings.accessTag = value; continue; + } else { + if(name == "excludeFromGrid") { + settings.excludeFromGrid = value; + } else { + if(name == "defaultSpeed") { + settings.defaultSpeed = atoi(value.c_str()); + settings.speedProfile["default"] = std::make_pair(settings.defaultSpeed, settings.speedProfile.size() ); + } + } } } } + settings.speedProfile[name] = std::make_pair(std::atoi(value.c_str()), settings.speedProfile.size() ); } - settings.speedProfile[name] = atoi(value.c_str()); } } catch(std::exception& e) { ERR("caught: " << e.what() ); @@ -189,7 +198,7 @@ int main (int argc, char *argv[]) { cout << "[extractor] parsing finished after " << get_timestamp() - time << " seconds" << endl; time = get_timestamp(); - boost::uint64_t memory_to_use = static_cast(amountOfRAM) * 1024 * 1024 * 1024; + boost::uint64_t memory_to_use = static_cast(amountOfRAM) * 1024 * 1024 * 1024; cout << "[extractor] Sorting used nodes ... " << flush; stxxl::sort(externalMemory.usedNodeIDs.begin(), externalMemory.usedNodeIDs.end(), Cmp(), memory_to_use); @@ -221,11 +230,11 @@ int main (int argc, char *argv[]) { while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) { if(wayStartAndEndEdgeIT->wayID < restrictionsIT->fromWay){ - ++wayStartAndEndEdgeIT; + ++wayStartAndEndEdgeIT; continue; } if(wayStartAndEndEdgeIT->wayID > restrictionsIT->fromWay) { - ++restrictionsIT; + ++restrictionsIT; continue; } assert(wayStartAndEndEdgeIT->wayID == restrictionsIT->fromWay); @@ -257,11 +266,11 @@ int main (int argc, char *argv[]) { wayStartAndEndEdgeIT = externalMemory.wayStartEndVector.begin(); while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) { if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){ - ++wayStartAndEndEdgeIT; + ++wayStartAndEndEdgeIT; continue; } if(wayStartAndEndEdgeIT->wayID > restrictionsIT->toWay) { - ++restrictionsIT; + ++restrictionsIT; continue; } NodeID viaNode = restrictionsIT->restriction.viaNode; @@ -276,9 +285,7 @@ int main (int argc, char *argv[]) { } if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { - ++usableRestrictionsCounter; - } else { - INFO("Restriction from: " << restrictionsIT->restriction.fromNode << ", to: " << restrictionsIT->restriction.toNode); + ++usableRestrictionsCounter; } ++restrictionsIT; } @@ -346,7 +353,7 @@ int main (int argc, char *argv[]) { STXXLEdgeVector::iterator edgeIT = externalMemory.allEdges.begin(); while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { if(edgeIT->start < nodesIT->id){ - ++edgeIT; + ++edgeIT; continue; } if(edgeIT->start > nodesIT->id) { @@ -374,11 +381,11 @@ int main (int argc, char *argv[]) { edgeIT = externalMemory.allEdges.begin(); while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { if(edgeIT->target < nodesIT->id){ - ++edgeIT; + ++edgeIT; continue; } if(edgeIT->target > nodesIT->id) { - ++nodesIT; + ++nodesIT; continue; } if(edgeIT->target == nodesIT->id) {