From f5226b222818f22a5fc37dcd61437f6b2c2f0307 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 16 Dec 2011 14:05:30 +0100 Subject: [PATCH] Certain type of edges, i.e. ferries, are now properly ignored from nearest neighbor lookup. Fixes ticket 59. --- Contractor/EdgeBasedGraphFactory.cpp | 6 +++++- Contractor/EdgeBasedGraphFactory.h | 4 +++- DataStructures/ExtractorCallBacks.h | 30 ++++++++++++++++------------ DataStructures/ExtractorStructs.h | 18 ++++++++++------- DataStructures/ImportEdge.h | 8 +++++--- DataStructures/NNGrid.h | 7 ++++--- Plugins/ObjectForPluginStruct.h | 19 +++++++++--------- Util/GraphLoader.h | 9 +++++---- createHierarchy.cpp | 2 +- extractor.cpp | 3 +-- 10 files changed, 61 insertions(+), 45 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 6d2c78558..efc683753 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -52,6 +52,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector 0 ); edge.data.shortcut = false; edge.data.roundabout = i->isRoundabout(); + edge.data.ignoreInGrid = i->ignoreInGrid(); edge.data.nameID = i->name(); edge.data.type = i->type(); edge.data.forward = i->isForward(); @@ -140,6 +141,7 @@ void EdgeBasedGraphFactory::Run() { currentNode.lat2 = inputNodeInfoList[v].lat; currentNode.lon2 = inputNodeInfoList[v].lon; currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID; + currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid; // short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. ); // short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. ); @@ -205,7 +207,7 @@ void EdgeBasedGraphFactory::Run() { EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); edgeBasedEdges.push_back(newEdge); - if(_nodeBasedGraph->GetEdgeData(e1).type != INT_MAX ) { + if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX ) { EdgeBasedNode currentNode; currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; currentNode.lat1 = inputNodeInfoList[u].lat; @@ -213,6 +215,8 @@ void EdgeBasedGraphFactory::Run() { currentNode.lat2 = inputNodeInfoList[v].lat; currentNode.lon2 = inputNodeInfoList[v].lon; currentNode.id = edgeBasedSource; + currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid; + // short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. ); // short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. ); // short heightDiff = startHeight - targetHeight; diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index cd210f5e2..162b3ac45 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -41,11 +41,12 @@ private: struct _NodeBasedEdgeData { int distance; unsigned edgeBasedNodeID; - unsigned nameID; + unsigned nameID:31; bool shortcut:1; bool forward:1; bool backward:1; bool roundabout:1; + bool ignoreInGrid:1; short type; } data; @@ -76,6 +77,7 @@ public: NodeID id; NodeID nameID; unsigned weight; + bool ignoreInGrid; }; private: diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index d84a5ebfc..1e844899c 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -118,6 +118,18 @@ public: w.roundabout = true; } + //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(0 < settings[route]) + highway = route; + else if (0 < settings[man_made]) { + highway = man_made; + } + } + //Is the highway tag listed as usable way? if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) { @@ -154,22 +166,14 @@ public: 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(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 = settings.GetHighwayTypeID(highway); + if(0 > w.type) { + ERR("Resolved highway " << highway << " to " << w.type); + } //Get the unique identifier for the street name const StringMap::const_iterator strit = stringMap->find(w.name); @@ -195,7 +199,7 @@ public: } 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->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid)); externalMemory->usedNodeIDs.push_back(w.path[n]); } externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]); diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 5da724183..c0d083baa 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -36,7 +36,7 @@ struct _PathData { }; typedef boost::unordered_map StringMap; -typedef boost::unordered_map > StringToIntPairMap; +typedef boost::unordered_map > StringToIntPairMap; struct _Node : NodeInfo{ _Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {} @@ -134,10 +134,12 @@ struct _Relation { }; struct _Edge { - _Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) {}; - _Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) { } - _Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false) { } - _Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra) { } + _Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) {}; + _Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) { } + _Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false) { } + _Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing) { + assert(0 <= type); + } NodeID start; NodeID target; short type; @@ -145,6 +147,7 @@ struct _Edge { double speed; unsigned nameID; bool isRoundabout; + bool ignoreInGrid; _Coordinate startCoord; _Coordinate targetCoord; @@ -265,10 +268,11 @@ struct Settings { } int GetHighwayTypeID(const std::string & param) const { if(param == excludeFromGrid) { - return INT_MAX; + return SHRT_MAX; } + assert(param != "ferry"); if(speedProfile.find(param) == speedProfile.end()) { - DEBUG("There is a bug with highway \"" << param << "\""); + ERR("There is a bug with highway \"" << param << "\""); return -1; } else { return speedProfile.at(param).second; diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 24e777826..f4fbe4f8c 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -42,10 +42,10 @@ public: /** Default constructor. target and weight are set to 0.*/ NodeBasedEdge() : - _source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false) { assert(false); } //shall not be used. + _source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false), _ignoreInGrid(false) { assert(false); } //shall not be used. - explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra) : - _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra) { assert(ty >= 0); } + explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig) : + _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig) { if(ty < 0) {ERR("Type: " << ty);}; } NodeID target() const {return _target; } NodeID source() const {return _source; } @@ -57,6 +57,7 @@ public: bool isForward() const { return forward; } bool isLocatable() const { return _type != 14; } bool isRoundabout() const { return _roundabout; } + bool ignoreInGrid() const { return _ignoreInGrid; } NodeID _source; NodeID _target; @@ -66,6 +67,7 @@ public: bool backward; short _type; bool _roundabout; + bool _ignoreInGrid; }; class EdgeBasedEdge { diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 50b32b4da..2886384a2 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -85,12 +85,13 @@ public: ramInFile.close(); } - template - void ConstructGrid(std::vector & edgeList, std::vector * int2ExtNodeMap, char * ramIndexOut, char * fileIndexOut) { + template + void ConstructGrid(std::vector & edgeList, char * ramIndexOut, char * fileIndexOut) { Percent p(edgeList.size()); BOOST_FOREACH(EdgeT & edge, edgeList) { p.printIncrement(); - + if(edge.ignoreInGrid) + continue; int slat = 100000*lat2y(edge.lat1/100000.); int slon = edge.lon1; int tlat = 100000*lat2y(edge.lat2/100000.); diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h index 10657e14e..89dc75d07 100644 --- a/Plugins/ObjectForPluginStruct.h +++ b/Plugins/ObjectForPluginStruct.h @@ -38,25 +38,24 @@ struct ObjectsForQueryStruct { QueryGraph * graph; ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") { - std::cout << "[objects] loading query data structures ..." << std::flush; - ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); + INFO("loading graph data"); + std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); //Deserialize road network graph std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrEdge> edgeList; const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList); graph = new QueryGraph(nodeList, edgeList); - INFO("Graph has " << graph->GetNumberOfNodes() << " nodes"); - INFO("Graph has " << graph->GetNumberOfEdges() << " edges"); - - - + assert(0 == nodeList.size()); + assert(0 == edgeList.size()); + INFO("Loading nearest neighbor indices"); //Init nearest neighbor data structure - ifstream nodesInStream(nodesPath.c_str(), ios::binary); + std::ifstream nodesInStream(nodesPath.c_str(), ios::binary); nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n); nodeHelpDesk->initNNGrid(nodesInStream); //deserialize street name list - ifstream namesInStream(namesPath.c_str(), ios::binary); + INFO("Loading names index"); + std::ifstream namesInStream(namesPath.c_str(), ios::binary); unsigned size(0); namesInStream.read((char *)&size, sizeof(unsigned)); names = new std::vector(); @@ -72,7 +71,7 @@ struct ObjectsForQueryStruct { } hsgrInStream.close(); namesInStream.close(); - std::cout << "ok" << std::endl; + INFO("All query data structures loaded"); } ~ObjectsForQueryStruct() { diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 54bd56e25..0c50b7104 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -142,7 +142,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto short type; NodeID nameID; int length; - bool isRoundabout; + bool isRoundabout, ignoreInGrid; for (EdgeID i=0; i& edgeList, vecto in.read((char*)&type, sizeof(short)); in.read((char*)&nameID, sizeof(unsigned)); in.read((char*)&isRoundabout, sizeof(bool)); + in.read((char*)&ignoreInGrid, sizeof(bool)); GUARANTEE(length > 0, "loaded null length edge" ); GUARANTEE(weight > 0, "loaded null weight"); @@ -163,6 +164,8 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto if (1 == dir) { backward = false; } if (2 == dir) { forward = false; } + assert(type >= 0); + // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { @@ -182,7 +185,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vecto target = intNodeID->second; GUARANTEE(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target"); - EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout ); + EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout, ignoreInGrid ); edgeList.push_back(inputEdge); } ext2IntNodeMap.clear(); @@ -358,7 +361,6 @@ template unsigned readHSGRFromStream(istream &in, vector& nodeList, vector & edgeList) { unsigned numberOfNodes = 0; in.read((char*) & numberOfNodes, sizeof(unsigned)); - INFO("Loading " << numberOfNodes << " nodes"); nodeList.resize(numberOfNodes); NodeT currentNode; for(unsigned nodeCounter = 0; nodeCounter < numberOfNodes; ++nodeCounter ) { @@ -368,7 +370,6 @@ unsigned readHSGRFromStream(istream &in, vector& nodeList, vector unsigned numberOfEdges = 0; in.read((char*) &numberOfEdges, sizeof(unsigned)); - INFO("Loading " << numberOfEdges << " edges"); edgeList.resize(numberOfEdges); EdgeT currentEdge; for(unsigned edgeCounter = 0; edgeCounter < numberOfEdges; ++edgeCounter) { diff --git a/createHierarchy.cpp b/createHierarchy.cpp index fc6bbacb8..d18897796 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -126,7 +126,7 @@ int main (int argc, char *argv[]) { WritableGrid * writeableGrid = new WritableGrid(); INFO("building grid ..."); - writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut); + writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut); DELETE( writeableGrid ); nodeBasedEdgeList.clear(); std::vector().swap(nodeBasedEdgeList); diff --git a/extractor.cpp b/extractor.cpp index e34037420..1c6679544 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -397,8 +397,6 @@ int main (int argc, char *argv[]) { double weight = ( distance * 10. ) / (edgeIT->speed / 3.6); int intWeight = max(1, (int) weight); int intDist = max(1, (int)distance); - int ferryIndex = settings["ferry"]; - assert(ferryIndex != -1); short zero = 0; short one = 1; @@ -429,6 +427,7 @@ int main (int argc, char *argv[]) { fout.write((char*)&edgeIT->type, sizeof(short)); fout.write((char*)&edgeIT->nameID, sizeof(unsigned)); fout.write((char*)&edgeIT->isRoundabout, sizeof(bool)); + fout.write((char*)&edgeIT->ignoreInGrid, sizeof(bool)); } ++usedEdgeCounter; ++edgeIT;