From 0cabc8169326ab229f1ecc039f1b23f5d286564e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 11:09:07 +0200 Subject: [PATCH] Reworking data access to go always through facades --- DataStructures/SearchEngine.h | 1 - Descriptors/JSONDescriptor.h | 2 +- Plugins/ViaRoutePlugin.h | 10 ++-- RoutingAlgorithms/AlternativePathRouting.h | 66 ++++++++++++---------- RoutingAlgorithms/BasicRoutingInterface.h | 52 ++++++++--------- RoutingAlgorithms/ShortestPathRouting.h | 10 ++-- 6 files changed, 73 insertions(+), 68 deletions(-) diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index f73624cd9..894ea8715 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -50,7 +50,6 @@ public: SearchEngine( DataFacadeT * facade ) : facade (facade), - engine_working_data(facade), shortest_path (facade, engine_working_data), alternative_path (facade, engine_working_data) {} diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 518f82e57..62fda69cb 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -73,7 +73,7 @@ public: JSONDescriptor() : entered_restricted_area_count(0) {} void SetConfig(const DescriptorConfig & c) { config = c; } - //TODO: reorder + //TODO: reorder parameters void Run( http::Reply & reply, const RawRouteData & raw_route_information, diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index e36549448..598d67c1d 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -115,12 +115,12 @@ public: ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) { - search_engine_ptr->alternativePaths( + search_engine_ptr->alternative_paths( rawRoute.segmentEndCoordinates[0], rawRoute ); } else { - search_engine_ptr->shortestPath( + search_engine_ptr->shortest_path( rawRoute.segmentEndCoordinates, rawRoute ); @@ -139,16 +139,16 @@ public: reply.content += "("; } - _DescriptorConfig descriptorConfig; + DescriptorConfig descriptorConfig; unsigned descriptorType = 0; if(descriptorTable.find(routeParameters.outputFormat) != descriptorTable.end() ) { descriptorType = descriptorTable.find(routeParameters.outputFormat)->second; } - descriptorConfig.z = routeParameters.zoomLevel; + descriptorConfig.zoom_level = routeParameters.zoomLevel; descriptorConfig.instructions = routeParameters.printInstructions; descriptorConfig.geometry = routeParameters.geometry; - descriptorConfig.encodeGeometry = routeParameters.compression; + descriptorConfig.encode_geometry = routeParameters.compression; switch(descriptorType){ case 0: diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 49c935604..96c0a3737 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -47,12 +47,18 @@ class AlternativeRouting : private BasicRoutingInterface { return (2*length + sharing) < (2*other.length + other.sharing); } }; - - const SearchGraph * search_graph; + DataFacadeT * facade; SearchEngineData & engine_working_data; public: - AlternativeRouting(DataFacadeT & qd, SearchEngineData & engine_working_data) : super(qd), search_graph(qd.graph), engine_working_data(engine_working_data) { } + AlternativeRouting( + DataFacadeT * facade, + SearchEngineData & engine_working_data + ) : + super(facade), + facade(facade), + engine_working_data(engine_working_data) + { } ~AlternativeRouting() {} @@ -252,8 +258,8 @@ private: //First partially unpack s-->v until paths deviate, note length of common path. for (unsigned i = 0, lengthOfPackedPath = std::min( packed_s_v_path.size(), packed_shortest_path.size()) - 1; (i < lengthOfPackedPath); ++i) { if (packed_s_v_path[i] == packed_shortest_path[i] && packed_s_v_path[i + 1] == packed_shortest_path[i + 1]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packed_s_v_path[i], packed_s_v_path[i + 1]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packed_s_v_path[i], packed_s_v_path[i + 1]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { if (packed_s_v_path[i] == packed_shortest_path[i]) { super::UnpackEdge(packed_s_v_path[i], packed_s_v_path[i+1], partiallyUnpackedViaPath); @@ -264,8 +270,8 @@ private: } //traverse partially unpacked edge and note common prefix for (int i = 0, lengthOfPackedPath = std::min( partiallyUnpackedViaPath.size(), partiallyUnpackedShortestPath.size()) - 1; (i < lengthOfPackedPath) && (partiallyUnpackedViaPath[i] == partiallyUnpackedShortestPath[i] && partiallyUnpackedViaPath[i+1] == partiallyUnpackedShortestPath[i+1]); ++i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } //Second, partially unpack v-->t in reverse order until paths deviate and note lengths @@ -273,8 +279,8 @@ private: int shortestPathIndex = packed_shortest_path.size() - 1; for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex ) { if (packed_v_t_path[viaPathIndex - 1] == packed_shortest_path[shortestPathIndex - 1] && packed_v_t_path[viaPathIndex] == packed_shortest_path[shortestPathIndex]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_v_t_path[viaPathIndex - 1], packed_v_t_path[viaPathIndex]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[viaPathIndex - 1], packed_v_t_path[viaPathIndex]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { if (packed_v_t_path[viaPathIndex] == packed_shortest_path[shortestPathIndex]) { super::UnpackEdge(packed_v_t_path[viaPathIndex-1], packed_v_t_path[viaPathIndex], partiallyUnpackedViaPath); @@ -288,8 +294,8 @@ private: shortestPathIndex = partiallyUnpackedShortestPath.size() - 1; for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex) { if (partiallyUnpackedViaPath[viaPathIndex - 1] == partiallyUnpackedShortestPath[shortestPathIndex - 1] && partiallyUnpackedViaPath[viaPathIndex] == partiallyUnpackedShortestPath[shortestPathIndex]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { break; } @@ -309,8 +315,8 @@ private: //compute forward sharing while( (packedAlternativePath[aindex] == packedShortestPath[aindex]) && (packedAlternativePath[aindex+1] == packedShortestPath[aindex+1]) ) { // SimpleLogger().Write() << "retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"; - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); - sharing += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); + sharing += facade->GetEdgeData(edgeID).distance; ++aindex; } @@ -318,8 +324,8 @@ private: int bindex = packedShortestPath.size()-1; //compute backward sharing while( aindex > 0 && bindex > 0 && (packedAlternativePath[aindex] == packedShortestPath[bindex]) && (packedAlternativePath[aindex-1] == packedShortestPath[bindex-1]) ) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); - sharing += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); + sharing += facade->GetEdgeData(edgeID).distance; --aindex; --bindex; } return sharing; @@ -357,12 +363,12 @@ private: } } - for ( typename SearchGraph::EdgeIterator edge = search_graph->BeginEdges( node ); edge < search_graph->EndEdges(node); edge++ ) { - const typename SearchGraph::EdgeData & data = search_graph->GetEdgeData(edge); + for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); edge++ ) { + const typename SearchGraph::EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { - const NodeID to = search_graph->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -432,8 +438,8 @@ private: std::stack unpackStack; //Traverse path s-->v for (unsigned i = packed_s_v_path.size() - 1; (i > 0) && unpackStack.empty(); --i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_s_v_path[i - 1], packed_s_v_path[i]); - int lengthOfCurrentEdge = search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_s_v_path[i - 1], packed_s_v_path[i]); + int lengthOfCurrentEdge = facade->GetEdgeData(edgeID).distance; if (lengthOfCurrentEdge + unpackedUntilDistance >= T_threshold) { unpackStack.push(std::make_pair(packed_s_v_path[i - 1], packed_s_v_path[i])); } else { @@ -445,15 +451,15 @@ private: while (!unpackStack.empty()) { const SearchSpaceEdge viaPathEdge = unpackStack.top(); unpackStack.pop(); - typename SearchGraph::EdgeIterator edgeIDInViaPath = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); + EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = search_graph->GetEdgeData(edgeIDInViaPath); + typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; - typename SearchGraph::EdgeIterator edgeIDOfSecondSegment = search_graph->FindEdgeInEitherDirection(middleOfViaPath, viaPathEdge.second); - int lengthOfSecondSegment = search_graph->GetEdgeData(edgeIDOfSecondSegment).distance; + EdgeID edgeIDOfSecondSegment = facade->FindEdgeInEitherDirection(middleOfViaPath, viaPathEdge.second); + int lengthOfSecondSegment = facade->GetEdgeData(edgeIDOfSecondSegment).distance; //attention: !unpacking in reverse! //Check if second segment is the one to go over treshold? if yes add second segment to stack, else push first segment to stack and add distance of second one. if (unpackedUntilDistance + lengthOfSecondSegment >= T_threshold) { @@ -473,8 +479,8 @@ private: unpackedUntilDistance = 0; //Traverse path s-->v for (unsigned i = 0, lengthOfPackedPath = packed_v_t_path.size() - 1; (i < lengthOfPackedPath) && unpackStack.empty(); ++i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_v_t_path[i], packed_v_t_path[i + 1]); - int lengthOfCurrentEdge = search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[i], packed_v_t_path[i + 1]); + int lengthOfCurrentEdge = facade->GetEdgeData(edgeID).distance; if (lengthOfCurrentEdge + unpackedUntilDistance >= T_threshold) { unpackStack.push( std::make_pair(packed_v_t_path[i], packed_v_t_path[i + 1])); } else { @@ -486,15 +492,15 @@ private: while (!unpackStack.empty()) { const SearchSpaceEdge viaPathEdge = unpackStack.top(); unpackStack.pop(); - typename SearchGraph::EdgeIterator edgeIDInViaPath = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); + EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = search_graph->GetEdgeData(edgeIDInViaPath); + typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); const bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; - typename SearchGraph::EdgeIterator edgeIDOfFirstSegment = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, middleOfViaPath); - int lengthOfFirstSegment = search_graph->GetEdgeData( edgeIDOfFirstSegment).distance; + EdgeID edgeIDOfFirstSegment = facade->FindEdgeInEitherDirection(viaPathEdge.first, middleOfViaPath); + int lengthOfFirstSegment = facade->GetEdgeData( edgeIDOfFirstSegment).distance; //Check if first segment is the one to go over treshold? if yes first segment to stack, else push second segment to stack and add distance of first one. if (unpackedUntilDistance + lengthOfFirstSegment >= T_threshold) { unpackStack.push( std::make_pair(viaPathEdge.first, middleOfViaPath)); diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index b182265e1..dc132223d 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -35,12 +35,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -template +template class BasicRoutingInterface : boost::noncopyable{ protected: - SearchEngineDataT * engine_working_data; + DataFacadeT * facade; public: - BasicRoutingInterface(SearchEngineDataT * engine_working_data) : engine_working_data(engine_working_data) { } + BasicRoutingInterface(DataFacadeT * facade) : facade(facade) { } virtual ~BasicRoutingInterface(){ }; inline void RoutingStep( @@ -72,14 +72,14 @@ public: //Stalling for( - EdgeID edge = engine_working_data->BeginEdges( node ); - edge < engine_working_data->EndEdges(node); + EdgeID edge = facade->BeginEdges( node ); + edge < facade->EndEdges(node); ++edge ) { - const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); + const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward; if(backwardDirectionFlag) { - const NodeID to = engine_working_data->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -92,12 +92,12 @@ public: } } - for ( EdgeID edge = engine_working_data->BeginEdges( node ); edge < engine_working_data->EndEdges(node); ++edge ) { - const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); + for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { + const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { - const NodeID to = engine_working_data->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -133,18 +133,18 @@ public: EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ + for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ + for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -152,7 +152,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order @@ -163,8 +163,8 @@ public: unpackedPath.push_back( _PathData( ed.id, - engine_working_data->GetNameIndexFromEdgeID(ed.id), - engine_working_data->GetTurnInstructionForEdgeID(ed.id), + facade->GetNameIndexFromEdgeID(ed.id), + facade->GetTurnInstructionForEdgeID(ed.id), ed.distance ) ); @@ -183,18 +183,18 @@ public: EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ + for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ + for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -202,7 +202,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 8c870aab0..3426772d9 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -27,13 +27,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/SearchEngineData.h" -template -class ShortestPathRouting : public BasicRoutingInterface{ - typedef BasicRoutingInterface super; - typedef typename QueryDataT::QueryHeap QueryHeap; +template +class ShortestPathRouting : public BasicRoutingInterface{ + typedef BasicRoutingInterface super; + typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; public: - ShortestPathRouting( QueryDataT & qd, SearchEngineData & engine_working_data) : super(qd), engine_working_data(engine_working_data) {} + ShortestPathRouting( DataFacadeT * facade, SearchEngineData & engine_working_data) : super(facade), engine_working_data(engine_working_data) {} ~ShortestPathRouting() {}