Making via routes more stable
This commit is contained in:
parent
e93735903e
commit
83fca53d04
@ -209,6 +209,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DecreaseKey( NodeID node, Weight weight ) {
|
void DecreaseKey( NodeID node, Weight weight ) {
|
||||||
|
assert( UINT_MAX != node );
|
||||||
const Key index = nodeIndex[node];
|
const Key index = nodeIndex[node];
|
||||||
Key key = insertedNodes[index].key;
|
Key key = insertedNodes[index].key;
|
||||||
assert ( key != 0 );
|
assert ( key != 0 );
|
||||||
|
@ -48,7 +48,7 @@ struct PhantomNodes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PhantomsAreOnSameEdge() const {
|
bool PhantomsAreOnSameEdge() const {
|
||||||
return ((startPhantom.startNode == startPhantom.targetNode && targetPhantom.startNode == targetPhantom.targetNode ) || (startPhantom.startNode == targetPhantom.targetNode && targetPhantom.startNode == startPhantom.targetNode));
|
return ((startPhantom.startNode == targetPhantom.startNode && startPhantom.targetNode == targetPhantom.targetNode ) || (startPhantom.startNode == targetPhantom.targetNode && targetPhantom.startNode == startPhantom.targetNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtLeastOnePhantomNodeIsUINTMAX() const {
|
bool AtLeastOnePhantomNodeIsUINTMAX() const {
|
||||||
|
@ -85,7 +85,7 @@ struct _InsertedNodes {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef BinaryHeap< NodeID, int, int, _HeapData, ArrayStorage<NodeID, NodeID, false> > _Heap;
|
typedef BinaryHeap< NodeID, int, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
|
||||||
|
|
||||||
template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk>
|
template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk>
|
||||||
class SearchEngine {
|
class SearchEngine {
|
||||||
@ -108,102 +108,78 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ComputeRoute(PhantomNodes &phantomNodes, vector<_PathData > & path) {
|
unsigned int ComputeRoute(PhantomNodes &phantomNodes, vector<_PathData > & path) {
|
||||||
bool onSameEdge = false;
|
bool startEdgeIsReversedInGraph = false;
|
||||||
bool onSameEdgeReversed = false;
|
bool targetEdgeIsReversed = false;
|
||||||
bool startReverse = false;
|
|
||||||
bool targetReverse = false;
|
unsigned int _upperbound = UINT_MAX;
|
||||||
|
|
||||||
|
if(!phantomNodes.AtLeastOnePhantomNodeIsUINTMAX())
|
||||||
|
return _upperbound;
|
||||||
|
|
||||||
|
EdgeID sourceEdgeID = _graph->FindEdgeIndicateIfReverse( phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode, startEdgeIsReversedInGraph);
|
||||||
|
if(sourceEdgeID == UINT_MAX){
|
||||||
|
return _upperbound;
|
||||||
|
}
|
||||||
|
|
||||||
|
EdgeID targetEdgeID = _graph->FindEdgeIndicateIfReverse( phantomNodes.targetPhantom.startNode, phantomNodes.targetPhantom.targetNode, targetEdgeIsReversed);
|
||||||
|
if(targetEdgeID == UINT_MAX){
|
||||||
|
return _upperbound;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_InsertedNodes _insertedNodes;
|
_InsertedNodes _insertedNodes;
|
||||||
_Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes());
|
_Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes());
|
||||||
_Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes());
|
_Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes());
|
||||||
|
|
||||||
NodeID middle = ( NodeID ) 0;
|
NodeID middle = ( NodeID ) 0;
|
||||||
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
|
||||||
|
|
||||||
if(phantomNodes.startPhantom.startNode == UINT_MAX || phantomNodes.startPhantom.targetNode == UINT_MAX || phantomNodes.targetPhantom.startNode == UINT_MAX || phantomNodes.targetPhantom.targetNode == UINT_MAX)
|
if( phantomNodes.PhantomsAreOnSameEdge() ) {
|
||||||
return _upperbound;
|
const EdgeData& currentEdgeData = _graph->GetEdgeData(sourceEdgeID);
|
||||||
|
EdgeWeight w = currentEdgeData.distance;
|
||||||
|
|
||||||
if( (phantomNodes.startPhantom.startNode == phantomNodes.startPhantom.targetNode && phantomNodes.targetPhantom.startNode == phantomNodes.targetPhantom.targetNode ) ||
|
//check if target is reachable from start on same edge
|
||||||
(phantomNodes.startPhantom.startNode == phantomNodes.targetPhantom.targetNode && phantomNodes.targetPhantom.startNode == phantomNodes.startPhantom.targetNode) )
|
if(currentEdgeData.forward && currentEdgeData.backward) {
|
||||||
{
|
_upperbound = absDouble( w*phantomNodes.targetPhantom.ratio);
|
||||||
bool reverse = false;
|
return _upperbound/10;
|
||||||
EdgeID currentEdge = _graph->FindEdge( phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode );
|
} else {
|
||||||
if(currentEdge == UINT_MAX){
|
if((startEdgeIsReversedInGraph && (phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio)) || (!startEdgeIsReversedInGraph && (phantomNodes.startPhantom.ratio < phantomNodes.targetPhantom.ratio))) {
|
||||||
currentEdge = _graph->FindEdge( phantomNodes.startPhantom.targetNode, phantomNodes.startPhantom.startNode );
|
_backwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.startNode);
|
||||||
reverse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentEdge == UINT_MAX){
|
|
||||||
return _upperbound;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(phantomNodes.startPhantom.ratio < phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward) {
|
|
||||||
onSameEdge = true;
|
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
|
|
||||||
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward && !reverse)
|
|
||||||
{
|
|
||||||
onSameEdge = true;
|
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
|
|
||||||
} else if(phantomNodes.startPhantom.ratio < phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward) {
|
|
||||||
onSameEdge = true;
|
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
|
|
||||||
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward && _graph->GetEdgeData(currentEdge).backward) {
|
|
||||||
onSameEdge = true;
|
|
||||||
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
|
|
||||||
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio) {
|
|
||||||
onSameEdgeReversed = true;
|
|
||||||
|
|
||||||
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
|
|
||||||
_forwardHeap.Insert(phantomNodes.targetPhantom.startNode, absDouble( w*phantomNodes.startPhantom.ratio), phantomNodes.targetPhantom.startNode);
|
|
||||||
_insertedNodes.ForwInsert(phantomNodes.targetPhantom.startNode);
|
|
||||||
_backwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( w-w*phantomNodes.targetPhantom.ratio), phantomNodes.startPhantom.startNode);
|
|
||||||
_insertedNodes.BackInsert(phantomNodes.startPhantom.startNode);
|
_insertedNodes.BackInsert(phantomNodes.startPhantom.startNode);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(phantomNodes.startPhantom.startNode != UINT_MAX) {
|
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
|
|
||||||
if(edge == UINT_MAX){
|
|
||||||
edge = _graph->FindEdge( phantomNodes.startPhantom.targetNode, phantomNodes.startPhantom.startNode );
|
|
||||||
if(edge == UINT_MAX){
|
|
||||||
return _upperbound;
|
|
||||||
}
|
|
||||||
startReverse = true;
|
|
||||||
}
|
|
||||||
const EdgeData& ed = _graph->GetEdgeData(edge);
|
|
||||||
EdgeWeight w = ed.distance;
|
|
||||||
|
|
||||||
if( (ed.backward && !startReverse) || (ed.forward && startReverse) ){
|
|
||||||
_forwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.startNode);
|
|
||||||
_insertedNodes.ForwInsert(phantomNodes.startPhantom.startNode);
|
|
||||||
}
|
|
||||||
if( (ed.backward && startReverse) || (ed.forward && !startReverse) ) {
|
|
||||||
_forwardHeap.Insert(phantomNodes.startPhantom.targetNode, absDouble( w-w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.targetNode);
|
_forwardHeap.Insert(phantomNodes.startPhantom.targetNode, absDouble( w-w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.targetNode);
|
||||||
_insertedNodes.ForwInsert(phantomNodes.startPhantom.targetNode);
|
_insertedNodes.ForwInsert(phantomNodes.startPhantom.targetNode);
|
||||||
|
} else {
|
||||||
|
_upperbound = absDouble( w*phantomNodes.targetPhantom.ratio);
|
||||||
|
return _upperbound/10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(phantomNodes.startPhantom.targetNode!= UINT_MAX && !onSameEdgeReversed) {
|
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes.targetPhantom.startNode, phantomNodes.targetPhantom.targetNode);
|
|
||||||
if(edge == UINT_MAX){
|
|
||||||
edge = _graph->FindEdge( phantomNodes.targetPhantom.targetNode, phantomNodes.targetPhantom.startNode);
|
|
||||||
targetReverse = true;
|
|
||||||
}
|
|
||||||
if(edge == UINT_MAX){
|
|
||||||
return _upperbound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const EdgeData& ed = _graph->GetEdgeData(edge);
|
//insert start and/or target node of start edge
|
||||||
EdgeWeight w = ed.distance;
|
const EdgeData& sourceEdgeData = _graph->GetEdgeData(sourceEdgeID);
|
||||||
|
EdgeWeight sw = sourceEdgeData.distance;
|
||||||
|
|
||||||
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) ) {
|
if( (sourceEdgeData.backward && !startEdgeIsReversedInGraph) || (sourceEdgeData.forward && startEdgeIsReversedInGraph) ){
|
||||||
_backwardHeap.Insert(phantomNodes.targetPhantom.targetNode, absDouble( w*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.targetNode);
|
_forwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( sw*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.startNode);
|
||||||
|
_insertedNodes.ForwInsert(phantomNodes.startPhantom.startNode);
|
||||||
|
}
|
||||||
|
if( (sourceEdgeData.backward && startEdgeIsReversedInGraph) || (sourceEdgeData.forward && !startEdgeIsReversedInGraph) ) {
|
||||||
|
_forwardHeap.Insert(phantomNodes.startPhantom.targetNode, absDouble(sw-sw*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.targetNode);
|
||||||
|
_insertedNodes.ForwInsert(phantomNodes.startPhantom.targetNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
//insert start and/or target node of target edge id
|
||||||
|
const EdgeData& targetEdgeData = _graph->GetEdgeData(targetEdgeID);
|
||||||
|
EdgeWeight tw = targetEdgeData.distance;
|
||||||
|
|
||||||
|
if( (targetEdgeData.backward && !targetEdgeIsReversed) || (targetEdgeData.forward && targetEdgeIsReversed) ) {
|
||||||
|
_backwardHeap.Insert(phantomNodes.targetPhantom.targetNode, absDouble( tw*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.targetNode);
|
||||||
_insertedNodes.BackInsert(phantomNodes.targetPhantom.targetNode);
|
_insertedNodes.BackInsert(phantomNodes.targetPhantom.targetNode);
|
||||||
}
|
}
|
||||||
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) ) {
|
if( (targetEdgeData.backward && targetEdgeIsReversed) || (targetEdgeData.forward && !targetEdgeIsReversed) ) {
|
||||||
_backwardHeap.Insert(phantomNodes.targetPhantom.startNode, absDouble(w-w*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.startNode);
|
_backwardHeap.Insert(phantomNodes.targetPhantom.startNode, absDouble(tw-tw*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.startNode);
|
||||||
_insertedNodes.BackInsert(phantomNodes.targetPhantom.startNode);
|
_insertedNodes.BackInsert(phantomNodes.targetPhantom.startNode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
|
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
|
||||||
if ( _forwardHeap.Size() > 0 ) {
|
if ( _forwardHeap.Size() > 0 ) {
|
||||||
@ -214,8 +190,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( _upperbound == UINT_MAX ) {
|
||||||
if ( _upperbound == std::numeric_limits< unsigned int >::max() || onSameEdge ) {
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +201,7 @@ public:
|
|||||||
pathNode = _forwardHeap.GetData( pathNode ).parent;
|
pathNode = _forwardHeap.GetData( pathNode ).parent;
|
||||||
packedPath.push_front( pathNode );
|
packedPath.push_front( pathNode );
|
||||||
}
|
}
|
||||||
// NodeID realStart = pathNode;
|
|
||||||
packedPath.push_back( middle );
|
packedPath.push_back( middle );
|
||||||
pathNode = middle;
|
pathNode = middle;
|
||||||
|
|
||||||
@ -241,54 +216,47 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
packedPath.clear();
|
packedPath.clear();
|
||||||
|
|
||||||
return _upperbound/10;
|
return _upperbound/10;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ComputeDistanceBetweenNodes(NodeID start, NodeID target) {
|
unsigned int ComputeDistanceBetweenNodes(NodeID start, NodeID target) {
|
||||||
_Heap * _forwardHeap = new _Heap(_graph->GetNumberOfNodes());
|
_Heap _forwardHeap(_graph->GetNumberOfNodes());
|
||||||
_Heap * _backwardHeap = new _Heap(_graph->GetNumberOfNodes());
|
_Heap _backwardHeap(_graph->GetNumberOfNodes());
|
||||||
NodeID middle = ( NodeID ) 0;
|
NodeID middle(UINT_MAX);
|
||||||
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
unsigned int _upperbound = UINT_MAX;
|
||||||
|
|
||||||
_forwardHeap->Insert(start, 0, start);
|
_forwardHeap.Insert(start, 0, start);
|
||||||
_backwardHeap->Insert(target, 0, target);
|
_backwardHeap.Insert(target, 0, target);
|
||||||
|
|
||||||
while(_forwardHeap->Size() + _backwardHeap->Size() > 0)
|
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
|
||||||
{
|
if ( _forwardHeap.Size() > 0 ) {
|
||||||
if ( _forwardHeap->Size() > 0 ) {
|
|
||||||
_RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound );
|
_RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound );
|
||||||
}
|
}
|
||||||
if ( _backwardHeap->Size() > 0 ) {
|
if ( _backwardHeap.Size() > 0 ) {
|
||||||
_RoutingStep( _backwardHeap, _forwardHeap, false, &middle, &_upperbound );
|
_RoutingStep( _backwardHeap, _forwardHeap, false, &middle, &_upperbound );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ComputeDistanceBetweenNodesWithStats(NodeID start, NodeID target, _Statistics& stats) {
|
unsigned int ComputeDistanceBetweenNodesWithStats(NodeID start, NodeID target, _Statistics& stats) {
|
||||||
_Heap * _forwardHeap = new _Heap(_graph->GetNumberOfNodes());
|
_Heap _forwardHeap(_graph->GetNumberOfNodes());
|
||||||
_Heap * _backwardHeap = new _Heap(_graph->GetNumberOfNodes());
|
_Heap _backwardHeap(_graph->GetNumberOfNodes());
|
||||||
NodeID middle = ( NodeID ) 0;
|
NodeID middle(UINT_MAX);
|
||||||
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
unsigned int _upperbound = UINT_MAX;
|
||||||
|
|
||||||
_forwardHeap->Insert(start, 0, start);
|
_forwardHeap.Insert(start, 0, start);
|
||||||
_backwardHeap->Insert(target, 0, target);
|
_backwardHeap.Insert(target, 0, target);
|
||||||
stats.insertedNodes += 2;
|
stats.insertedNodes += 2;
|
||||||
|
|
||||||
while(_forwardHeap->Size() + _backwardHeap->Size() > 0)
|
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
|
||||||
{
|
if ( _forwardHeap.Size() > 0 ) {
|
||||||
if ( _forwardHeap->Size() > 0 ) {
|
|
||||||
_RoutingStepWithStats( _forwardHeap, _backwardHeap, true, &middle, &_upperbound, stats );
|
_RoutingStepWithStats( _forwardHeap, _backwardHeap, true, &middle, &_upperbound, stats );
|
||||||
}
|
}
|
||||||
if ( _backwardHeap->Size() > 0 ) {
|
if ( _backwardHeap.Size() > 0 ) {
|
||||||
_RoutingStepWithStats( _backwardHeap, _forwardHeap, false, &middle, &_upperbound, stats );
|
_RoutingStepWithStats( _backwardHeap, _forwardHeap, false, &middle, &_upperbound, stats );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,13 +277,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline NodeID GetNameIDForOriginDestinationNodeID(NodeID s, NodeID t) const {
|
inline NodeID GetNameIDForOriginDestinationNodeID(NodeID s, NodeID t) const {
|
||||||
|
//INFO("Getting nameID for s=" << s << " and t=" << t);
|
||||||
if(s==t)
|
if(s==t)
|
||||||
return 0;
|
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) {
|
if(UINT_MAX == e) {
|
||||||
INFO("edge not found for start " << s << ", target " << t)
|
// INFO("edge not found for start " << s << ", target " << t)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(e != UINT_MAX);
|
assert(e != UINT_MAX);
|
||||||
@ -342,7 +311,6 @@ public:
|
|||||||
return ( GetEscapedNameForNameID(nameID) );
|
return ( GetEscapedNameForNameID(nameID) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
|
inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
|
||||||
return ( (nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID)) );
|
return ( (nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID)) );
|
||||||
}
|
}
|
||||||
@ -357,9 +325,9 @@ public:
|
|||||||
return ed.type;
|
return ed.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void RegisterThread(const unsigned k, const unsigned v) {
|
// inline void RegisterThread(const unsigned k, const unsigned v) {
|
||||||
nodeHelpDesk->RegisterThread(k,v);
|
// nodeHelpDesk->RegisterThread(k,v);
|
||||||
}
|
// }
|
||||||
private:
|
private:
|
||||||
|
|
||||||
inline void _RoutingStep(_Heap& _forwardHeap, _Heap &_backwardHeap, const bool& forwardDirection, NodeID * middle, unsigned int * _upperbound) {
|
inline void _RoutingStep(_Heap& _forwardHeap, _Heap &_backwardHeap, const bool& forwardDirection, NodeID * middle, unsigned int * _upperbound) {
|
||||||
@ -379,14 +347,10 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
for ( typename GraphT::EdgeIterator edge = _graph->BeginEdges( node ); edge < _graph->EndEdges(node); edge++ ) {
|
for ( typename GraphT::EdgeIterator edge = _graph->BeginEdges( node ); edge < _graph->EndEdges(node); edge++ ) {
|
||||||
//const EdgeData& ed = _graph->GetEdgeData(edge);
|
|
||||||
// if(!ed.shortcut)
|
|
||||||
// continue;
|
|
||||||
const NodeID to = _graph->GetTarget(edge);
|
const NodeID to = _graph->GetTarget(edge);
|
||||||
const EdgeWeight edgeWeight = _graph->GetEdgeData(edge).distance;
|
const EdgeWeight edgeWeight = _graph->GetEdgeData(edge).distance;
|
||||||
|
|
||||||
assert( edgeWeight > 0 );
|
assert( edgeWeight > 0 );
|
||||||
//const int toDistance = distance + edgeWeight;
|
|
||||||
|
|
||||||
//Stalling
|
//Stalling
|
||||||
bool backwardDirectionFlag = (!forwardDirection) ? _graph->GetEdgeData(edge).forward : _graph->GetEdgeData(edge).backward;
|
bool backwardDirectionFlag = (!forwardDirection) ? _graph->GetEdgeData(edge).forward : _graph->GetEdgeData(edge).backward;
|
||||||
@ -419,18 +383,6 @@ private:
|
|||||||
//new parent
|
//new parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(forwardDirection ? ed.forward : ed.backward ) {
|
|
||||||
// //New Node discovered -> Add to Heap + Node Info Storage
|
|
||||||
// if ( !_forwardHeap->WasInserted( to ) ) {
|
|
||||||
// _forwardHeap->Insert( to, toDistance, node );
|
|
||||||
// }
|
|
||||||
// //Found a shorter Path -> Update distance
|
|
||||||
// else if ( toDistance < _forwardHeap->GetKey( to ) ) {
|
|
||||||
// _forwardHeap->GetData( to ).parent = node;
|
|
||||||
// _forwardHeap->DecreaseKey( to, toDistance );
|
|
||||||
// //new parent
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,42 +439,32 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< _PathData >& path ) {
|
inline 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;
|
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++) {
|
||||||
{
|
|
||||||
const EdgeWeight weight = _graph->GetEdgeData(eit).distance;
|
const EdgeWeight weight = _graph->GetEdgeData(eit).distance;
|
||||||
{
|
if(_graph->GetTarget(eit) == target && weight < smallestWeight && _graph->GetEdgeData(eit).forward) {
|
||||||
if(_graph->GetTarget(eit) == target && weight < smallestWeight && _graph->GetEdgeData(eit).forward)
|
|
||||||
{
|
|
||||||
smallestEdge = eit; smallestWeight = weight;
|
smallestEdge = eit; smallestWeight = weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if(smallestEdge == SPECIAL_EDGEID) {
|
||||||
if(smallestEdge == SPECIAL_EDGEID)
|
for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(target); eit < _graph->EndEdges(target); eit++) {
|
||||||
{
|
|
||||||
for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(target); eit < _graph->EndEdges(target); eit++)
|
|
||||||
{
|
|
||||||
const EdgeWeight weight = _graph->GetEdgeData(eit).distance;
|
const EdgeWeight weight = _graph->GetEdgeData(eit).distance;
|
||||||
{
|
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;
|
forward = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
assert(smallestWeight != SPECIAL_EDGEID); //no edge found. This should not happen at all!
|
assert(smallestWeight != SPECIAL_EDGEID); //no edge found. This should not happen at all!
|
||||||
|
|
||||||
const EdgeData& ed = _graph->GetEdgeData(smallestEdge);
|
const EdgeData& ed = _graph->GetEdgeData(smallestEdge);
|
||||||
if(ed.shortcut)
|
if(ed.shortcut) {//unpack
|
||||||
{//unpack
|
|
||||||
const NodeID middle = ed.middleName.middle;
|
const NodeID middle = ed.middleName.middle;
|
||||||
_UnpackEdge(source, middle, path);
|
_UnpackEdge(source, middle, path);
|
||||||
_UnpackEdge(middle, target, path);
|
_UnpackEdge(middle, target, path);
|
||||||
|
@ -126,6 +126,11 @@ public:
|
|||||||
return smallestEdge;
|
return smallestEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EdgeIterator FindEdgeInEitherDirection( const NodeIterator &from, const NodeIterator &to ) const {
|
||||||
|
EdgeIterator tmp = FindEdge( from, to );
|
||||||
|
return (UINT_MAX != tmp ? tmp : FindEdge( to, from ));
|
||||||
|
}
|
||||||
|
|
||||||
EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator &from, const NodeIterator &to, bool & result ) const {
|
EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator &from, const NodeIterator &to, bool & result ) const {
|
||||||
EdgeIterator tmp = FindEdge( from, to );
|
EdgeIterator tmp = FindEdge( from, to );
|
||||||
if(UINT_MAX == tmp) {
|
if(UINT_MAX == tmp) {
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
|
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
|
||||||
inputReader = inputReaderFactory(filename);
|
inputReader = inputReaderFactory(filename);
|
||||||
}
|
}
|
||||||
~XMLParser() {}
|
virtual ~XMLParser() {}
|
||||||
|
|
||||||
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way), bool (*addressCallbackPointer)(_Node, HashTable<std::string, std::string>) ) {
|
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way), bool (*addressCallbackPointer)(_Node, HashTable<std::string, std::string>) ) {
|
||||||
nodeCallback = *nodeCallbackPointer;
|
nodeCallback = *nodeCallbackPointer;
|
||||||
|
@ -25,9 +25,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/StaticGraph.h"
|
#include "../DataStructures/StaticGraph.h"
|
||||||
#include "../Util/GraphLoader.h"
|
#include "../Util/GraphLoader.h"
|
||||||
|
|
||||||
typedef StaticGraph<EdgeData>::InputEdge InputEdge;
|
typedef StaticGraph<EdgeData> QueryGraph;
|
||||||
|
typedef QueryGraph::InputEdge InputEdge;
|
||||||
|
|
||||||
struct ObjectsForQueryStruct {
|
struct ObjectsForQueryStruct {
|
||||||
|
NodeInformationHelpDesk * nodeHelpDesk;
|
||||||
|
std::vector<std::string> * names;
|
||||||
|
QueryGraph * graph;
|
||||||
|
|
||||||
ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
|
ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
|
||||||
std::cout << "[objects] loading query data structures ..." << std::flush;
|
std::cout << "[objects] loading query data structures ..." << std::flush;
|
||||||
//Init nearest neighbor data structure
|
//Init nearest neighbor data structure
|
||||||
@ -37,14 +42,14 @@ struct ObjectsForQueryStruct {
|
|||||||
|
|
||||||
ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
|
ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
|
||||||
//Deserialize road network graph
|
//Deserialize road network graph
|
||||||
std::vector< InputEdge> * edgeList = new std::vector< InputEdge>();
|
std::vector< InputEdge> edgeList;
|
||||||
readHSGRFromStream(hsgrInStream, edgeList);
|
readHSGRFromStream(hsgrInStream, edgeList);
|
||||||
graph = new StaticGraph<EdgeData>(nodeHelpDesk->getNumberOfNodes()-1, *edgeList);
|
graph = new QueryGraph(nodeHelpDesk->getNumberOfNodes()-1, edgeList);
|
||||||
delete edgeList;
|
std::vector< InputEdge >().swap( edgeList ); //free memory
|
||||||
|
|
||||||
//deserialize street name list
|
//deserialize street name list
|
||||||
ifstream namesInStream(namesPath.c_str(), ios::binary);
|
ifstream namesInStream(namesPath.c_str(), ios::binary);
|
||||||
unsigned size = 0;
|
unsigned size(0);
|
||||||
namesInStream.read((char *)&size, sizeof(unsigned));
|
namesInStream.read((char *)&size, sizeof(unsigned));
|
||||||
names = new std::vector<std::string>();
|
names = new std::vector<std::string>();
|
||||||
|
|
||||||
@ -67,10 +72,6 @@ struct ObjectsForQueryStruct {
|
|||||||
delete graph;
|
delete graph;
|
||||||
delete nodeHelpDesk;
|
delete nodeHelpDesk;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
|
||||||
std::vector<std::string> * names;
|
|
||||||
StaticGraph<EdgeData> * graph;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OBJECTFORPLUGINSTRUCT_H_ */
|
#endif /* OBJECTFORPLUGINSTRUCT_H_ */
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
descriptorTable.Set("gpx", 2);
|
descriptorTable.Set("gpx", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RoutePlugin() {
|
virtual ~RoutePlugin() {
|
||||||
DELETE(sEngine);
|
DELETE(sEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
descriptorTable.Set("gpx", 2);
|
descriptorTable.Set("gpx", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ViaRoutePlugin() {
|
virtual ~ViaRoutePlugin() {
|
||||||
for ( unsigned threadNum = 0; threadNum < threadData.size(); threadNum++ ) {
|
for ( unsigned threadNum = 0; threadNum < threadData.size(); threadNum++ ) {
|
||||||
DELETE( threadData[threadNum] );
|
DELETE( threadData[threadNum] );
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ public:
|
|||||||
std::vector< _PathData > path;
|
std::vector< _PathData > path;
|
||||||
int distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(segmentPhantomNodes, path);
|
int distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(segmentPhantomNodes, path);
|
||||||
|
|
||||||
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment || path.empty()) {
|
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment ) {
|
||||||
errorOccurredFlag = true;
|
errorOccurredFlag = true;
|
||||||
cout << "Error occurred, path not found" << endl;
|
cout << "Error occurred, path not found" << endl;
|
||||||
distance = UINT_MAX;
|
distance = UINT_MAX;
|
||||||
|
@ -247,6 +247,7 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
weight = 0;
|
weight = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
weight = length*weight/3.6;
|
weight = length*weight/3.6;
|
||||||
@ -348,7 +349,7 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename EdgeT>
|
template<typename EdgeT>
|
||||||
unsigned readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
unsigned readHSGRFromStream(istream &in, vector<EdgeT> & edgeList) {
|
||||||
unsigned numberOfNodes = 0;
|
unsigned numberOfNodes = 0;
|
||||||
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX);
|
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX);
|
||||||
while(!in.eof()) {
|
while(!in.eof()) {
|
||||||
@ -384,7 +385,7 @@ unsigned readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
|||||||
if(middle > numberOfNodes)
|
if(middle > numberOfNodes)
|
||||||
numberOfNodes = middle;
|
numberOfNodes = middle;
|
||||||
|
|
||||||
edgeList->push_back(g);
|
edgeList.push_back(g);
|
||||||
}
|
}
|
||||||
return numberOfNodes+1;
|
return numberOfNodes+1;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
|
||||||
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
||||||
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
||||||
typedef BaseConfiguration ContractorConfiguration;
|
typedef BaseConfiguration ContractorConfiguration;
|
||||||
@ -195,4 +194,5 @@ int main (int argc, char *argv[]) {
|
|||||||
delete int2ExtNodeMap;
|
delete int2ExtNodeMap;
|
||||||
|
|
||||||
cout << "finished" << endl;
|
cout << "finished" << endl;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,9 @@ typedef NodeCoords<NodeID> NodeInfo;
|
|||||||
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
||||||
#include "DataStructures/DynamicGraph.h"
|
#include "DataStructures/DynamicGraph.h"
|
||||||
|
|
||||||
|
//Fix to make Eclipse 3.7 happy
|
||||||
|
#ifndef __TIMESTAMP__
|
||||||
|
#define __TIMESTAMP__ "unknown date"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* TYPEDEFS_H_ */
|
#endif /* TYPEDEFS_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user