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) { }
};
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;
template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk>
@ -57,7 +63,7 @@ public:
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 onSameEdgeReversed = false;
@ -192,7 +198,8 @@ public:
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++)
{
@ -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);
//find edge first.
bool forward = true;
typename GraphT::EdgeIterator smallestEdge = SPECIAL_EDGEID;
EdgeWeight smallestWeight = UINT_MAX;
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)
{
smallestEdge = eit; smallestWeight = weight;
forward = false;
}
}
}
@ -347,7 +356,7 @@ private:
return false;
} else {
assert(!ed.shortcut);
path->push_back(target);
path->push_back(_PathData(target, (forward ? ed.forwardTurn : ed.backwardTurn) ) );
return true;
}
}

View File

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