Exploration of tiny components.
This commit is contained in:
@@ -22,13 +22,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#define GRIDEDGE_H_
|
||||
|
||||
struct _GridEdge {
|
||||
_GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc) {}
|
||||
_GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX) {}
|
||||
_GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc, bool bttc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc), belongsToTinyComponent(bttc) {}
|
||||
_GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX), belongsToTinyComponent(false) {}
|
||||
NodeID edgeBasedNode;
|
||||
NodeID nameID;
|
||||
int weight;
|
||||
_Coordinate startCoord;
|
||||
_Coordinate targetCoord;
|
||||
bool belongsToTinyComponent;
|
||||
|
||||
bool operator< ( const _GridEdge& right) const {
|
||||
return edgeBasedNode < right.edgeBasedNode;
|
||||
}
|
||||
|
||||
+16
-30
@@ -100,7 +100,7 @@ public:
|
||||
int slon = edge.lon1;
|
||||
int tlat = 100000*lat2y(edge.lat2/100000.);
|
||||
int tlon = edge.lon2;
|
||||
AddEdge( _GridEdge( edge.id, edge.nameID, edge.weight, _Coordinate(slat, slon), _Coordinate(tlat, tlon) ) );
|
||||
AddEdge( _GridEdge( edge.id, edge.nameID, edge.weight, _Coordinate(slat, slon), _Coordinate(tlat, tlon), edge.belongsToTinyComponent ) );
|
||||
}
|
||||
double timestamp = get_timestamp();
|
||||
//create index file on disk, old one is over written
|
||||
@@ -148,7 +148,9 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
|
||||
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) {
|
||||
bool ignoreTinyComponents = (zoomLevel <= 14);
|
||||
// INFO("ZoomLevel: " << zoomLevel << ", ignoring tinyComponentents: " << (ignoreTinyComponents ? "yes" : "no"));
|
||||
// double time1 = get_timestamp();
|
||||
bool foundNode = false;
|
||||
_Coordinate startCoord(100000*(lat2y(static_cast<double>(location.lat)/100000.)), location.lon);
|
||||
@@ -166,10 +168,12 @@ public:
|
||||
double r, tmpDist;
|
||||
|
||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
||||
if(candidate.belongsToTinyComponent && ignoreTinyComponents)
|
||||
continue;
|
||||
r = 0.;
|
||||
tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
||||
if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) {
|
||||
//INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist);
|
||||
// INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist << ", tinyCC: " << (candidate.belongsToTinyComponent ? "yes" : "no"));
|
||||
dist = tmpDist;
|
||||
resultNode.edgeBasedNode = candidate.edgeBasedNode;
|
||||
resultNode.nodeBasedEdgeNameID = candidate.nameID;
|
||||
@@ -212,41 +216,23 @@ public:
|
||||
}
|
||||
resultNode.ratio = ratio;
|
||||
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio);
|
||||
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--");
|
||||
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--");
|
||||
// double time2 = get_timestamp();
|
||||
// INFO("NN-Lookup in " << 1000*(time2-time1) << "ms");
|
||||
return foundNode;
|
||||
}
|
||||
|
||||
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes & routingStarts) {
|
||||
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes & routingStarts, unsigned zoomLevel) {
|
||||
routingStarts.Reset();
|
||||
return (FindPhantomNodeForCoordinate( start, routingStarts.startPhantom) &&
|
||||
FindPhantomNodeForCoordinate( target, routingStarts.targetPhantom) );
|
||||
return (FindPhantomNodeForCoordinate( start, routingStarts.startPhantom, zoomLevel) &&
|
||||
FindPhantomNodeForCoordinate( target, routingStarts.targetPhantom, zoomLevel) );
|
||||
}
|
||||
|
||||
bool FindNearestCoordinateOnEdgeInNodeBasedGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
||||
bool found = false;
|
||||
unsigned fileIndex = GetFileIndexForLatLon(100000*(lat2y(static_cast<double>(inputCoordinate.lat)/100000.)), inputCoordinate.lon);
|
||||
std::vector<_GridEdge> candidates;
|
||||
boost::unordered_map< unsigned, unsigned > cellMap;
|
||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
||||
for(int i = -1; i < 2; ++i) {
|
||||
GetContentsOfFileBucket(fileIndex+i+j, candidates, cellMap);
|
||||
}
|
||||
}
|
||||
_Coordinate tmp;
|
||||
double dist = (std::numeric_limits<double>::max)();
|
||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
||||
double r = 0.;
|
||||
double tmpDist = ComputeDistance(inputCoordinate, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
||||
if(tmpDist < dist) {
|
||||
found = true;
|
||||
dist = tmpDist;
|
||||
outputCoordinate = tmp;
|
||||
}
|
||||
}
|
||||
outputCoordinate.lat = 100000*(y2lat(static_cast<double>(outputCoordinate.lat)/100000.));
|
||||
return found;
|
||||
bool FindNearestCoordinateOnEdgeInNodeBasedGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate, unsigned zoomLevel = 18) {
|
||||
PhantomNode resultNode;
|
||||
bool foundNode = FindPhantomNodeForCoordinate(inputCoordinate, resultNode, zoomLevel);
|
||||
outputCoordinate = resultNode.location;
|
||||
return foundNode;
|
||||
}
|
||||
|
||||
void FindNearestPointOnEdge(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
||||
|
||||
@@ -53,7 +53,6 @@ public:
|
||||
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
||||
}
|
||||
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
||||
numberOfNodes = coordinateVector.size();
|
||||
nodesInstream.close();
|
||||
|
||||
DEBUG("Loading edge data");
|
||||
@@ -95,12 +94,13 @@ public:
|
||||
inline bool FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const {
|
||||
return readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
|
||||
}
|
||||
inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) const {
|
||||
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode);
|
||||
|
||||
inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) const {
|
||||
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode, zoomLevel);
|
||||
}
|
||||
|
||||
inline void FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes) const {
|
||||
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
|
||||
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){
|
||||
@@ -116,8 +116,8 @@ private:
|
||||
std::vector<OriginalEdgeData> origEdgeData;
|
||||
|
||||
ReadOnlyGrid * readOnlyGrid;
|
||||
unsigned numberOfNodes;
|
||||
unsigned checkSum;
|
||||
const unsigned numberOfNodes;
|
||||
const unsigned checkSum;
|
||||
};
|
||||
|
||||
#endif /*NODEINFORMATIONHELPDESK_H_*/
|
||||
|
||||
@@ -129,8 +129,8 @@ public:
|
||||
_queryData.nodeHelpDesk->FindRoutingStarts(start, target, routingStarts);
|
||||
}
|
||||
|
||||
inline void FindPhantomNodeForCoordinate(const _Coordinate & location, PhantomNode & result) const {
|
||||
_queryData.nodeHelpDesk->FindPhantomNodeForCoordinate(location, result);
|
||||
inline void FindPhantomNodeForCoordinate(const _Coordinate & location, PhantomNode & result, unsigned zoomLevel) const {
|
||||
_queryData.nodeHelpDesk->FindPhantomNodeForCoordinate(location, result, zoomLevel);
|
||||
}
|
||||
|
||||
inline NodeID GetNameIDForOriginDestinationNodeID(const NodeID s, const NodeID t) const {
|
||||
|
||||
Reference in New Issue
Block a user