diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 0f313e339..13f49ecb7 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -96,7 +96,7 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector< EdgeBasedEdge edgeBasedEdges.swap(outputEdgeList); } -void EdgeBasedGraphFactory::GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes) { +void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & nodes) { #ifndef NDEBUG BOOST_FOREACH(EdgeBasedNode & node, edgeBasedNodes){ assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index e290b762a..08e473f4e 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -64,9 +64,23 @@ public: bool operator<(const EdgeBasedNode & other) const { return other.id < id; } + bool operator==(const EdgeBasedNode & other) const { return id == other.id; } + + inline _Coordinate Centroid() const { + _Coordinate centroid; + //The coordinates of the midpoint are given by: + //x = (x1 + x2) /2 and y = (y1 + y2) /2. + centroid.lon = (std::min(lon1, lon2) + std::max(lon1, lon2))/2; + centroid.lat = (std::min(lat1, lat2) + std::max(lat1, lat2))/2; + return centroid; + } + + inline bool isIgnored() const { + return ignoreInGrid; + } NodeID id; int lat1; int lat2; @@ -126,7 +140,7 @@ private: RestrictionMap _restrictionMap; DeallocatingVector edgeBasedEdges; - DeallocatingVector edgeBasedNodes; + std::vector edgeBasedNodes; NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const; bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const; @@ -144,7 +158,7 @@ public: void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); - void GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes); + void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const; unsigned GetNumberOfNodes() const; diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 029d30def..f13c9ad34 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -21,34 +21,49 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef NODEINFORMATIONHELPDESK_H_ #define NODEINFORMATIONHELPDESK_H_ +#include "NodeCoords.h" +#include "PhantomNodes.h" +#include "QueryEdge.h" +#include "StaticRTree.h" +#include "../Contractor/EdgeBasedGraphFactory.h" +#include "../typedefs.h" + +#include +#include + #include + #include #include -#include - -#include "../typedefs.h" -#include "../DataStructures/QueryEdge.h" -#include "NNGrid.h" -#include "PhantomNodes.h" -#include "NodeCoords.h" +typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; class NodeInformationHelpDesk : boost::noncopyable{ public: - NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) { - readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); - assert(0 == coordinateVector.size()); + NodeInformationHelpDesk( + const char* ramIndexInput, + const char* fileIndexInput, + const unsigned number_of_nodes, + const unsigned crc) : number_of_nodes(number_of_nodes), checkSum(crc) { + read_only_rtree = new StaticRTree( + ramIndexInput, + fileIndexInput + ); + BOOST_ASSERT_MSG( + 0 == coordinateVector.size(), + "Coordinate vector not empty" + ); } //Todo: Shared memory mechanism -// NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { -// readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); -// } - ~NodeInformationHelpDesk() { - delete readOnlyGrid; + delete read_only_rtree; } - void initNNGrid(std::ifstream& nodesInstream, std::ifstream& edgesInStream) { + + void initNNGrid( + std::ifstream& nodesInstream, + std::ifstream& edgesInStream + ) { DEBUG("Loading node data"); NodeInfo b; while(!nodesInstream.eof()) { @@ -68,20 +83,15 @@ public: OriginalEdgeData deserialized_originalEdgeData; for(unsigned i = 0; i < numberOfOrigEdges; ++i) { edgesInStream.read((char*)&(deserialized_originalEdgeData), sizeof(OriginalEdgeData)); - origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode; - origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID; + origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode; + origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID; origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction; } edgesInStream.close(); DEBUG("Loaded " << numberOfOrigEdges << " orig edges"); DEBUG("Opening NN indices"); - readOnlyGrid->OpenIndexFiles(); } -// void initNNGrid() { -// readOnlyGrid->OpenIndexFiles(); -// } - inline int getLatitudeOfNode(const unsigned id) const { const NodeID node = origEdgeData_viaNode.at(id); return coordinateVector.at(node).lat; @@ -100,24 +110,36 @@ public: return origEdgeData_turnInstruction.at(id); } - inline NodeID getNumberOfNodes() const { return numberOfNodes; } - inline NodeID getNumberOfNodes2() const { return coordinateVector.size(); } + inline NodeID getNumberOfNodes() const { + return number_of_nodes; + } - inline bool FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const { - return readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result); - } + inline NodeID getNumberOfNodes2() const { + return coordinateVector.size(); + } - inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) { - return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode, zoomLevel); - } + inline bool FindNearestNodeCoordForLatLon( + const _Coordinate& input_coordinate, + _Coordinate& result, + const unsigned zoom_level = 18 + ) const { + PhantomNode resulting_phantom_node; + bool foundNode = FindPhantomNodeForCoordinate(input_coordinate, resulting_phantom_node, zoom_level); + result = resulting_phantom_node.location; + return foundNode; + } - inline void FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes, const unsigned zoomLevel) const { - readOnlyGrid->FindRoutingStarts(start, target, phantomNodes, zoomLevel); - } - - inline void FindNearestPointOnEdge(const _Coordinate & input, _Coordinate& output){ - readOnlyGrid->FindNearestPointOnEdge(input, output); - } + inline bool FindPhantomNodeForCoordinate( + const _Coordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const { + return read_only_rtree->FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, + zoom_level + ); + } inline unsigned GetCheckSum() const { return checkSum; @@ -129,8 +151,8 @@ private: std::vector origEdgeData_nameID; std::vector origEdgeData_turnInstruction; - ReadOnlyGrid * readOnlyGrid; - const unsigned numberOfNodes; + StaticRTree * read_only_rtree; + const unsigned number_of_nodes; const unsigned checkSum; }; diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index c26e75fb6..f1c7d60ac 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -21,13 +21,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef LOCATEPLUGIN_H_ #define LOCATEPLUGIN_H_ -#include - -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "BasePlugin.h" #include "RouteParameters.h" -#include "../Util/StringUtil.h" #include "../DataStructures/NodeInformationHelpDesk.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" +#include "../Util/StringUtil.h" + +#include /* * This Plugin locates the nearest node in the road network for a given coordinate. diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index a42a95e35..caef97a96 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -44,6 +44,7 @@ public: inline void RoutingStep(typename QueryDataT::QueryHeap & _forwardHeap, typename QueryDataT::QueryHeap & _backwardHeap, NodeID *middle, int *_upperbound, const int edgeBasedOffset, const bool forwardDirection) const { const NodeID node = _forwardHeap.DeleteMin(); const int distance = _forwardHeap.GetKey(node); + //INFO("Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance); if(_backwardHeap.WasInserted(node) ){ const int newDistance = _backwardHeap.GetKey(node) + distance; if(newDistance < *_upperbound ){ diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 66d374079..472e7ddbe 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -73,18 +73,24 @@ public: //insert new starting nodes into forward heap, adjusted by previous distances. if(searchFrom1stStartNode) { forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); + INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); - } + INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); + } if(phantomNodePair.startPhantom.isBidirected() && searchFrom2ndStartNode) { forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); + INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); + INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); } //insert new backward nodes into backward heap, unadjusted. reverse_heap1.Insert(phantomNodePair.targetPhantom.edgeBasedNode, phantomNodePair.targetPhantom.weight1, phantomNodePair.targetPhantom.edgeBasedNode); + INFO("rv1: " << phantomNodePair.targetPhantom.edgeBasedNode << ", w;" << phantomNodePair.targetPhantom.weight1 ); if(phantomNodePair.targetPhantom.isBidirected() ) { reverse_heap2.Insert(phantomNodePair.targetPhantom.edgeBasedNode+1, phantomNodePair.targetPhantom.weight2, phantomNodePair.targetPhantom.edgeBasedNode+1); - } + INFO("rv2: " << phantomNodePair.targetPhantom.edgeBasedNode+1 << ", w;" << phantomNodePair.targetPhantom.weight2 ); + } const int forward_offset = phantomNodePair.startPhantom.weight1 + (phantomNodePair.startPhantom.isBidirected() ? phantomNodePair.startPhantom.weight2 : 0); const int reverse_offset = phantomNodePair.targetPhantom.weight1 + (phantomNodePair.targetPhantom.isBidirected() ? phantomNodePair.targetPhantom.weight2 : 0); diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 5da8ecde3..5e6343d1d 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -23,8 +23,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Contractor/EdgeBasedGraphFactory.h" #include "DataStructures/BinaryHeap.h" #include "DataStructures/DeallocatingVector.h" -#include "DataStructures/NNGrid.h" #include "DataStructures/QueryEdge.h" +#include "DataStructures/StaticGraph.h" +#include "DataStructures/StaticRTree.h" #include "Util/BaseConfiguration.h" #include "Util/GraphLoader.h" #include "Util/InputFileUtil.h" @@ -92,8 +93,8 @@ int main (int argc, char *argv[]) { std::string nodeOut(argv[1]); nodeOut += ".nodes"; std::string edgeOut(argv[1]); edgeOut += ".edges"; std::string graphOut(argv[1]); graphOut += ".hsgr"; - std::string ramIndexOut(argv[1]); ramIndexOut += ".ramIndex"; - std::string fileIndexOut(argv[1]); fileIndexOut += ".fileIndex"; + std::string rtree_nodes_path(argv[1]); rtree_nodes_path += ".ramIndex"; + std::string rtree_leafs_path(argv[1]); rtree_leafs_path += ".fileIndex"; /*** Setup Scripting Environment ***/ if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) { @@ -154,7 +155,7 @@ int main (int argc, char *argv[]) { NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); DeallocatingVector edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); - DeallocatingVector nodeBasedEdgeList; + std::vector nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); delete edgeBasedGraphFactory; @@ -174,11 +175,15 @@ int main (int argc, char *argv[]) { * Building grid-like nearest-neighbor data structure */ - INFO("building grid ..."); - WritableGrid * writeableGrid = new WritableGrid(); - writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut.c_str(), fileIndexOut.c_str()); - delete writeableGrid; - IteratorbasedCRC32 > crc32; + INFO("building r-tree ..."); + StaticRTree * rtree = + new StaticRTree( + nodeBasedEdgeList, + rtree_nodes_path.c_str(), + rtree_leafs_path.c_str() + ); + delete rtree; + IteratorbasedCRC32 > crc32; unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); nodeBasedEdgeList.clear(); INFO("CRC32 based checksum is " << crc32OfNodeBasedEdgeList);