From 4e75bd1de62f8c7e5290f043d8cb4e45c7f511ce Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 24 Nov 2011 17:33:23 +0100 Subject: [PATCH] Start and target can be on same edge --- Contractor/EdgeBasedGraphFactory.cpp | 8 ++++++- DataStructures/ExtractorCallBacks.h | 2 ++ DataStructures/NNGrid.h | 3 +-- DataStructures/PhantomNodes.h | 7 +++--- DataStructures/SearchEngine.h | 34 ++++++++++++++++++---------- Descriptors/JSONDescriptor.h | 1 - Plugins/ViaRoutePlugin.h | 2 +- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index f5c2fcc48..ba3f0d21a 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -144,8 +144,14 @@ void EdgeBasedGraphFactory::Run() { _EdgeBasedEdge newEdge; newEdge.source = edgeBasedSource; newEdge.target = edgeBasedTarget; + //Todo: incorporate turn costs - newEdge.data.distance = _nodeBasedGraph->GetEdgeData(e1).distance; + /* double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); + double delta = std::min(_nodeBasedGraph->GetEdgeData(e1).distance, _nodeBasedGraph->GetEdgeData(e2).distance); + double radius = std::tan(angle/2.) * delta/2.; + double max_v = std::sqrt(0.31*radius); + */ + newEdge.data.distance = _nodeBasedGraph->GetEdgeData(e1).distance /*+ (int)max_v*/; newEdge.data.forward = true; newEdge.data.backward = false; newEdge.data.via = v; diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index c4b857663..5dfc69d96 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -33,6 +33,7 @@ typedef stxxl::vector STXXLStringVector; typedef stxxl::vector<_RawRestrictionContainer> STXXLRestrictionsVector; typedef stxxl::vector<_WayIDStartAndEndEdge> STXXLWayIDStartEndVector; + struct STXXLContainers { STXXLNodeIDVector usedNodeIDs; STXXLNodeVector allNodes; @@ -104,6 +105,7 @@ public: 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() ) diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 0922d88fb..90e149041 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -307,7 +307,6 @@ public: 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.isBidirected = true; resultNode.weight2 = candidate.weight; /* if(resultNode.weight1 != resultNode.weight2) { ERR("w1: " << resultNode.weight1 << ", w2: " << resultNode.weight2); @@ -345,7 +344,7 @@ public: assert(ratio >= 0 && ratio <=1); // INFO("Old weight1: " << resultNode.weight1 << ", old weight2: " << resultNode.weight2); resultNode.weight1 *= ratio; - if(resultNode.isBidirected) { + if(INT_MAX != resultNode.weight2) { resultNode.weight2 *= (1-ratio); // INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2); } diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index a7265026f..76ba93e1d 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -24,21 +24,22 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorStructs.h" struct PhantomNode { - PhantomNode() : isBidirected(false), edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX) {} - bool isBidirected; + PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX) {} NodeID edgeBasedNode; unsigned nodeBasedEdgeNameID; int weight1; int weight2; _Coordinate location; void Reset() { - isBidirected = false; edgeBasedNode = UINT_MAX; nodeBasedEdgeNameID = UINT_MAX; weight1 = INT_MAX; weight2 = INT_MAX; location.Reset(); } + bool isBidirected() const { + return weight2 != INT_MAX; + } }; struct PhantomNodes { diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 25cbde1ec..baaa33ef0 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -95,24 +95,35 @@ public: InitializeThreadLocalStorageIfNecessary(); NodeID middle = ( NodeID ) UINT_MAX; + + //Handling the special case that origin and destination are on same edge and that the order is correct. if(phantomNodes.PhantomsAreOnSameNodeBasedEdge()){ - //TODO: Hier behandeln, dass Start und Ziel auf der gleichen Originalkante liegen - INFO("TODO: Start and target are on same edge") - return _upperbound; + INFO("TODO: Start and target are on same edge, bidirected: " << (phantomNodes.startPhantom.isBidirected() && phantomNodes.targetPhantom.isBidirected() ? "yes": "no")); + + if(phantomNodes.startPhantom.isBidirected() && phantomNodes.targetPhantom.isBidirected()) { + //TODO: Hier behandeln, dass Start und Ziel auf der gleichen Originalkante liegen + int weight = std::abs(phantomNodes.startPhantom.weight1 - phantomNodes.targetPhantom.weight1); + INFO("Weight is : " << weight); + return weight; + } else if(phantomNodes.startPhantom.weight1 <= phantomNodes.targetPhantom.weight1){ + int weight = std::abs(phantomNodes.startPhantom.weight1 - phantomNodes.targetPhantom.weight1); + INFO("Weight is : " << weight); + return weight; + } } + double time1 = get_timestamp(); //insert start and/or target node of start edge _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode, -phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.edgeBasedNode); // INFO("[FORW] Inserting node " << phantomNodes.startPhantom.edgeBasedNode << " at distance " << -phantomNodes.startPhantom.weight1); - if(phantomNodes.startPhantom.isBidirected) { + if(phantomNodes.startPhantom.isBidirected() ) { _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1); - // INFO("[FORW] Inserting node " << phantomNodes.startPhantom.edgeBasedNode+1 << " at distance " << -phantomNodes.startPhantom.weight2); + // INFO("[FORW] Inserting node " << phantomNodes.startPhantom.edgeBasedNode+1 << " at distance " << -phantomNodes.startPhantom.weight2); } - //insert start and/or target node of target edge id _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode); // INFO("[BACK] Inserting node " << phantomNodes.targetPhantom.edgeBasedNode << " at distance " << -phantomNodes.targetPhantom.weight1); - if(phantomNodes.targetPhantom.isBidirected) { + if(phantomNodes.targetPhantom.isBidirected() ) { _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode+1); // INFO("[BACK] Inserting node " << phantomNodes.targetPhantom.edgeBasedNode+1 << " at distance " << -phantomNodes.targetPhantom.weight2); } @@ -132,14 +143,14 @@ public: } NodeID pathNode = middle; deque packedPath; - while(phantomNodes.startPhantom.edgeBasedNode != pathNode && (!phantomNodes.startPhantom.isBidirected || phantomNodes.startPhantom.edgeBasedNode+1 != pathNode) ) { + while(phantomNodes.startPhantom.edgeBasedNode != pathNode && (!phantomNodes.startPhantom.isBidirected() || phantomNodes.startPhantom.edgeBasedNode+1 != pathNode) ) { pathNode = _forwardHeap->GetData(pathNode).parent; packedPath.push_front(pathNode); } // INFO("Finished getting packed forward path: " << packedPath.size()); packedPath.push_back(middle); pathNode = middle; - while(phantomNodes.targetPhantom.edgeBasedNode != pathNode && (!phantomNodes.targetPhantom.isBidirected || phantomNodes.targetPhantom.edgeBasedNode+1 != pathNode)) { + while(phantomNodes.targetPhantom.edgeBasedNode != pathNode && (!phantomNodes.targetPhantom.isBidirected() || phantomNodes.targetPhantom.edgeBasedNode+1 != pathNode)) { pathNode = _backwardHeap->GetData(pathNode).parent; packedPath.push_back(pathNode); } @@ -226,8 +237,7 @@ private: inline void _RoutingStep(HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, const bool & forwardDirection, NodeID *middle, int *_upperbound) { const NodeID node = _forwardHeap->DeleteMin(); const int distance = _forwardHeap->GetKey(node); - // INFO((forwardDirection ? "[FORW]" : "[BACK]") << " settling " << node << " with distance " << distance); - if(_backwardHeap->WasInserted(node)){ + if(_backwardHeap->WasInserted(node) && (distance > 0) ){ const int newDistance = _backwardHeap->GetKey(node) + distance; if(newDistance < *_upperbound){ *middle = node; @@ -287,7 +297,7 @@ private: const NodeID node = _forwardHeap->DeleteMin(); stats.deleteMins++; const unsigned int distance = _forwardHeap->GetKey(node); - if(_backwardHeap->WasInserted(node)){ + if(_backwardHeap->WasInserted(node) && (distance > 0)){ const unsigned int newDistance = _backwardHeap->GetKey(node) + distance; if(newDistance < *_upperbound){ *middle = node; diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 65dde85ec..4fe37108e 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -116,7 +116,6 @@ public: reply.content += ","; reply.content += "[\""; - INFO("Instruction: " << segment.turnInstruction); if(TurnInstructions.LeaveRoundAbout == segment.turnInstruction) { reply.content += TurnInstructions.TurnStrings[TurnInstructions.EnterRoundAbout]; reply.content += " and leave at "; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 0be7e839d..4172214b0 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -139,7 +139,7 @@ public: std::vector< _PathData > path; distance = searchEngine->ComputeRoute(segmentPhantomNodes, path); - if(UINT_MAX == distance ) { + if(INT_MAX == distance ) { INFO( "Error occurred, single path not found" ); }