Refactored various parts for integration of multi-segment paths
This commit is contained in:
parent
4bbf53ce62
commit
f29f6c65a5
@ -77,7 +77,9 @@ struct _Coordinate {
|
|||||||
lat = INT_MIN;
|
lat = INT_MIN;
|
||||||
lon = INT_MIN;
|
lon = INT_MIN;
|
||||||
}
|
}
|
||||||
|
bool isSet() const {
|
||||||
|
return (INT_MIN != lat) && (INT_MIN != lon);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ostream & operator<<(ostream & out, const _Coordinate & c){
|
ostream & operator<<(ostream & out, const _Coordinate & c){
|
||||||
|
@ -276,11 +276,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes * routingStarts) {
|
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
|
||||||
routingStarts->Reset();
|
bool foundNode = false;
|
||||||
_Coordinate startCoord(100000*(lat2y(static_cast<double>(start.lat)/100000.)), start.lon);
|
_Coordinate startCoord(100000*(lat2y(static_cast<double>(location.lat)/100000.)), location.lon);
|
||||||
_Coordinate targetCoord(100000*(lat2y(static_cast<double>(target.lat)/100000.)), target.lon);
|
|
||||||
|
|
||||||
/** search for point on edge close to source */
|
/** search for point on edge close to source */
|
||||||
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
||||||
std::vector<_Edge> candidates;
|
std::vector<_Edge> candidates;
|
||||||
@ -292,7 +290,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cout << "[debug] " << candidates.size() << " start candidates" << std::endl;
|
|
||||||
_Coordinate tmp;
|
_Coordinate tmp;
|
||||||
double dist = numeric_limits<double>::max();
|
double dist = numeric_limits<double>::max();
|
||||||
timestamp = get_timestamp();
|
timestamp = get_timestamp();
|
||||||
@ -300,44 +297,23 @@ public:
|
|||||||
double r = 0.;
|
double r = 0.;
|
||||||
double tmpDist = ComputeDistance(startCoord, it->startCoord, it->targetCoord, tmp, &r);
|
double tmpDist = ComputeDistance(startCoord, it->startCoord, it->targetCoord, tmp, &r);
|
||||||
if(tmpDist < dist) {
|
if(tmpDist < dist) {
|
||||||
// std::cout << "[debug] start distance " << (it - candidates.begin()) << " " << tmpDist << std::endl;
|
// std::cout << "[debug] start distance " << (it - candidates.begin()) << " " << tmpDist << std::endl;
|
||||||
routingStarts->startNode1 = it->start;
|
resultNode.startNode = it->start;
|
||||||
routingStarts->startNode2 = it->target;
|
resultNode.targetNode = it->target;
|
||||||
routingStarts->startRatio = r;
|
resultNode.ratio = r;
|
||||||
dist = tmpDist;
|
dist = tmpDist;
|
||||||
routingStarts->startCoord.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
resultNode.location.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
||||||
routingStarts->startCoord.lon = tmp.lon;
|
resultNode.location.lon = tmp.lon;
|
||||||
|
foundNode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
candidates.clear();
|
return foundNode;
|
||||||
|
}
|
||||||
|
|
||||||
/** search for point on edge close to target */
|
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes * routingStarts) {
|
||||||
fileIndex = GetFileIndexForLatLon(targetCoord.lat, targetCoord.lon);
|
routingStarts->Reset();
|
||||||
timestamp = get_timestamp();
|
return (FindPhantomNodeForCoordinate( start, routingStarts->startPhantom) &&
|
||||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
FindPhantomNodeForCoordinate( target, routingStarts->targetPhantom) );
|
||||||
for(int i = -1; i < 2; i++){
|
|
||||||
GetContentsOfFileBucket(fileIndex+i+j, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// std::cout << "[debug] " << candidates.size() << " target candidates" << std::endl;
|
|
||||||
dist = numeric_limits<double>::max();
|
|
||||||
timestamp = get_timestamp();
|
|
||||||
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++)
|
|
||||||
{
|
|
||||||
double r = 0.;
|
|
||||||
double tmpDist = ComputeDistance(targetCoord, it->startCoord, it->targetCoord, tmp, &r);
|
|
||||||
if(tmpDist < dist)
|
|
||||||
{
|
|
||||||
// std::cout << "[debug] target distance " << (it - candidates.begin()) << " " << tmpDist << std::endl;
|
|
||||||
routingStarts->targetNode1 = it->start;
|
|
||||||
routingStarts->targetNode2 = it->target;
|
|
||||||
routingStarts->targetRatio = r;
|
|
||||||
dist = tmpDist;
|
|
||||||
routingStarts->targetCoord.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
|
||||||
routingStarts->targetCoord.lon = tmp.lon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindNearestNodeInGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
void FindNearestNodeInGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
||||||
|
@ -61,6 +61,9 @@ public:
|
|||||||
inline void FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) {
|
inline void FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) {
|
||||||
readOnlyGrid->FindNearestNodeInGraph(coord, result);
|
readOnlyGrid->FindNearestNodeInGraph(coord, result);
|
||||||
}
|
}
|
||||||
|
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
|
||||||
|
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes * phantomNodes) {
|
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes * phantomNodes) {
|
||||||
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
|
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
|
||||||
|
@ -23,35 +23,38 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include "ExtractorStructs.h"
|
#include "ExtractorStructs.h"
|
||||||
|
|
||||||
struct PhantomNodes {
|
struct PhantomNode {
|
||||||
PhantomNodes() : startNode1(UINT_MAX), startNode2(UINT_MAX), targetNode1(UINT_MAX), targetNode2(UINT_MAX), startRatio(1.), targetRatio(1.) {}
|
PhantomNode() : startNode(UINT_MAX), targetNode(UINT_MAX), ratio(1.) {}
|
||||||
NodeID startNode1;
|
|
||||||
NodeID startNode2;
|
NodeID startNode;
|
||||||
NodeID targetNode1;
|
NodeID targetNode;
|
||||||
NodeID targetNode2;
|
double ratio;
|
||||||
double startRatio;
|
_Coordinate location;
|
||||||
double targetRatio;
|
|
||||||
_Coordinate startCoord;
|
|
||||||
_Coordinate targetCoord;
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
startNode1 = UINT_MAX;
|
startNode = UINT_MAX;
|
||||||
startNode2 = UINT_MAX;
|
targetNode = UINT_MAX;
|
||||||
targetNode1 = UINT_MAX;
|
ratio = 1.;
|
||||||
targetNode2 = UINT_MAX;
|
location.Reset();
|
||||||
startRatio = 1.;
|
}
|
||||||
targetRatio = 1.;
|
|
||||||
startCoord.Reset();
|
};
|
||||||
targetCoord.Reset();
|
|
||||||
|
struct PhantomNodes {
|
||||||
|
PhantomNode startPhantom;
|
||||||
|
PhantomNode targetPhantom;
|
||||||
|
void Reset() {
|
||||||
|
startPhantom.Reset();
|
||||||
|
targetPhantom.Reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){
|
std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){
|
||||||
out << "startNode1: " << pn.startNode1 << std::endl;
|
out << "startNode1: " << pn.startPhantom.startNode << std::endl;
|
||||||
out << "startNode2: " << pn.startNode2 << std::endl;
|
out << "startNode2: " << pn.startPhantom.targetNode << std::endl;
|
||||||
out << "targetNode1: " << pn.targetNode1 << std::endl;
|
out << "targetNode1: " << pn.targetPhantom.startNode << std::endl;
|
||||||
out << "targetNode2: " << pn.targetNode2 << std::endl;
|
out << "targetNode2: " << pn.targetPhantom.targetNode << std::endl;
|
||||||
out << "startCoord: " << pn.startCoord << std::endl;
|
out << "startCoord: " << pn.startPhantom.location << std::endl;
|
||||||
out << "targetCoord: " << pn.targetCoord << std::endl;
|
out << "targetCoord: " << pn.targetPhantom.location << std::endl;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<_PathData > * path) {
|
unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<_PathData > * path) {
|
||||||
|
|
||||||
bool onSameEdge = false;
|
bool onSameEdge = false;
|
||||||
bool onSameEdgeReversed = false;
|
bool onSameEdgeReversed = false;
|
||||||
bool startReverse = false;
|
bool startReverse = false;
|
||||||
@ -121,16 +120,16 @@ public:
|
|||||||
NodeID middle = ( NodeID ) 0;
|
NodeID middle = ( NodeID ) 0;
|
||||||
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
||||||
|
|
||||||
if(phantomNodes->startNode1 == UINT_MAX || phantomNodes->targetNode1 == UINT_MAX || phantomNodes->startNode2 == UINT_MAX || phantomNodes->targetNode2 == UINT_MAX)
|
if(phantomNodes->startPhantom.startNode == UINT_MAX || phantomNodes->startPhantom.targetNode == UINT_MAX || phantomNodes->targetPhantom.startNode == UINT_MAX || phantomNodes->targetPhantom.targetNode == UINT_MAX)
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
|
|
||||||
if( (phantomNodes->startNode1 == phantomNodes->targetNode1 && phantomNodes->startNode2 == phantomNodes->targetNode2 ) ||
|
if( (phantomNodes->startPhantom.startNode == phantomNodes->startPhantom.targetNode && phantomNodes->targetPhantom.startNode == phantomNodes->targetPhantom.targetNode ) ||
|
||||||
(phantomNodes->startNode1 == phantomNodes->targetNode2 && phantomNodes->startNode2 == phantomNodes->targetNode1 ) )
|
(phantomNodes->startPhantom.startNode == phantomNodes->targetPhantom.targetNode && phantomNodes->targetPhantom.startNode == phantomNodes->startPhantom.targetNode) )
|
||||||
{
|
{
|
||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
EdgeID currentEdge = _graph->FindEdge( phantomNodes->startNode1, phantomNodes->startNode2 );
|
EdgeID currentEdge = _graph->FindEdge( phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode );
|
||||||
if(currentEdge == UINT_MAX){
|
if(currentEdge == UINT_MAX){
|
||||||
currentEdge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 );
|
currentEdge = _graph->FindEdge( phantomNodes->startPhantom.targetNode, phantomNodes->startPhantom.startNode );
|
||||||
reverse = true;
|
reverse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,34 +137,34 @@ public:
|
|||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(phantomNodes->startRatio < phantomNodes->targetRatio && _graph->GetEdgeData(currentEdge).forward) {
|
if(phantomNodes->startPhantom.ratio < phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward) {
|
||||||
onSameEdge = true;
|
onSameEdge = true;
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
|
||||||
} else if(phantomNodes->startRatio > phantomNodes->targetRatio && _graph->GetEdgeData(currentEdge).backward && !reverse)
|
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward && !reverse)
|
||||||
{
|
{
|
||||||
onSameEdge = true;
|
onSameEdge = true;
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
|
||||||
} else if(phantomNodes->startRatio < phantomNodes->targetRatio && _graph->GetEdgeData(currentEdge).backward) {
|
} else if(phantomNodes->startPhantom.ratio < phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward) {
|
||||||
onSameEdge = true;
|
onSameEdge = true;
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
|
||||||
} else if(phantomNodes->startRatio > phantomNodes->targetRatio && _graph->GetEdgeData(currentEdge).forward && _graph->GetEdgeData(currentEdge).backward) {
|
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward && _graph->GetEdgeData(currentEdge).backward) {
|
||||||
onSameEdge = true;
|
onSameEdge = true;
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
|
||||||
} else if(phantomNodes->startRatio > phantomNodes->targetRatio) {
|
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio) {
|
||||||
onSameEdgeReversed = true;
|
onSameEdgeReversed = true;
|
||||||
|
|
||||||
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
|
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
|
||||||
_forwardHeap.Insert(phantomNodes->startNode2, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode2);
|
_forwardHeap.Insert(phantomNodes->targetPhantom.startNode, absDouble( w*phantomNodes->startPhantom.ratio), phantomNodes->targetPhantom.startNode);
|
||||||
_insertedNodes.ForwInsert(phantomNodes->startNode2);
|
_insertedNodes.ForwInsert(phantomNodes->targetPhantom.startNode);
|
||||||
_backwardHeap.Insert(phantomNodes->startNode1, absDouble( w-w*phantomNodes->targetRatio), phantomNodes->startNode1);
|
_backwardHeap.Insert(phantomNodes->startPhantom.startNode, absDouble( w-w*phantomNodes->targetPhantom.ratio), phantomNodes->startPhantom.startNode);
|
||||||
_insertedNodes.BackInsert(phantomNodes->startNode1);
|
_insertedNodes.BackInsert(phantomNodes->startPhantom.startNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(phantomNodes->startNode1 != UINT_MAX) {
|
if(phantomNodes->startPhantom.startNode != UINT_MAX) {
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes->startNode1, phantomNodes->startNode2);
|
EdgeID edge = _graph->FindEdge( phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
edge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 );
|
edge = _graph->FindEdge( phantomNodes->startPhantom.targetNode, phantomNodes->startPhantom.startNode );
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
@ -175,18 +174,18 @@ public:
|
|||||||
EdgeWeight w = ed.distance;
|
EdgeWeight w = ed.distance;
|
||||||
|
|
||||||
if( (ed.backward && !startReverse) || (ed.forward && startReverse) ){
|
if( (ed.backward && !startReverse) || (ed.forward && startReverse) ){
|
||||||
_forwardHeap.Insert(phantomNodes->startNode1, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode1);
|
_forwardHeap.Insert(phantomNodes->startPhantom.startNode, absDouble( w*phantomNodes->startPhantom.ratio), phantomNodes->startPhantom.startNode);
|
||||||
_insertedNodes.ForwInsert(phantomNodes->startNode1);
|
_insertedNodes.ForwInsert(phantomNodes->startPhantom.startNode);
|
||||||
}
|
}
|
||||||
if( (ed.backward && startReverse) || (ed.forward && !startReverse) ) {
|
if( (ed.backward && startReverse) || (ed.forward && !startReverse) ) {
|
||||||
_forwardHeap.Insert(phantomNodes->startNode2, absDouble(w-w*phantomNodes->startRatio), phantomNodes->startNode2);
|
_forwardHeap.Insert(phantomNodes->startPhantom.targetNode, absDouble(w-w*phantomNodes->startPhantom.ratio), phantomNodes->startPhantom.targetNode);
|
||||||
_insertedNodes.ForwInsert(phantomNodes->startNode2);
|
_insertedNodes.ForwInsert(phantomNodes->startPhantom.targetNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(phantomNodes->targetNode1 != UINT_MAX && !onSameEdgeReversed) {
|
if(phantomNodes->startPhantom.targetNode!= UINT_MAX && !onSameEdgeReversed) {
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes->targetNode1, phantomNodes->targetNode2);
|
EdgeID edge = _graph->FindEdge( phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
edge = _graph->FindEdge( phantomNodes->targetNode2, phantomNodes->targetNode1 );
|
edge = _graph->FindEdge( phantomNodes->targetPhantom.targetNode, phantomNodes->targetPhantom.startNode);
|
||||||
targetReverse = true;
|
targetReverse = true;
|
||||||
}
|
}
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
@ -197,12 +196,12 @@ public:
|
|||||||
EdgeWeight w = ed.distance;
|
EdgeWeight w = ed.distance;
|
||||||
|
|
||||||
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) ) {
|
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) ) {
|
||||||
_backwardHeap.Insert(phantomNodes->targetNode2, absDouble( w*phantomNodes->targetRatio), phantomNodes->targetNode2);
|
_backwardHeap.Insert(phantomNodes->targetPhantom.targetNode, absDouble( w*phantomNodes->targetPhantom.ratio), phantomNodes->targetPhantom.targetNode);
|
||||||
_insertedNodes.BackInsert(phantomNodes->targetNode2);
|
_insertedNodes.BackInsert(phantomNodes->targetPhantom.targetNode);
|
||||||
}
|
}
|
||||||
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) ) {
|
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) ) {
|
||||||
_backwardHeap.Insert(phantomNodes->targetNode1, absDouble(w-w*phantomNodes->targetRatio), phantomNodes->targetNode1);
|
_backwardHeap.Insert(phantomNodes->targetPhantom.startNode, absDouble(w-w*phantomNodes->targetPhantom.ratio), phantomNodes->targetPhantom.startNode);
|
||||||
_insertedNodes.BackInsert(phantomNodes->targetNode1);
|
_insertedNodes.BackInsert(phantomNodes->targetPhantom.startNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// double time = get_timestamp();
|
// double time = get_timestamp();
|
||||||
@ -308,11 +307,20 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool FindPhantomNodeForCoordinate(const _Coordinate &location, PhantomNode & result) {
|
||||||
|
return nodeHelpDesk->FindPhantomNodeForCoordinate(location, result);
|
||||||
|
}
|
||||||
|
|
||||||
inline NodeID GetNameIDForOriginDestinationNodeID(NodeID s, NodeID t) const {
|
inline NodeID GetNameIDForOriginDestinationNodeID(NodeID s, NodeID t) const {
|
||||||
assert(s!=t);
|
if(s==t)
|
||||||
|
return 0;
|
||||||
EdgeID e = _graph->FindEdge( s, t );
|
EdgeID e = _graph->FindEdge( s, t );
|
||||||
if(e == UINT_MAX)
|
if(e == UINT_MAX)
|
||||||
e = _graph->FindEdge( t, s );
|
e = _graph->FindEdge( t, s );
|
||||||
|
if(UINT_MAX == e) {
|
||||||
|
INFO("edge not found for start " << s << ", target " << t)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
assert(e != UINT_MAX);
|
assert(e != UINT_MAX);
|
||||||
const EdgeData ed = _graph->GetEdgeData(e);
|
const EdgeData ed = _graph->GetEdgeData(e);
|
||||||
return ed.middleName.nameID;
|
return ed.middleName.nameID;
|
||||||
|
@ -33,13 +33,16 @@ public:
|
|||||||
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
||||||
void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||||
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
reply.content += "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd\">";
|
reply.content += "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
||||||
|
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||||
|
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
||||||
|
"\">";
|
||||||
reply.content += "<rte>";
|
reply.content += "<rte>";
|
||||||
if(distance != UINT_MAX && route->routeSegments.size()) {
|
if(distance != UINT_MAX && route->routeSegments.size()) {
|
||||||
|
|
||||||
convertInternalLatLonToString(phantomNodes->startCoord.lat, tmp);
|
convertInternalLatLonToString(phantomNodes->startPhantom.location.lat, tmp);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||||
convertInternalLatLonToString(phantomNodes->startCoord.lon, tmp);
|
convertInternalLatLonToString(phantomNodes->startPhantom.location.lon, tmp);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||||
|
|
||||||
for(unsigned segmentIdx = 0; segmentIdx < route->routeSegments.size(); segmentIdx++) {
|
for(unsigned segmentIdx = 0; segmentIdx < route->routeSegments.size(); segmentIdx++) {
|
||||||
@ -57,9 +60,9 @@ public:
|
|||||||
reply.content +="</rtept>";
|
reply.content +="</rtept>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
convertInternalLatLonToString(phantomNodes->targetCoord.lat, tmp);
|
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lat, tmp);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||||
convertInternalLatLonToString(phantomNodes->targetCoord.lon, tmp);
|
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lon, tmp);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||||
}
|
}
|
||||||
reply.content += "</rte></gpx>";
|
reply.content += "</rte></gpx>";
|
||||||
|
@ -47,26 +47,26 @@ public:
|
|||||||
"\"status_message\": \"Found route between points\",";
|
"\"status_message\": \"Found route between points\",";
|
||||||
|
|
||||||
//Put first segment of route into geometry
|
//Put first segment of route into geometry
|
||||||
polyline.push_back(phantomNodes->startCoord);
|
polyline.push_back(phantomNodes->startPhantom.location);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startCoord;
|
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
|
||||||
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
||||||
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
|
||||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode2, phantomNodes->startNode1);
|
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
|
||||||
|
|
||||||
//If we have a route, i.e. start and dest not on same edge, than get it
|
//If we have a route, i.e. start and dest not on same edge, than get it
|
||||||
if(rawRoute->routeSegments[0].size() > 0)
|
if(rawRoute->routeSegments[0].size() > 0)
|
||||||
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||||
else
|
else
|
||||||
descriptorState.tmpCoord = phantomNodes->targetCoord;
|
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||||
|
|
||||||
descriptorState.previousCoordinate = phantomNodes->startCoord;
|
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
|
||||||
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
||||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
||||||
|
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
//Get Heading
|
//Get Heading
|
||||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||||
getDirectionOfInstruction(angle, directionOfInstruction);
|
getDirectionOfInstruction(angle, directionOfInstruction);
|
||||||
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ public:
|
|||||||
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
|
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
|
||||||
|
|
||||||
if ( UINT_MAX == lastNodeID) {
|
if ( UINT_MAX == lastNodeID) {
|
||||||
lastNodeID = (phantomNodes->startNode1 == (*path.begin()).node ? phantomNodes->startNode2 : phantomNodes->startNode1);
|
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->startPhantom.targetNode : phantomNodes->startPhantom.startNode);
|
||||||
}
|
}
|
||||||
//Check, if there is overlap between current and previous route segment
|
//Check, if there is overlap between current and previous route segment
|
||||||
//if not, than we are fine and can route over this edge without paying any special attention.
|
//if not, than we are fine and can route over this edge without paying any special attention.
|
||||||
@ -83,16 +83,16 @@ public:
|
|||||||
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||||
polyline.push_back(descriptorState.currentCoordinate);
|
polyline.push_back(descriptorState.currentCoordinate);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startNode1 ? rawRoute->segmentEndCoordinates[segmentIdx].startNode2 : rawRoute->segmentEndCoordinates[segmentIdx].startNode1);
|
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||||
|
|
||||||
//output of the via nodes coordinates
|
//output of the via nodes coordinates
|
||||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startCoord);
|
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||||
//Make a special announement to do a U-Turn.
|
//Make a special announement to do a U-Turn.
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
descriptorState.routeInstructionString += ",";
|
descriptorState.routeInstructionString += ",";
|
||||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startCoord);
|
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
@ -105,12 +105,12 @@ public:
|
|||||||
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
||||||
assert(segmentIdx != 0);
|
assert(segmentIdx != 0);
|
||||||
//routeInstructionString += "reaching via node: ";
|
//routeInstructionString += "reaching via node: ";
|
||||||
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startCoord;
|
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||||
|
|
||||||
polyline.push_back(descriptorState.currentCoordinate);
|
polyline.push_back(descriptorState.currentCoordinate);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startCoord);
|
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||||
@ -155,18 +155,19 @@ public:
|
|||||||
}
|
}
|
||||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||||
lastNodeID = it->node;
|
lastNodeID = it->node;
|
||||||
if(it != path.begin()) {
|
if(it != path.begin()-1) {
|
||||||
descriptorState.previousCoordinate = descriptorState.currentCoordinate;
|
descriptorState.previousCoordinate = descriptorState.currentCoordinate;
|
||||||
descriptorState.currentCoordinate = descriptorState.nextCoordinate;
|
descriptorState.currentCoordinate = descriptorState.nextCoordinate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
|
||||||
descriptorState.nextCoordinate = phantomNodes->targetCoord;
|
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
|
||||||
|
|
||||||
|
polyline.push_back(descriptorState.currentCoordinate);
|
||||||
|
descriptorState.geometryCounter++;
|
||||||
|
|
||||||
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
||||||
polyline.push_back(descriptorState.currentCoordinate);
|
|
||||||
descriptorState.geometryCounter++;
|
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
descriptorState.routeInstructionString += ",";
|
descriptorState.routeInstructionString += ",";
|
||||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||||
@ -176,7 +177,7 @@ public:
|
|||||||
}
|
}
|
||||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||||
polyline.push_back(phantomNodes->targetCoord);
|
polyline.push_back(phantomNodes->targetPhantom.location);
|
||||||
descriptorState.geometryCounter++;
|
descriptorState.geometryCounter++;
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
summary.BuildDurationAndLengthStrings(descriptorState.entireDistance, distance);
|
summary.BuildDurationAndLengthStrings(descriptorState.entireDistance, distance);
|
||||||
@ -224,7 +225,12 @@ public:
|
|||||||
if(segmentIdx > 1)
|
if(segmentIdx > 1)
|
||||||
reply.content += ",";
|
reply.content += ",";
|
||||||
reply.content += "[";
|
reply.content += "[";
|
||||||
convertInternalReversedCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, tmp);
|
if(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
|
||||||
|
convertInternalReversedCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
|
||||||
|
else
|
||||||
|
convertInternalReversedCoordinateToString(rawRoute->rawViaNodeCoordinates[segmentIdx], tmp);
|
||||||
|
// INFO(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||||
|
// INFO(rawRoute->rawViaNodeCoordinates[segmentIdx]);
|
||||||
reply.content += tmp;
|
reply.content += tmp;
|
||||||
reply.content += "]";
|
reply.content += "]";
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,25 @@ public:
|
|||||||
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
|
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
|
||||||
|
|
||||||
//Put first segment of route into geometry
|
//Put first segment of route into geometry
|
||||||
appendCoordinateToString(phantomNodes->startCoord, descriptorState.routeGeometryString);
|
appendCoordinateToString(phantomNodes->startPhantom.location, descriptorState.routeGeometryString);
|
||||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startCoord;
|
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
|
||||||
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
||||||
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->startNode2, phantomNodes->startNode1);
|
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
|
||||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode2, phantomNodes->startNode1);
|
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
|
||||||
|
|
||||||
//If we have a route, i.e. start and dest not on same edge, than get it
|
//If we have a route, i.e. start and dest not on same edge, than get it
|
||||||
if(rawRoute->routeSegments[0].size() > 0)
|
if(rawRoute->routeSegments[0].size() > 0)
|
||||||
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||||
else
|
else
|
||||||
descriptorState.tmpCoord = phantomNodes->targetCoord;
|
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||||
|
|
||||||
descriptorState.previousCoordinate = phantomNodes->startCoord;
|
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
|
||||||
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
||||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
||||||
|
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
//Get Heading
|
//Get Heading
|
||||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||||
getDirectionOfInstruction(angle, directionOfInstruction);
|
getDirectionOfInstruction(angle, directionOfInstruction);
|
||||||
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
||||||
}
|
}
|
||||||
@ -72,21 +72,21 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( UINT_MAX == lastNodeID) {
|
if ( UINT_MAX == lastNodeID) {
|
||||||
lastNodeID = (phantomNodes->startNode1 == (*path.begin()).node ? phantomNodes->startNode2 : phantomNodes->startNode1);
|
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->targetPhantom.startNode : phantomNodes->startPhantom.startNode);
|
||||||
}
|
}
|
||||||
//Check, if there is overlap between current and previous route segment
|
//Check, if there is overlap between current and previous route segment
|
||||||
//if not, than we are fine and can route over this edge without paying any special attention.
|
//if not, than we are fine and can route over this edge without paying any special attention.
|
||||||
if(lastNodeID == (*path.begin()).node) {
|
if(lastNodeID == (*path.begin()).node) {
|
||||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||||
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startNode1 ? rawRoute->segmentEndCoordinates[segmentIdx].startNode2 : rawRoute->segmentEndCoordinates[segmentIdx].startNode1);
|
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||||
|
|
||||||
//output of the via nodes coordinates
|
//output of the via nodes coordinates
|
||||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, descriptorState.routeGeometryString);
|
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||||
//Make a special announement to do a U-Turn.
|
//Make a special announement to do a U-Turn.
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
|
|
||||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startCoord);
|
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
@ -98,10 +98,10 @@ public:
|
|||||||
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
||||||
assert(segmentIdx != 0);
|
assert(segmentIdx != 0);
|
||||||
//routeInstructionString += "\nreaching via node: \n";
|
//routeInstructionString += "\nreaching via node: \n";
|
||||||
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startCoord;
|
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, descriptorState.routeGeometryString);
|
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||||
if(config.instructions) {
|
if(config.instructions) {
|
||||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
@ -149,8 +149,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.targetNode, phantomNodes->targetPhantom.targetNode);
|
||||||
descriptorState.nextCoordinate = phantomNodes->targetCoord;
|
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
|
||||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||||
|
|
||||||
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
||||||
@ -161,7 +161,7 @@ public:
|
|||||||
}
|
}
|
||||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||||
appendCoordinateToString(phantomNodes->targetCoord, descriptorState.routeGeometryString);
|
appendCoordinateToString(phantomNodes->targetPhantom.location, descriptorState.routeGeometryString);
|
||||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||||
descriptorState.SetStartOfSegment();
|
descriptorState.SetStartOfSegment();
|
||||||
//compute distance/duration for route summary
|
//compute distance/duration for route summary
|
||||||
@ -197,7 +197,7 @@ public:
|
|||||||
reply.content += "<name>Via Point 1</name>";
|
reply.content += "<name>Via Point 1</name>";
|
||||||
reply.content += "<Point>";
|
reply.content += "<Point>";
|
||||||
reply.content += "<coordinates>";
|
reply.content += "<coordinates>";
|
||||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, reply.content);
|
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
|
||||||
reply.content += "</coordinates>";
|
reply.content += "</coordinates>";
|
||||||
reply.content += "</Point>";
|
reply.content += "</Point>";
|
||||||
reply.content += "</Placemark>";
|
reply.content += "</Placemark>";
|
||||||
|
@ -22,12 +22,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#define RAWROUTEDATA_H_
|
#define RAWROUTEDATA_H_
|
||||||
|
|
||||||
struct RawRouteData {
|
struct RawRouteData {
|
||||||
RawRouteData(unsigned size) {
|
void Resize() {
|
||||||
|
unsigned size = rawViaNodeCoordinates.size()-1;
|
||||||
routeSegments.resize(size);
|
routeSegments.resize(size);
|
||||||
segmentEndCoordinates.resize(size);
|
segmentEndCoordinates.resize(size);
|
||||||
}
|
}
|
||||||
std::vector< std::vector< _PathData > > routeSegments;
|
std::vector< std::vector< _PathData > > routeSegments;
|
||||||
std::vector< PhantomNodes > segmentEndCoordinates;
|
std::vector< PhantomNodes > segmentEndCoordinates;
|
||||||
|
std::vector< _Coordinate > rawViaNodeCoordinates;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RAWROUTEDATA_H_ */
|
#endif /* RAWROUTEDATA_H_ */
|
||||||
|
@ -95,7 +95,7 @@ public:
|
|||||||
_Coordinate targetCoord(lat2, lon2);
|
_Coordinate targetCoord(lat2, lon2);
|
||||||
|
|
||||||
vector< _PathData > * path = new vector< _PathData >();
|
vector< _PathData > * path = new vector< _PathData >();
|
||||||
RawRouteData * rawRoute = new RawRouteData(0);
|
RawRouteData * rawRoute = new RawRouteData();
|
||||||
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);
|
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path);
|
||||||
|
@ -32,6 +32,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "BaseDescriptor.h"
|
#include "BaseDescriptor.h"
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
|
#include "GPXDescriptor.h"
|
||||||
#include "KMLDescriptor.h"
|
#include "KMLDescriptor.h"
|
||||||
#include "JSONDescriptor.h"
|
#include "JSONDescriptor.h"
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ public:
|
|||||||
descriptorTable.Set("", 0); //default descriptor
|
descriptorTable.Set("", 0); //default descriptor
|
||||||
descriptorTable.Set("kml", 0);
|
descriptorTable.Set("kml", 0);
|
||||||
descriptorTable.Set("json", 1);
|
descriptorTable.Set("json", 1);
|
||||||
|
descriptorTable.Set("gpx", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ViaRoutePlugin() {
|
~ViaRoutePlugin() {
|
||||||
@ -113,13 +115,13 @@ public:
|
|||||||
|
|
||||||
_Coordinate startCoord(lat1, lon1);
|
_Coordinate startCoord(lat1, lon1);
|
||||||
_Coordinate targetCoord(lat2, lon2);
|
_Coordinate targetCoord(lat2, lon2);
|
||||||
std::vector<_Coordinate> viaPointVector;
|
RawRouteData rawRoute;
|
||||||
|
|
||||||
if(false == checkCoord(startCoord) || false == checkCoord(targetCoord)) {
|
if(false == checkCoord(startCoord) || false == checkCoord(targetCoord)) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
viaPointVector.push_back(startCoord);
|
rawRoute.rawViaNodeCoordinates.push_back(startCoord);
|
||||||
|
|
||||||
std::cout << "[debug] number of vianodes: " << routeParameters.viaPoints.size() << std::endl;
|
std::cout << "[debug] number of vianodes: " << routeParameters.viaPoints.size() << std::endl;
|
||||||
for(unsigned i = 0; i < routeParameters.viaPoints.size(); i++) {
|
for(unsigned i = 0; i < routeParameters.viaPoints.size(); i++) {
|
||||||
@ -130,53 +132,53 @@ public:
|
|||||||
}
|
}
|
||||||
int vialat = static_cast<int>(100000.*atof(textCoord[0].c_str()));
|
int vialat = static_cast<int>(100000.*atof(textCoord[0].c_str()));
|
||||||
int vialon = static_cast<int>(100000.*atof(textCoord[1].c_str()));
|
int vialon = static_cast<int>(100000.*atof(textCoord[1].c_str()));
|
||||||
std::cout << "[debug] via" << i << ": " << vialat << "," << vialon << std::endl;
|
// std::cout << "[debug] via" << i << ": " << vialat << "," << vialon << std::endl;
|
||||||
_Coordinate viaCoord(vialat, vialon);
|
_Coordinate viaCoord(vialat, vialon);
|
||||||
if(false == checkCoord(viaCoord)) {
|
if(false == checkCoord(viaCoord)) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
viaPointVector.push_back(viaCoord);
|
rawRoute.rawViaNodeCoordinates.push_back(viaCoord);
|
||||||
|
}
|
||||||
|
rawRoute.rawViaNodeCoordinates.push_back(targetCoord);
|
||||||
|
vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size());
|
||||||
|
#pragma omp parallel for
|
||||||
|
for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); i++) {
|
||||||
|
threadData[omp_get_thread_num()]->sEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
|
||||||
}
|
}
|
||||||
viaPointVector.push_back(targetCoord);
|
|
||||||
|
|
||||||
|
rawRoute.Resize();
|
||||||
RawRouteData * rawRoute = new RawRouteData(viaPointVector.size()-1);
|
|
||||||
|
|
||||||
unsigned distance = 0;
|
unsigned distance = 0;
|
||||||
bool errorOccurredFlag = false;
|
bool errorOccurredFlag = false;
|
||||||
double time = get_timestamp();
|
double time = get_timestamp();
|
||||||
|
|
||||||
//#pragma omp parallel for reduction(+:distance)
|
|
||||||
for(unsigned i = 0; i < viaPointVector.size()-1; i++) {
|
//#pragma omp parallel for reduction(+:distance)
|
||||||
|
for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) {
|
||||||
PhantomNodes & segmentPhantomNodes = threadData[omp_get_thread_num()]->phantomNodesOfSegment;
|
PhantomNodes & segmentPhantomNodes = threadData[omp_get_thread_num()]->phantomNodesOfSegment;
|
||||||
|
segmentPhantomNodes.startPhantom = phantomNodeVector[i];
|
||||||
|
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
|
||||||
std::vector< _PathData > path;
|
std::vector< _PathData > path;
|
||||||
threadData[omp_get_thread_num()]->sEngine->FindRoutingStarts(viaPointVector[i], viaPointVector[i+1], &segmentPhantomNodes);
|
|
||||||
threadData[omp_get_thread_num()]->distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(&segmentPhantomNodes, &path);
|
threadData[omp_get_thread_num()]->distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(&segmentPhantomNodes, &path);
|
||||||
|
|
||||||
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment) {
|
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment) {
|
||||||
errorOccurredFlag = true;
|
errorOccurredFlag = true;
|
||||||
|
cout << "Error occurred, path not found" << endl;
|
||||||
|
distance = UINT_MAX;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
distance += threadData[omp_get_thread_num()]->distanceOfSegment;
|
distance += threadData[omp_get_thread_num()]->distanceOfSegment;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Computing route segment " << i << std::endl;
|
|
||||||
|
|
||||||
//put segments at correct position of routes raw data
|
//put segments at correct position of routes raw data
|
||||||
rawRoute->segmentEndCoordinates[i] = (segmentPhantomNodes);
|
rawRoute.segmentEndCoordinates[i] = (segmentPhantomNodes);
|
||||||
rawRoute->routeSegments[i] = path;
|
rawRoute.routeSegments[i] = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
double time2 = get_timestamp();
|
double time2 = get_timestamp();
|
||||||
std::cout << "Finished routing after " << (time2-time) << "s" << std::endl;
|
std::cout << "Finished routing after " << (time2-time) << "s" << std::endl;
|
||||||
time = get_timestamp();
|
time = get_timestamp();
|
||||||
|
|
||||||
if(errorOccurredFlag) {
|
|
||||||
distance = UINT_MAX;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
|
|
||||||
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||||
@ -213,6 +215,10 @@ public:
|
|||||||
case 1:
|
case 1:
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
desc = new GPXDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
@ -222,7 +228,7 @@ public:
|
|||||||
PhantomNodes phantomNodes;
|
PhantomNodes phantomNodes;
|
||||||
threadData[0]->sEngine->FindRoutingStarts(startCoord, targetCoord, &phantomNodes);
|
threadData[0]->sEngine->FindRoutingStarts(startCoord, targetCoord, &phantomNodes);
|
||||||
desc->SetConfig(descriptorConfig);
|
desc->SetConfig(descriptorConfig);
|
||||||
desc->Run(reply, rawRoute, &phantomNodes, threadData[0]->sEngine, distance);
|
desc->Run(reply, &rawRoute, &phantomNodes, threadData[0]->sEngine, distance);
|
||||||
if("" != JSONParameter) {
|
if("" != JSONParameter) {
|
||||||
reply.content += ")\n";
|
reply.content += ")\n";
|
||||||
}
|
}
|
||||||
@ -253,6 +259,13 @@ public:
|
|||||||
reply.headers[2].value = "attachment; filename=\"route.json\"";
|
reply.headers[2].value = "attachment; filename=\"route.json\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "application/gpx+xml; charset=UTF-8";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.gpx\"";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
reply.headers[1].name = "Content-Type";
|
reply.headers[1].name = "Content-Type";
|
||||||
@ -268,7 +281,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
delete desc;
|
delete desc;
|
||||||
delete rawRoute;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
void handle_request(const Request& req, Reply& rep){
|
void handle_request(const Request& req, Reply& rep){
|
||||||
//parse command
|
//parse command
|
||||||
std::string request(req.uri);
|
std::string request(req.uri);
|
||||||
|
std::cout << "[r] " << request << std::endl;
|
||||||
std::string command;
|
std::string command;
|
||||||
std::size_t firstAmpPosition = request.find_first_of("&");
|
std::size_t firstAmpPosition = request.find_first_of("&");
|
||||||
command = request.substr(1,firstAmpPosition-1);
|
command = request.substr(1,firstAmpPosition-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user