From cb6104e0acd16aa9f5afc2f7fa708cdbe2512969 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 17 Dec 2012 13:17:35 +0100 Subject: [PATCH] Using vector instead of deque for path unpacking --- RoutingAlgorithms/AlternativePathRouting.h | 18 +++++++++--------- RoutingAlgorithms/BasicRoutingInterface.h | 8 +++++--- RoutingAlgorithms/ShortestPathRouting.h | 8 ++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 2f07f33ad..b55d1a9aa 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -59,7 +59,7 @@ public: std::vector alternativePath; std::vector viaNodeCandidates; - std::deque packedShortestPath; + std::vector packedShortestPath; std::vector nodesThatPassPreselection; HeapPtr & forwardHeap = super::_queryData.forwardHeap; @@ -161,7 +161,7 @@ private: inline void retrievePackedViaPath(const HeapPtr & _forwardHeap1, const HeapPtr & _backwardHeap1, const HeapPtr & _forwardHeap2, const HeapPtr & _backwardHeap2, const NodeID s_v_middle, const NodeID v_t_middle, std::vector<_PathData> & unpackedPath) { //unpack [s,v) - std::deque packed_s_v_path, packed_v_t_path; + std::vector packed_s_v_path, packed_v_t_path; super::RetrievePackedPathFromHeap(_forwardHeap1, _backwardHeap2, s_v_middle, packed_s_v_path); packed_s_v_path.resize(packed_s_v_path.size()-1); //unpack [v,t] @@ -171,7 +171,7 @@ private: } inline void computeLengthAndSharingOfViaPath(const PreselectedNode& node, int *lengthOfViaPath, int *sharingOfViaPath, - const int offset, const std::deque & packedShortestPath) { + const int offset, const std::vector & packedShortestPath) { //compute and unpack and by exploring search spaces from v and intersecting against queues //only half-searches have to be done at this stage super::_queryData.InitializeOrClearSecondThreadLocalStorage(); @@ -181,8 +181,8 @@ private: HeapPtr & newForwardHeap = super::_queryData.forwardHeap2; HeapPtr & newBackwardHeap = super::_queryData.backwardHeap2; - std::deque < NodeID > packed_s_v_path; - std::deque < NodeID > packed_v_t_path; + std::vector < NodeID > packed_s_v_path; + std::vector < NodeID > packed_v_t_path; std::vector partiallyUnpackedShortestPath; std::vector partiallyUnpackedViaPath; @@ -258,8 +258,8 @@ private: //finished partial unpacking spree! Amount of sharing is stored to appropriate poiner variable } - inline int approximateAmountOfSharing(const NodeID middleNodeIDOfAlternativePath, HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, const std::deque & packedShortestPath) { - std::deque packedAlternativePath; + inline int approximateAmountOfSharing(const NodeID middleNodeIDOfAlternativePath, HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, const std::vector & packedShortestPath) { + std::vector packedAlternativePath; super::RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middleNodeIDOfAlternativePath, packedAlternativePath); if(packedShortestPath.size() < 2 || packedAlternativePath.size() < 2) @@ -336,8 +336,8 @@ private: //conduct T-Test inline bool viaNodeCandidatePasses_T_Test( HeapPtr& existingForwardHeap, HeapPtr& existingBackwardHeap, HeapPtr& newForwardHeap, HeapPtr& newBackwardHeap, const RankedCandidateNode& candidate, const int offset, const int lengthOfShortestPath, int * lengthOfViaPath, NodeID * s_v_middle, NodeID * v_t_middle) { - std::deque < NodeID > packed_s_v_path; - std::deque < NodeID > packed_v_t_path; + std::vector < NodeID > packed_s_v_path; + std::vector < NodeID > packed_v_t_path; super::_queryData.InitializeOrClearSecondThreadLocalStorage(); *s_v_middle = UINT_MAX; diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 01066b524..bbe0474e4 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -104,7 +104,7 @@ public: } } - inline void UnpackPath(std::deque & packedPath, std::vector<_PathData> & unpackedPath) const { + inline void UnpackPath(std::vector & packedPath, std::vector<_PathData> & unpackedPath) const { const unsigned sizeOfPackedPath = packedPath.size(); std::stack > recursionStack; @@ -204,13 +204,15 @@ public: unpackedPath.push_back(t); } - inline void RetrievePackedPathFromHeap(const typename QueryDataT::HeapPtr & _fHeap, const typename QueryDataT::HeapPtr & _bHeap, const NodeID middle, std::deque& packedPath) { + inline void RetrievePackedPathFromHeap(const typename QueryDataT::HeapPtr & _fHeap, const typename QueryDataT::HeapPtr & _bHeap, const NodeID middle, std::vector& packedPath) { NodeID pathNode = middle; while(pathNode != _fHeap->GetData(pathNode).parent) { pathNode = _fHeap->GetData(pathNode).parent; - packedPath.push_front(pathNode); + packedPath.push_back(pathNode); } + std::reverse(packedPath.begin(), packedPath.end()); + packedPath.push_back(middle); pathNode = middle; while (pathNode != _bHeap->GetData(pathNode).parent){ diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index da553f616..6fc4c5996 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -47,8 +47,8 @@ public: bool searchFrom2ndStartNode(true); NodeID middle1 = ( NodeID ) UINT_MAX; NodeID middle2 = ( NodeID ) UINT_MAX; - std::deque packedPath1; - std::deque packedPath2; + std::vector packedPath1; + std::vector packedPath2; typename QueryDataT::HeapPtr & forwardHeap = super::_queryData.forwardHeap; typename QueryDataT::HeapPtr & backwardHeap = super::_queryData.backwardHeap; @@ -141,8 +141,8 @@ public: // INFO("middle1: " << middle1); //Unpack paths if they exist - std::deque temporaryPackedPath1; - std::deque temporaryPackedPath2; + std::vector temporaryPackedPath1; + std::vector temporaryPackedPath2; if(INT_MAX != _localUpperbound1) { super::RetrievePackedPathFromHeap(forwardHeap, backwardHeap, middle1, temporaryPackedPath1); // INFO("temporaryPackedPath1 ends with " << *(temporaryPackedPath1.end()-1) );