Every node in route carries a bit that indicates if its possible at all to take a turn

This commit is contained in:
Dennis Luxen 2010-10-01 10:32:39 +00:00
parent e91058c2eb
commit 3b885a492c
2 changed files with 46 additions and 26 deletions

View File

@ -34,6 +34,12 @@ struct _HeapData {
_HeapData( NodeID p ) : parent(p), stalled(false) { } _HeapData( NodeID p ) : parent(p), stalled(false) { }
}; };
struct _PathData {
_PathData(NodeID n, bool t) : node(n), turn(t) { }
NodeID node:31;
bool turn:1;
};
typedef BinaryHeap< NodeID, int, int, _HeapData, DenseStorage< NodeID, unsigned > > _Heap; typedef BinaryHeap< NodeID, int, int, _HeapData, DenseStorage< NodeID, unsigned > > _Heap;
template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk> template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk>
@ -57,7 +63,7 @@ public:
return nodeHelpDesk->getNumberOfNodes(); return nodeHelpDesk->getNumberOfNodes();
} }
unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<NodeID > * path, _Coordinate& startCoord, _Coordinate& targetCoord) unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<_PathData > * path, _Coordinate& startCoord, _Coordinate& targetCoord)
{ {
bool onSameEdge = false; bool onSameEdge = false;
bool onSameEdgeReversed = false; bool onSameEdgeReversed = false;
@ -192,7 +198,8 @@ public:
packedPath.push_back( pathNode ); packedPath.push_back( pathNode );
} }
path->push_back(packedPath[0] );
path->push_back( _PathData(packedPath[0], false) );
{ {
for(deque<NodeID>::size_type i = 0; i < packedPath.size()-1; i++) for(deque<NodeID>::size_type i = 0; i < packedPath.size()-1; i++)
{ {
@ -307,9 +314,10 @@ private:
} }
} }
bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< NodeID >* path ) { bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< _PathData >* path ) {
assert(source != target); assert(source != target);
//find edge first. //find edge first.
bool forward = true;
typename GraphT::EdgeIterator smallestEdge = SPECIAL_EDGEID; typename GraphT::EdgeIterator smallestEdge = SPECIAL_EDGEID;
EdgeWeight smallestWeight = UINT_MAX; EdgeWeight smallestWeight = UINT_MAX;
for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(source); eit < _graph->EndEdges(source); eit++) for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(source); eit < _graph->EndEdges(source); eit++)
@ -331,6 +339,7 @@ private:
if(_graph->GetTarget(eit) == source && weight < smallestWeight && _graph->GetEdgeData(eit).backward) if(_graph->GetTarget(eit) == source && weight < smallestWeight && _graph->GetEdgeData(eit).backward)
{ {
smallestEdge = eit; smallestWeight = weight; smallestEdge = eit; smallestWeight = weight;
forward = false;
} }
} }
} }
@ -347,7 +356,7 @@ private:
return false; return false;
} else { } else {
assert(!ed.shortcut); assert(!ed.shortcut);
path->push_back(target); path->push_back(_PathData(target, (forward ? ed.forwardTurn : ed.backwardTurn) ) );
return true; return true;
} }
} }

View File

