Preprocessing of routing datastructures at least 30 percent faster (Monav backport, thanks Christian)
This commit is contained in:
parent
545162cd4c
commit
03772fd85b
@ -66,13 +66,9 @@ private:
|
|||||||
} data;
|
} data;
|
||||||
|
|
||||||
struct _HeapData {
|
struct _HeapData {
|
||||||
//short hops;
|
bool target;
|
||||||
//_HeapData() {
|
_HeapData() : target(false) {}
|
||||||
// hops = 0;
|
_HeapData( bool t ) : target(t) {}
|
||||||
//}
|
|
||||||
//_HeapData( int h ) {
|
|
||||||
// hops = h;
|
|
||||||
//}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef DynamicGraph< _EdgeData > _DynamicGraph;
|
typedef DynamicGraph< _EdgeData > _DynamicGraph;
|
||||||
@ -495,11 +491,12 @@ private:
|
|||||||
|
|
||||||
bool _ConstructCH( _DynamicGraph* _graph );
|
bool _ConstructCH( _DynamicGraph* _graph );
|
||||||
|
|
||||||
void _Dijkstra( NodeID source, const int maxDistance, _ThreadData* data ){
|
void _Dijkstra( NodeID source, const int maxDistance, const unsigned numTargets, _ThreadData* data ){
|
||||||
|
|
||||||
_Heap& heap = data->heap;
|
_Heap& heap = data->heap;
|
||||||
|
|
||||||
int nodes = 0;
|
int nodes = 0;
|
||||||
|
unsigned targetsFound = 0;
|
||||||
while ( heap.Size() > 0 ) {
|
while ( heap.Size() > 0 ) {
|
||||||
const NodeID node = heap.DeleteMin();
|
const NodeID node = heap.DeleteMin();
|
||||||
const int distance = heap.GetKey( node );
|
const int distance = heap.GetKey( node );
|
||||||
@ -511,6 +508,11 @@ private:
|
|||||||
//Destination settled?
|
//Destination settled?
|
||||||
if ( distance > maxDistance )
|
if ( distance > maxDistance )
|
||||||
return;
|
return;
|
||||||
|
if( heap.GetData( node ).target ) {
|
||||||
|
targetsFound++;
|
||||||
|
if ( targetsFound >= numTargets )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//iterate over all edges of node
|
//iterate over all edges of node
|
||||||
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge != endEdges; ++edge ) {
|
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge != endEdges; ++edge ) {
|
||||||
@ -593,6 +595,7 @@ private:
|
|||||||
if ( node != source )
|
if ( node != source )
|
||||||
heap.Insert( node, inData.distance, _HeapData() );
|
heap.Insert( node, inData.distance, _HeapData() );
|
||||||
int maxDistance = 0;
|
int maxDistance = 0;
|
||||||
|
unsigned numTargets = 0;
|
||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
||||||
const _EdgeData& outData = _graph->GetEdgeData( outEdge );
|
const _EdgeData& outData = _graph->GetEdgeData( outEdge );
|
||||||
@ -602,12 +605,15 @@ private:
|
|||||||
const int pathDistance = inData.distance + outData.distance;
|
const int pathDistance = inData.distance + outData.distance;
|
||||||
maxDistance = std::max( maxDistance, pathDistance );
|
maxDistance = std::max( maxDistance, pathDistance );
|
||||||
if ( !heap.WasInserted( target ) )
|
if ( !heap.WasInserted( target ) )
|
||||||
heap.Insert( target, pathDistance, _HeapData() );
|
heap.Insert( target, pathDistance, _HeapData(true) );
|
||||||
else if ( pathDistance < heap.GetKey( target ) )
|
else if ( pathDistance < heap.GetKey( target ) )
|
||||||
heap.DecreaseKey( target, pathDistance );
|
heap.DecreaseKey( target, pathDistance );
|
||||||
}
|
}
|
||||||
|
|
||||||
_Dijkstra( source, maxDistance, data );
|
if( Simulate )
|
||||||
|
_Dijkstra( source, maxDistance, 500, data );
|
||||||
|
else
|
||||||
|
_Dijkstra( source, maxDistance, 1000, data );
|
||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
||||||
const _EdgeData& outData = _graph->GetEdgeData( outEdge );
|
const _EdgeData& outData = _graph->GetEdgeData( outEdge );
|
||||||
|
Loading…
Reference in New Issue
Block a user