replacing nearest neighbor grid by static r-tree
This commit is contained in:
parent
0a6c37b726
commit
648f9c9723
@ -96,7 +96,7 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector< EdgeBasedEdge
|
||||
edgeBasedEdges.swap(outputEdgeList);
|
||||
}
|
||||
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes) {
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector<EdgeBasedNode> & nodes) {
|
||||
#ifndef NDEBUG
|
||||
BOOST_FOREACH(EdgeBasedNode & node, edgeBasedNodes){
|
||||
assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX);
|
||||
|
@ -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<EdgeBasedEdge> edgeBasedEdges;
|
||||
DeallocatingVector<EdgeBasedNode> edgeBasedNodes;
|
||||
std::vector<EdgeBasedNode> 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;
|
||||
|
@ -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 <boost/assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#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<RTreeLeaf>(
|
||||
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()) {
|
||||
@ -75,13 +90,8 @@ public:
|
||||
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,23 +110,35 @@ public:
|
||||
return origEdgeData_turnInstruction.at(id);
|
||||
}
|
||||
|
||||
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
|
||||
inline NodeID getNumberOfNodes2() const { return coordinateVector.size(); }
|
||||
|
||||
inline bool FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const {
|
||||
return readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
|
||||
inline NodeID getNumberOfNodes() const {
|
||||
return number_of_nodes;
|
||||
}
|
||||
|
||||
inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) {
|
||||
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode, zoomLevel);
|
||||
inline NodeID getNumberOfNodes2() const {
|
||||
return coordinateVector.size();
|
||||
}
|
||||
|
||||
inline void FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes, const unsigned zoomLevel) const {
|
||||
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes, 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 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 {
|
||||
@ -129,8 +151,8 @@ private:
|
||||
std::vector<unsigned> origEdgeData_nameID;
|
||||
std::vector<TurnInstruction> origEdgeData_turnInstruction;
|
||||
|
||||
ReadOnlyGrid * readOnlyGrid;
|
||||
const unsigned numberOfNodes;
|
||||
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * read_only_rtree;
|
||||
const unsigned number_of_nodes;
|
||||
const unsigned checkSum;
|
||||
};
|
||||
|
||||
|
@ -21,13 +21,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef LOCATEPLUGIN_H_
|
||||
#define LOCATEPLUGIN_H_
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#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 <fstream>
|
||||
|
||||
/*
|
||||
* This Plugin locates the nearest node in the road network for a given coordinate.
|
||||
|
@ -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 ){
|
||||
|
@ -73,17 +73,23 @@ 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);
|
||||
|
@ -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<EdgeBasedEdge> edgeBasedEdgeList;
|
||||
edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList);
|
||||
DeallocatingVector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList;
|
||||
std::vector<EdgeBasedGraphFactory::EdgeBasedNode> 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<DeallocatingVector<EdgeBasedGraphFactory::EdgeBasedNode> > crc32;
|
||||
INFO("building r-tree ...");
|
||||
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * rtree =
|
||||
new StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode>(
|
||||
nodeBasedEdgeList,
|
||||
rtree_nodes_path.c_str(),
|
||||
rtree_leafs_path.c_str()
|
||||
);
|
||||
delete rtree;
|
||||
IteratorbasedCRC32<std::vector<EdgeBasedGraphFactory::EdgeBasedNode> > crc32;
|
||||
unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() );
|
||||
nodeBasedEdgeList.clear();
|
||||
INFO("CRC32 based checksum is " << crc32OfNodeBasedEdgeList);
|
||||
|
Loading…
Reference in New Issue
Block a user