From 683dbb42d9e13f58504cfc8e02d6139597839bcc Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sun, 4 Dec 2011 22:19:16 +0100 Subject: [PATCH 01/12] improved parsing of some osm tags --- DataStructures/ExtractorCallBacks.h | 142 ++++++++++++++-------------- Rakefile | 12 +-- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 0face8d56..3ca24974d 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -93,75 +93,78 @@ public: /** warning: caller needs to take care of synchronization! */ inline bool wayFunction(_Way &w) { - - //Get the properties of the way. - std::string highway( w.keyVals.Find("highway") ); - std::string name( w.keyVals.Find("name") ); - std::string ref( w.keyVals.Find("ref")); - 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()) ); - std::string access( w.keyVals.Find("access") ); + std::string accessClass( w.keyVals.Find(settings.accessTag) ); - std::string man_made( w.keyVals.Find("man_made") ); - std::string barrier( w.keyVals.Find("barrier") ); - - //Save the name of the way if it has one, ref has precedence over name tag. - if ( 0 < ref.length() ) - w.name = ref; - else - if ( 0 < name.length() ) - w.name = name; - - if(junction == "roundabout") { - w.roundabout = true; - } - - //Is the highway tag listed as usable way? - if(0 < settings[highway]) { - - if(0 < maxspeed) - w.speed = maxspeed; - else - w.speed = settings[highway]; - w.useful = true; - - //Okay, do we have access to that way? - if(0 < access.size()) { //fastest way to check for non-empty string - //If access is forbidden, we don't want to route there. - if(access == "private" || access == "no" || access == "agricultural" || access == "forestry" || access == "delivery") { //Todo: this is still hard coded - w.access = false; - } - } - - if("yes" == accessClass || "designated" == accessClass) - w.access = true; - else if("no" == accessClass) - w.access = false; - - //Let's process oneway property, if speed profile obeys to it - if(oneway != "no" && oneway != "false" && oneway != "0" && settings.obeyOneways) { - //if oneway tag is in forward direction or if actually roundabout - if(junction == "roundabout" || oneway == "yes" || oneway == "true" || oneway == "1") { - w.direction = _Way::oneway; - } else { - if( oneway == "-1") - w.direction = _Way::opposite; - } - } - } else { - //Is the route tag listed as usable way in the profile? - if(settings[route] > 0 || settings[man_made] > 0) { - w.useful = true; - w.speed = settings[route]; - w.direction = _Way::bidirectional; - } - } - 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? + std::string access( w.keyVals.Find("access") ); + std::string highway( w.keyVals.Find("highway") ); + + //class tag like bicycle=yes/no overrides everything else + if("yes" == accessClass || "permissive" == accessClass || "designated" == accessClass || "official" == accessClass) + w.access = true; + else if("no" == accessClass) + w.access = false; + else { + std::string route( w.keyVals.Find("route") ); + std::string man_made( w.keyVals.Find("man_made") ); + //speedprofile allows routing on this type of way/route/man_made? + if(settings[highway] > 0 || settings[route] > 0 || settings[man_made] > 0) { + if(0 < access.size()) { //fastest way to check for non-empty string + if( access == "yes" || access == "permissive" || access == "designated" || access == "public" ) + w.access = true; + else + w.access = false; + } + } + else + w.access = false; + } + + if ( w.access == true && (1 < w.path.size()) ) { + std::string name( w.keyVals.Find("name") ); + std::string ref( w.keyVals.Find("ref")); + std::string oneway( w.keyVals.Find("oneway")); + std::string onewayClass( w.keyVals.Find("oneway:"+accessClass)); + std::string junction( w.keyVals.Find("junction") ); + double maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) ); + std::string barrier( w.keyVals.Find("barrier") ); + + //name + if ( 0 < ref.length() ) + w.name = ref; + else if ( 0 < name.length() ) + w.name = name; + + //roundabout + if(junction == "roundabout") + w.roundabout = true; + + //speed + if(0 < maxspeed && (maxspeed < settings[highway]) ) + w.speed = maxspeed; + else + w.speed = settings[highway]; + + //TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly? w.type = 1; + //oneway + if( settings.obeyOneways ) { + //TODO: handle cycleway=opposite_* + if( oneway == "no" || oneway == "0" || oneway == "false" || + onewayClass == "no" || onewayClass == "0" || onewayClass == "false") + w.direction = _Way::bidirectional; + else if( oneway == "yes" || oneway == "1" || oneway == "true" || + onewayClass == "yes" || onewayClass == "1" || onewayClass == "true" || + junction == "roundabout" || highway == "motorway_link" || highway == "motorway" ) + w.direction = _Way::oneway; + else if( oneway == "-1") { + w.direction = _Way::opposite; + std::reverse( w.path.begin(), w.path.end() ); + } + else + w.direction = _Way::bidirectional; + } + //Get the unique identifier for the street name const StringMap::const_iterator strit = stringMap->find(w.name); if(strit == stringMap->end()) { @@ -172,7 +175,7 @@ public: w.nameID = strit->second; } - if(-1 == w.speed){ + if(-1 == w.speed) { WARN("found way with bogus speed, id: " << w.id); return true; } @@ -181,10 +184,6 @@ public: return true; } - if ( w.direction == _Way::opposite ){ - std::reverse( w.path.begin(), w.path.end() ); - } - for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) { externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout)); externalMemory->usedNodeIDs.push_back(w.path[n]); @@ -194,6 +193,7 @@ public: //The following information is needed to identify start and end segments of restrictions externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(w.id, w.path[0], w.path[1], w.path[w.path.size()-2], w.path[w.path.size()-1])); } + return true; } }; diff --git a/Rakefile b/Rakefile index e28fec545..d7fd2d11d 100644 --- a/Rakefile +++ b/Rakefile @@ -6,20 +6,20 @@ task :default => [:compile, :process, :run] desc "Compile" task :compile do - system "scons" + raise "Error while building." unless system "scons" end file "#{sandbox}/amager.osm.pbf" => "amager.osm.pbf" do |t| - system "cp #{t.prerequisites.join} #{t.name}" + raise unless system "cp #{t.prerequisites.join} #{t.name}" end desc "Reprocess OSM test data" task :process => ["#{sandbox}/amager.osm.pbf", :setup] do prev = Dir.pwd cd sandbox #we must be in the sandbox folder to use the speedprofile.ini in that folder - system "./osrm-extract amager.osm.pbf" - system "./osrm-prepare amager.osrm amager.osrm.restrictions" + raise "Error while extracting data." unless system "./osrm-extract amager.osm.pbf" + raise "Error while preparing data." unless system "./osrm-prepare amager.osrm amager.osrm.restrictions" cd prev end @@ -27,11 +27,11 @@ desc "Setup server files" task :setup => ["#{sandbox}/speedprofile.ini", "#{sandbox}/extractor.ini", "#{sandbox}/server.ini"] file "#{sandbox}/speedprofile.ini" => "speedprofile.ini" do |t| - system "cp #{t.prerequisites.join} #{t.name}" + raise unless system "cp #{t.prerequisites.join} #{t.name}" end file "#{sandbox}/extractor.ini" => "extractor.ini" do |t| - system "cp #{t.prerequisites.join} #{t.name}" + raise unless system "cp #{t.prerequisites.join} #{t.name}" end file "#{sandbox}/server.ini" => "server.ini" do |t| From 045922fb56c35368e70ccce6961f80ba86eb6d35 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Dec 2011 14:45:45 +0100 Subject: [PATCH 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 09/12] 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 39872e9867a85652a718671e8a474d0a89a3b716 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 6 Dec 2011 13:52:39 +0100 Subject: [PATCH 10/12] rake task for downloading osm data --- Rakefile | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Rakefile b/Rakefile index d7fd2d11d..c1a3a1fe3 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ sandbox = "sandbox" #where to locate builds, server configs and test data osm_data = "amager" #name of OSM data file desc "Recompile, reprocess OSM data and run server" -task :default => [:compile, :process, :run] +task :default => [:compile, "data:process", :run] desc "Compile" task :compile do @@ -14,13 +14,26 @@ file "#{sandbox}/amager.osm.pbf" => "amager.osm.pbf" do |t| raise unless system "cp #{t.prerequisites.join} #{t.name}" end -desc "Reprocess OSM test data" -task :process => ["#{sandbox}/amager.osm.pbf", :setup] do - prev = Dir.pwd - cd sandbox #we must be in the sandbox folder to use the speedprofile.ini in that folder - raise "Error while extracting data." unless system "./osrm-extract amager.osm.pbf" - raise "Error while preparing data." unless system "./osrm-prepare amager.osrm amager.osrm.restrictions" - cd prev +namespace :data do + desc "Reprocess OSM test data" + task :process => ["#{sandbox}/amager.osm.pbf", :setup] do + prev = Dir.pwd + cd sandbox #we must be in the sandbox folder to use the speedprofile.ini in that folder + raise "Error while extracting data." unless system "./osrm-extract amager.osm.pbf" + raise "Error while preparing data." unless system "./osrm-prepare amager.osrm amager.osrm.restrictions" + cd prev + end + + desc "Download fresh OSM for the test data" + task :download => :setup do + start = Time.now + country = 'denmark' + bbox = 'top=55.6655 left=12.5589 bottom=55.6462 right=12.5963' + area = 'amager' + + raise "Error while downloading data." unless system "curl http://download.geofabrik.de/osm/europe/#{country}.osm.pbf -o #{sandbox}/#{country}.osm.pbf" + raise "Error while cropping data." unless system "osmosis --read-pbf file=#{sandbox}/#{country}.osm.pbf --bounding-box #{bbox} --write-pbf file=#{sandbox}/#{area}.osm.pbf omitmetadata=true" + end end desc "Setup server files" From 3767ffd79ac8984df3648ffba61bf6e35ccd5c2e Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 6 Dec 2011 14:56:52 +0100 Subject: [PATCH 11/12] 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) { From c79a7f469fbe681132bd6e43cba789d181cf20ec Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 6 Dec 2011 15:05:14 +0100 Subject: [PATCH 12/12] updated scons script --- SConstruct | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 21022ac5b..a6a6423b3 100644 --- a/SConstruct +++ b/SConstruct @@ -74,15 +74,20 @@ else: if sys.platform == 'darwin': #Mac OS X env.Append(CPPPATH = ['/usr/include/libxml2'] ) #comes with os x - #assume stxxl and boost are installed via homebrew. - #call out to brew to get the folder locations + #assume dependencies are installed with homebrew, and call out get folder locations import subprocess stxxl_prefix = subprocess.check_output(["brew", "--prefix", "libstxxl"]).strip() - boost_prefix = subprocess.check_output(["brew", "--prefix", "boost"]).strip() env.Append(CPPPATH = [stxxl_prefix+"/include"] ) env.Append(LIBPATH = [stxxl_prefix+"/lib"] ) + + boost_prefix = subprocess.check_output(["brew", "--prefix", "boost"]).strip() env.Append(CPPPATH = [boost_prefix+"/include"] ) env.Append(LIBPATH = [boost_prefix+"/lib"] ) + + #libxml2_prefix = subprocess.check_output(["brew", "--prefix", "libxml2"]).strip() + #env.Append(CPPPATH = [libxml2_prefix+"/include"] ) + #env.Append(LIBPATH = [libxml2_prefix+"/lib"] ) + elif sys.platform.startswith("freebsd"): env.ParseConfig('pkg-config --cflags --libs protobuf') env.Append(CPPPATH = ['/usr/local/include', '/usr/local/include/libxml2']) @@ -105,9 +110,11 @@ else: env.Append(CPPPATH = ['/usr/include', '/usr/include/include', '/usr/include/libxml2/']) -if not conf.CheckHeader('omp.h'): - print "Compiler does not support OpenMP. Exiting" - Exit(-1) +if sys.platform != 'darwin': + if not conf.CheckHeader('omp.h'): + print "Compiler does not support OpenMP. Exiting" + Exit(-1) + if not conf.CheckLibWithHeader('xml2', 'libxml/xmlreader.h', 'CXX'): print "libxml2 library or header not found. Exiting" Exit(-1)