diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index 2486a8e40..e2b75e1ae 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 ); } }; @@ -145,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; @@ -165,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++ ) { @@ -203,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 ) @@ -211,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 ) { @@ -224,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 ) { @@ -232,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 ); @@ -257,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/Contractor.h b/Contractor/Contractor.h index 9daa36865..c8d9568e8 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; @@ -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 ); diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index e7499c722..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(); @@ -99,40 +99,78 @@ 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 ) { //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) { ++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); + } + 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 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(u == restrictionIterator->fromNode) { + 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,12 +183,12 @@ 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; - 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; diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 5dfc69d96..d84a5ebfc 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -101,9 +101,9 @@ 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 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") ); @@ -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,10 +140,9 @@ public: } } - if("yes" == accessClass) - w.access = true; - else if("no" == accessClass) - w.access = false; + 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) { @@ -154,17 +158,21 @@ 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; + 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 - 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); @@ -173,8 +181,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() ); diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 0f5ead963..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) {} @@ -64,6 +65,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){ @@ -177,10 +185,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 +241,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; @@ -247,19 +255,28 @@ struct CmpWayStartAndEnd : public std::binary_function<_WayIDStartAndEndEdge, _W }; 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 { 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 { diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index a83248a5b..a446e20b7 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -304,22 +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; - /* if(resultNode.weight1 != resultNode.weight2) { - ERR("w1: " << resultNode.weight1 << ", w2: " << resultNode.weight2); - assert(false); - }*/ +// 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) { + if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) { +// INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist); resultNode.Reset(); resultNode.edgeBasedNode = candidate.edgeBasedNode; resultNode.nodeBasedEdgeNameID = candidate.nameID; @@ -330,26 +330,29 @@ public: foundNode = true; smallestEdge = candidate; newEndpoint = tmp; +// } else if(tmpDist < dist) { +// INFO("a) ignored " << candidate.edgeBasedNode << " at distance " << std::fabs(dist - tmpDist)); } } - // 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); - // 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("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--") return foundNode; } @@ -412,7 +415,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 ) { @@ -551,6 +554,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/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index a211cb6e9..ef0e4a4f2 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. diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 26da8fc28..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){ @@ -256,7 +260,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; } } 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; } 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/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 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 diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index e1d4d9464..30074d577 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,8 +103,8 @@ 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;) - 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); 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; } @@ -148,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) { cerr << "loaded null length edge" << endl; exit(1); } - // 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,20 +175,19 @@ 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); } + 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 @@ -204,17 +197,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 +280,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 +322,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 +333,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/createHierarchy.cpp b/createHierarchy.cpp index f2a1be972..4e3c5d655 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,11 +61,10 @@ 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); + std::ifstream restrictionsInstream(argv[2], ios::binary); _Restriction restriction; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); @@ -83,36 +83,24 @@ 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]; - 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); @@ -132,24 +120,24 @@ 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); + nodeBasedEdgeList.clear(); + std::vector().swap(nodeBasedEdgeList); - 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 +148,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; } diff --git a/extractor.cpp b/extractor.cpp index d919ba897..2ba0a35a3 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,25 +96,25 @@ int main (int argc, char *argv[]) { restrictionsFileName.append(".osrm.restrictions"); } } - string adressFileName(outputFileName); + std::string adressFileName(outputFileName); Settings settings; 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("")) { - 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") @@ -137,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() ); @@ -150,23 +156,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 +182,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 { @@ -198,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); @@ -217,7 +217,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; @@ -230,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); @@ -264,14 +264,13 @@ 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; + ++wayStartAndEndEdgeIT; continue; } if(wayStartAndEndEdgeIT->wayID > restrictionsIT->toWay) { - ++restrictionsIT; + ++restrictionsIT; continue; } NodeID viaNode = restrictionsIT->restriction.viaNode; @@ -286,12 +285,12 @@ int main (int argc, char *argv[]) { } if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { - ++usableRestrictionsCounter; + ++usableRestrictionsCounter; } ++restrictionsIT; } - cout << "ok, after " << get_timestamp() - time << "s" << endl; + INFO("usable restrictions: " << usableRestrictionsCounter); //serialize restrictions ofstream restrictionsOutstream; restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary); @@ -354,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) { @@ -382,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) { diff --git a/typedefs.h b/typedefs.h index 9dacefff2..0fd300f4f 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 @@ -41,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);