@ -104,7 +104,7 @@ public:
_Coordinate startCoord(lat1, lon1); _Coordinate startCoord(lat1, lon1);
_Coordinate targetCoord(lat2, lon2); _Coordinate targetCoord(lat2, lon2);
vector<NodeID > * path = new vector<NodeID >(); vector< _PathData > * path = new vector< _PathData >();
PhantomNodes * phantomNodes = new PhantomNodes(); PhantomNodes * phantomNodes = new PhantomNodes();
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes); sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord); unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
@ -118,7 +118,7 @@ public:
if(distance != std::numeric_limits<unsigned int>::max()) if(distance != std::numeric_limits<unsigned int>::max())
computeDescription(tmp, path, phantomNodes); computeDescription(tmp, path, phantomNodes);
// cout << tmp << endl;
// rep.content += tmp; // rep.content += tmp;
rep.content += ("<Placemark>"); rep.content += ("<Placemark>");
rep.content += ("<name>OSM Routing Engine (c) Dennis Luxen and others </name>"); rep.content += ("<name>OSM Routing Engine (c) Dennis Luxen and others </name>");
@ -152,9 +152,9 @@ public:
rep.content += tmp; rep.content += tmp;
rep.content += (" "); rep.content += (" ");
_Coordinate result; _Coordinate result;
for(vector<NodeID >::iterator it = path->begin(); it != path->end(); it++) for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++)
{ {
sEngine->getNodeInfo(*it, result); sEngine->getNodeInfo(it->node, result);
convertLatLon(result.lon, tmp); convertLatLon(result.lon, tmp);
rep.content += tmp; rep.content += tmp;
rep.content += (","); rep.content += (",");
@ -263,7 +263,7 @@ private:
return buffer; return buffer;
} }
void computeDescription(string &tmp, vector<NodeID> * path, PhantomNodes * phantomNodes) void computeDescription(string &tmp, vector< _PathData > * path, PhantomNodes * phantomNodes)
{ {
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon); _Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
_Coordinate next, current, lastPlace; _Coordinate next, current, lastPlace;
@ -277,18 +277,18 @@ private:
lastPlace.lon = phantomNodes->startCoord.lon; lastPlace.lon = phantomNodes->startCoord.lon;
short nextType = SHRT_MAX; short nextType = SHRT_MAX;
short prevType = SHRT_MAX; short prevType = SHRT_MAX;
tmp += "<Placemark><Name>"; tmp += "<Placemark>\n <Name>";
for(vector<NodeID >::iterator it = path->begin(); it != path->end(); it++) for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++)
{ {
sEngine->getNodeInfo(*it, current); sEngine->getNodeInfo(it->node, current);
if(it==path->end()-1){ if(it==path->end()-1){
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon); next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
} else { } else {
sEngine->getNodeInfo(*(it+1), next); sEngine->getNodeInfo((it+1)->node, next);
nextID = sEngine->GetNameIDForOriginDestinationNodeID(*it, *(it+1)); nextID = sEngine->GetNameIDForOriginDestinationNodeID(it->node, (it+1)->node);
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(*it, *(it+1)); nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
} }
if(nextID == nameID) { if(nextID == nameID) {
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon); tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
@ -299,13 +299,20 @@ private:
tmp += "leave motorway and "; tmp += "leave motorway and ";
double angle = GetAngleBetweenTwoEdges(previous, current, next); double angle = GetAngleBetweenTwoEdges(previous, current, next);
if(it->turn)
tmp += " turn! ";
tmp += "follow road "; tmp += "follow road ";
if(nameID != 0)
tmp += sEngine->GetNameForNameID(nameID); tmp += sEngine->GetNameForNameID(nameID);
tmp += " (type: "; tmp += " (type: ";
numberString << type; numberString << type;
tmp += numberString.str(); tmp += numberString.str();
numberString.str(""); numberString.str("");
tmp += ")</Name><Description>drive for "; tmp += ", id: ";
numberString << nameID;
tmp += numberString.str();
numberString.str("");
tmp += ")</Name>\n <Description>drive for ";
numberString << ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon)+tempDist; numberString << ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon)+tempDist;
tmp += numberString.str(); tmp += numberString.str();
numberString.str(""); numberString.str("");
@ -314,13 +321,17 @@ private:
convertLatLon(lastPlace.lon, lon); convertLatLon(lastPlace.lon, lon);
convertLatLon(lastPlace.lat, lat); convertLatLon(lastPlace.lat, lat);
lastPlace = current; lastPlace = current;
tmp += "<Point><Coordinates>"; tmp += "\n <Point><Coordinates>";
tmp += lon; tmp += lon;
tmp += ","; tmp += ",";
tmp += lat; tmp += lat;
tmp += "</Coordinates></Point>"; tmp += "</Coordinates></Point>";
tmp += "</Placemark>"; tmp += "\n</Placemark>\n";
tmp += "<Placemark><Name>"; tmp += "<Placemark>\n <Name> (";
numberString << angle;
tmp += numberString.str();
numberString.str("");
tmp +=") ";
if(angle > 160 && angle < 200) { if(angle > 160 && angle < 200) {
tmp += /* " (" << angle << ")*/"drive ahead, "; tmp += /* " (" << angle << ")*/"drive ahead, ";
} else if (angle > 290 && angle <= 360) { } else if (angle > 290 && angle <= 360) {
@ -351,11 +362,11 @@ private:
numberString << type; numberString << type;
tmp += numberString.str(); tmp += numberString.str();
numberString.str(""); numberString.str("");
tmp += ")</name><Description> drive for "; tmp += ")</name>\n <Description> drive for ";
numberString << (previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist; numberString << (previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist;
tmp += numberString.str(); tmp += numberString.str();
numberString.str(""); numberString.str("");
tmp += "m</Description>"; tmp += "m</Description>\n ";
string lat; string lon; string lat; string lon;
convertLatLon(lastPlace.lon, lon); convertLatLon(lastPlace.lon, lon);
convertLatLon(lastPlace.lat, lat); convertLatLon(lastPlace.lat, lat);
@ -364,16 +375,16 @@ private:
tmp += ","; tmp += ",";
tmp += lat; tmp += lat;
tmp += "</Coordinates></Point>"; tmp += "</Coordinates></Point>";
tmp += "</Placemark>"; tmp += "</Placemark>\n";
tmp += "<Placemark><Name>you have reached your destination</Name>"; tmp += "<Placemark>\n <Name>you have reached your destination</Name>\n ";
tmp += "<Description>End of Route</Description>"; tmp += "<Description>End of Route</Description>";
convertLatLon(phantomNodes->targetCoord.lon, lon); convertLatLon(phantomNodes->targetCoord.lon, lon);
convertLatLon(phantomNodes->targetCoord.lat, lat); convertLatLon(phantomNodes->targetCoord.lat, lat);
tmp += "<Point><Coordinates>"; tmp += "\n <Point><Coordinates>";
tmp += lon; tmp += lon;
tmp += ","; tmp += ",";
tmp += lat; tmp += lat;
tmp +="</Coordinates></Point>"; tmp +="</Coordinates></Point>\n";
tmp += "</Placemark>"; tmp += "</Placemark>";
} }