Removed Dead code
This commit is contained in:
parent
75ba542c38
commit
d2c532e4d5
@ -36,287 +36,279 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
class ContractionCleanup {
|
class ContractionCleanup {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct _HeapData {
|
struct _HeapData {
|
||||||
NodeID parent;
|
NodeID parent;
|
||||||
_HeapData( NodeID p ) {
|
_HeapData( NodeID p ) {
|
||||||
parent = p;
|
parent = p;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#ifdef _MANYCORES
|
#ifdef _MANYCORES
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
|
||||||
#else
|
#else
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
|
||||||
#endif
|
#endif
|
||||||
struct _ThreadData {
|
struct _ThreadData {
|
||||||
_Heap* _heapForward;
|
_Heap* _heapForward;
|
||||||
_Heap* _heapBackward;
|
_Heap* _heapBackward;
|
||||||
_ThreadData( NodeID nodes ) {
|
_ThreadData( NodeID nodes ) {
|
||||||
_heapBackward = new _Heap(nodes);
|
_heapBackward = new _Heap(nodes);
|
||||||
_heapForward = new _Heap(nodes);
|
_heapForward = new _Heap(nodes);
|
||||||
}
|
}
|
||||||
~_ThreadData()
|
~_ThreadData()
|
||||||
{
|
{
|
||||||
delete _heapBackward;
|
delete _heapBackward;
|
||||||
delete _heapForward;
|
delete _heapForward;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
union _MiddleName {
|
union _MiddleName {
|
||||||
NodeID nameID;
|
NodeID nameID;
|
||||||
NodeID middle;
|
NodeID middle;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Edge {
|
struct Edge {
|
||||||
NodeID source;
|
NodeID source;
|
||||||
NodeID target;
|
NodeID target;
|
||||||
struct EdgeData {
|
struct EdgeData {
|
||||||
int distance : 29;
|
int distance : 29;
|
||||||
bool shortcut : 1;
|
bool shortcut : 1;
|
||||||
bool forward : 1;
|
bool forward : 1;
|
||||||
bool backward : 1;
|
bool backward : 1;
|
||||||
short type:6;
|
short type:6;
|
||||||
bool forwardTurn:1;
|
bool forwardTurn:1;
|
||||||
bool backwardTurn:1;
|
bool backwardTurn:1;
|
||||||
_MiddleName middleName;
|
_MiddleName middleName;
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
//sorts by source and other attributes
|
//sorts by source and other attributes
|
||||||
static bool CompareBySource( const Edge& left, const Edge& right ) {
|
static bool CompareBySource( const Edge& left, const Edge& right ) {
|
||||||
if ( left.source != right.source )
|
if ( left.source != right.source )
|
||||||
return left.source < right.source;
|
return left.source < right.source;
|
||||||
int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 );
|
int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 );
|
||||||
int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 );
|
int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 );
|
||||||
if ( l != r )
|
if ( l != r )
|
||||||
return l < r;
|
return l < r;
|
||||||
if ( left.target != right.target )
|
if ( left.target != right.target )
|
||||||
return left.target < right.target;
|
return left.target < right.target;
|
||||||
return left.data.distance < right.data.distance;
|
return left.data.distance < right.data.distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== ( const Edge& right ) const {
|
bool operator== ( const Edge& right ) const {
|
||||||
return ( source == right.source && target == right.target && data.distance == right.data.distance && data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward && data.middleName.middle == right.data.middleName.middle );
|
return ( source == right.source && target == right.target && data.distance == right.data.distance && data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward && data.middleName.middle == right.data.middleName.middle );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) {
|
ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) {
|
||||||
_graph = edges;
|
_graph = edges;
|
||||||
_numNodes = numNodes;
|
_numNodes = numNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ContractionCleanup() {
|
~ContractionCleanup() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Run() {
|
void Run() {
|
||||||
RemoveUselessShortcuts();
|
RemoveUselessShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EdgeT >
|
template< class EdgeT >
|
||||||
void GetData( std::vector< EdgeT >& edges ) {
|
void GetData( std::vector< EdgeT >& edges ) {
|
||||||
for ( int edge = 0, endEdges = ( int ) _graph.size(); edge != endEdges; ++edge ) {
|
for ( int edge = 0, endEdges = ( int ) _graph.size(); edge != endEdges; ++edge ) {
|
||||||
EdgeT newEdge;
|
EdgeT newEdge;
|
||||||
newEdge.source = _graph[edge].source;
|
newEdge.source = _graph[edge].source;
|
||||||
newEdge.target = _graph[edge].target;
|
newEdge.target = _graph[edge].target;
|
||||||
|
|
||||||
newEdge.data.distance = _graph[edge].data.distance;
|
newEdge.data.distance = _graph[edge].data.distance;
|
||||||
newEdge.data.shortcut = _graph[edge].data.shortcut;
|
newEdge.data.shortcut = _graph[edge].data.shortcut;
|
||||||
newEdge.data.middleName = _graph[edge].data.middleName;
|
newEdge.data.middleName = _graph[edge].data.middleName;
|
||||||
newEdge.data.forward = _graph[edge].data.forward;
|
newEdge.data.forward = _graph[edge].data.forward;
|
||||||
newEdge.data.backward = _graph[edge].data.backward;
|
newEdge.data.backward = _graph[edge].data.backward;
|
||||||
newEdge.data.type = _graph[edge].data.type;
|
newEdge.data.type = _graph[edge].data.type;
|
||||||
newEdge.data.forwardTurn = _graph[edge].data.forwardTurn;
|
newEdge.data.forwardTurn = _graph[edge].data.forwardTurn;
|
||||||
newEdge.data.backwardTurn = _graph[edge].data.backwardTurn;
|
newEdge.data.backwardTurn = _graph[edge].data.backwardTurn;
|
||||||
edges.push_back( newEdge );
|
edges.push_back( newEdge );
|
||||||
}
|
}
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
#ifdef _GLIBCXX_PARALLEL
|
||||||
__gnu_parallel::sort( edges.begin(), edges.end() );
|
__gnu_parallel::sort( edges.begin(), edges.end() );
|
||||||
#else
|
#else
|
||||||
sort( edges.begin(), edges.end() );
|
sort( edges.begin(), edges.end() );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
class AllowForwardEdge {
|
class AllowForwardEdge {
|
||||||
public:
|
public:
|
||||||
bool operator()( const Edge& data ) const {
|
bool operator()( const Edge& data ) const {
|
||||||
return data.data.forward;
|
return data.data.forward;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class AllowBackwardEdge {
|
class AllowBackwardEdge {
|
||||||
public:
|
public:
|
||||||
bool operator()( const Edge& data ) const {
|
bool operator()( const Edge& data ) const {
|
||||||
return data.data.backward;
|
return data.data.backward;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
double _Timestamp() {
|
double _Timestamp() {
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
gettimeofday(&tp, NULL);
|
gettimeofday(&tp, NULL);
|
||||||
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
|
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildOutgoingGraph() {
|
void BuildOutgoingGraph() {
|
||||||
//sort edges by source
|
//sort edges by source
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
#ifdef _GLIBCXX_PARALLEL
|
||||||
__gnu_parallel::sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
__gnu_parallel::sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
||||||
#else
|
#else
|
||||||
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
||||||
#endif
|
#endif
|
||||||
try {
|
try {
|
||||||
_firstEdge.resize( _numNodes + 1 );
|
_firstEdge.resize( _numNodes + 1 );
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
cerr << "Not enough RAM on machine" << endl;
|
cerr << "Not enough RAM on machine" << endl;
|
||||||
}
|
}
|
||||||
_firstEdge[0] = 0;
|
_firstEdge[0] = 0;
|
||||||
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
|
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
|
||||||
while ( _graph[i].source != node )
|
while ( _graph[i].source != node )
|
||||||
_firstEdge[++node] = i;
|
_firstEdge[++node] = i;
|
||||||
if ( i == ( NodeID ) _graph.size() - 1 )
|
if ( i == ( NodeID ) _graph.size() - 1 )
|
||||||
while ( node < _numNodes )
|
while ( node < _numNodes )
|
||||||
_firstEdge[++node] = ( int ) _graph.size();
|
_firstEdge[++node] = ( int ) _graph.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveUselessShortcuts() {
|
void RemoveUselessShortcuts() {
|
||||||
int maxThreads = omp_get_max_threads();
|
int maxThreads = omp_get_max_threads();
|
||||||
std::vector < _ThreadData* > threadData;
|
std::vector < _ThreadData* > threadData;
|
||||||
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
threadData.push_back( new _ThreadData( _numNodes ) );
|
threadData.push_back( new _ThreadData( _numNodes ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Scanning for useless shortcuts" << endl;
|
cout << "Scanning for useless shortcuts" << endl;
|
||||||
BuildOutgoingGraph();
|
BuildOutgoingGraph();
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
for ( unsigned i = 0; i < ( unsigned ) _graph.size(); i++ ) {
|
for ( unsigned i = 0; i < ( unsigned ) _graph.size(); i++ ) {
|
||||||
for ( unsigned edge = _firstEdge[_graph[i].source]; edge < _firstEdge[_graph[i].source + 1]; ++edge ) {
|
for ( unsigned edge = _firstEdge[_graph[i].source]; edge < _firstEdge[_graph[i].source + 1]; ++edge ) {
|
||||||
if ( edge == i )
|
if ( edge == i )
|
||||||
continue;
|
continue;
|
||||||
if ( _graph[edge].target != _graph[i].target )
|
if ( _graph[edge].target != _graph[i].target )
|
||||||
continue;
|
continue;
|
||||||
if ( _graph[edge].data.distance < _graph[i].data.distance )
|
if ( _graph[edge].data.distance < _graph[i].data.distance )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_graph[edge].data.forward &= !_graph[i].data.forward;
|
_graph[edge].data.forward &= !_graph[i].data.forward;
|
||||||
_graph[edge].data.backward &= !_graph[i].data.backward;
|
_graph[edge].data.backward &= !_graph[i].data.backward;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !_graph[i].data.forward && !_graph[i].data.backward )
|
if ( !_graph[i].data.forward && !_graph[i].data.backward )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//only remove shortcuts
|
//only remove shortcuts
|
||||||
if ( !_graph[i].data.shortcut )
|
if ( !_graph[i].data.shortcut )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( _graph[i].data.forward ) {
|
if ( _graph[i].data.forward ) {
|
||||||
int result = _ComputeDistance( _graph[i].source, _graph[i].target, threadData[omp_get_thread_num()] );
|
int result = _ComputeDistance( _graph[i].source, _graph[i].target, threadData[omp_get_thread_num()] );
|
||||||
if ( result < _graph[i].data.distance ) {
|
if ( result < _graph[i].data.distance ) {
|
||||||
_graph[i].data.forward = false;
|
_graph[i].data.forward = false;
|
||||||
Contractor::Witness temp;
|
}
|
||||||
temp.source = _graph[i].source;
|
}
|
||||||
temp.target = _graph[i].target;
|
if ( _graph[i].data.backward ) {
|
||||||
temp.middleName.middle = _graph[i].data.middleName.middle;
|
int result = _ComputeDistance( _graph[i].target, _graph[i].source, threadData[omp_get_thread_num()] );
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( _graph[i].data.backward ) {
|
|
||||||
int result = _ComputeDistance( _graph[i].target, _graph[i].source, threadData[omp_get_thread_num()] );
|
|
||||||
|
|
||||||
if ( result < _graph[i].data.distance ) {
|
if ( result < _graph[i].data.distance ) {
|
||||||
_graph[i].data.backward = false;
|
_graph[i].data.backward = false;
|
||||||
Contractor::Witness temp;
|
}
|
||||||
temp.source = _graph[i].target;
|
}
|
||||||
temp.target = _graph[i].source;
|
}
|
||||||
temp.middleName.middle = _graph[i].data.middleName.middle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Removing edges" << endl;
|
cout << "Removing edges" << endl;
|
||||||
int usefull = 0;
|
int usefull = 0;
|
||||||
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
||||||
if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut )
|
if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut )
|
||||||
continue;
|
continue;
|
||||||
_graph[usefull] = _graph[i];
|
_graph[usefull] = _graph[i];
|
||||||
usefull++;
|
usefull++;
|
||||||
}
|
}
|
||||||
cout << "Removed " << _graph.size() - usefull << " useless shortcuts" << endl;
|
cout << "Removed " << _graph.size() - usefull << " useless shortcuts" << endl;
|
||||||
_graph.resize( usefull );
|
_graph.resize( usefull );
|
||||||
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
delete threadData[threadNum];
|
delete threadData[threadNum];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EdgeAllowed, class StallEdgeAllowed > void _ComputeStep( _Heap* heapForward, _Heap* heapBackward, const EdgeAllowed& edgeAllowed, const StallEdgeAllowed& stallEdgeAllowed, NodeID* middle, int* targetDistance ) {
|
template< class EdgeAllowed, class StallEdgeAllowed > void _ComputeStep( _Heap* heapForward, _Heap* heapBackward, const EdgeAllowed& edgeAllowed, const StallEdgeAllowed& stallEdgeAllowed, NodeID* middle, int* targetDistance ) {
|
||||||
|
|
||||||
const NodeID node = heapForward->DeleteMin();
|
const NodeID node = heapForward->DeleteMin();
|
||||||
const int distance = heapForward->GetKey( node );
|
const int distance = heapForward->GetKey( node );
|
||||||
|
|
||||||
if ( heapBackward->WasInserted( node ) ) {
|
if ( heapBackward->WasInserted( node ) ) {
|
||||||
const int newDistance = heapBackward->GetKey( node ) + distance;
|
const int newDistance = heapBackward->GetKey( node ) + distance;
|
||||||
if ( newDistance < *targetDistance ) {
|
if ( newDistance < *targetDistance ) {
|
||||||
*middle = node;
|
*middle = node;
|
||||||
*targetDistance = newDistance;
|
*targetDistance = newDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( distance > *targetDistance ) {
|
if ( distance > *targetDistance ) {
|
||||||
heapForward->DeleteAll();
|
heapForward->DeleteAll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) {
|
for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) {
|
||||||
const NodeID to = _graph[edge].target;
|
const NodeID to = _graph[edge].target;
|
||||||
const int edgeWeight = _graph[edge].data.distance;
|
const int edgeWeight = _graph[edge].data.distance;
|
||||||
assert( edgeWeight > 0 );
|
assert( edgeWeight > 0 );
|
||||||
const int toDistance = distance + edgeWeight;
|
const int toDistance = distance + edgeWeight;
|
||||||
|
|
||||||
if ( edgeAllowed( _graph[edge] ) ) {
|
if ( edgeAllowed( _graph[edge] ) ) {
|
||||||
//New Node discovered -> Add to Heap + Node Info Storage
|
//New Node discovered -> Add to Heap + Node Info Storage
|
||||||
if ( !heapForward->WasInserted( to ) )
|
if ( !heapForward->WasInserted( to ) )
|
||||||
heapForward->Insert( to, toDistance, node );
|
heapForward->Insert( to, toDistance, node );
|
||||||
|
|
||||||
//Found a shorter Path -> Update distance
|
//Found a shorter Path -> Update distance
|
||||||
else if ( toDistance < heapForward->GetKey( to ) ) {
|
else if ( toDistance < heapForward->GetKey( to ) ) {
|
||||||
heapForward->DecreaseKey( to, toDistance );
|
heapForward->DecreaseKey( to, toDistance );
|
||||||
//new parent
|
//new parent
|
||||||
heapForward->GetData( to ) = node;
|
heapForward->GetData( to ) = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vector< NodeID >* path = NULL ) {
|
int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vector< NodeID >* path = NULL ) {
|
||||||
data->_heapForward->Clear();
|
data->_heapForward->Clear();
|
||||||
data->_heapBackward->Clear();
|
data->_heapBackward->Clear();
|
||||||
//insert source into heap
|
//insert source into heap
|
||||||
data->_heapForward->Insert( source, 0, source );
|
data->_heapForward->Insert( source, 0, source );
|
||||||
data->_heapBackward->Insert( target, 0, target );
|
data->_heapBackward->Insert( target, 0, target );
|
||||||
|
|
||||||
int targetDistance = std::numeric_limits< int >::max();
|
int targetDistance = std::numeric_limits< int >::max();
|
||||||
NodeID middle = 0;
|
NodeID middle = 0;
|
||||||
AllowForwardEdge forward;
|
AllowForwardEdge forward;
|
||||||
AllowBackwardEdge backward;
|
AllowBackwardEdge backward;
|
||||||
|
|
||||||
while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) {
|
while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) {
|
||||||
|
|
||||||
if ( data->_heapForward->Size() > 0 ) {
|
if ( data->_heapForward->Size() > 0 ) {
|
||||||
_ComputeStep( data->_heapForward, data->_heapBackward, forward, backward, &middle, &targetDistance );
|
_ComputeStep( data->_heapForward, data->_heapBackward, forward, backward, &middle, &targetDistance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( data->_heapBackward->Size() > 0 ) {
|
if ( data->_heapBackward->Size() > 0 ) {
|
||||||
_ComputeStep( data->_heapBackward, data->_heapForward, backward, forward, &middle, &targetDistance );
|
_ComputeStep( data->_heapBackward, data->_heapForward, backward, forward, &middle, &targetDistance );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( targetDistance == std::numeric_limits< int >::max() )
|
if ( targetDistance == std::numeric_limits< int >::max() )
|
||||||
return std::numeric_limits< unsigned >::max();
|
return std::numeric_limits< unsigned >::max();
|
||||||
|
|
||||||
return targetDistance;
|
return targetDistance;
|
||||||
}
|
}
|
||||||
NodeID _numNodes;
|
NodeID _numNodes;
|
||||||
std::vector< Edge > _graph;
|
std::vector< Edge > _graph;
|
||||||
std::vector< unsigned > _firstEdge;
|
std::vector< unsigned > _firstEdge;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTRACTIONCLEANUP_H_INCLUDED
|
#endif // CONTRACTIONCLEANUP_H_INCLUDED
|
||||||
|
@ -44,15 +44,6 @@ private:
|
|||||||
NodeID nameID;
|
NodeID nameID;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
struct Witness {
|
|
||||||
NodeID source;
|
|
||||||
NodeID target;
|
|
||||||
_MiddleName middleName;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct _EdgeData {
|
struct _EdgeData {
|
||||||
unsigned distance;
|
unsigned distance;
|
||||||
unsigned originalEdges : 29;
|
unsigned originalEdges : 29;
|
||||||
@ -78,7 +69,6 @@ private:
|
|||||||
struct _ThreadData {
|
struct _ThreadData {
|
||||||
_Heap heap;
|
_Heap heap;
|
||||||
std::vector< _ImportEdge > insertedEdges;
|
std::vector< _ImportEdge > insertedEdges;
|
||||||
std::vector< Witness > witnessList;
|
|
||||||
_ThreadData( NodeID nodes ): heap( nodes ) {
|
_ThreadData( NodeID nodes ): heap( nodes ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
|
||||||
any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CREATEGRAPH_H
|
|
||||||
#define GRAPHLOADER_H
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cmath>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <google/dense_hash_map>
|
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
#include <parallel/algorithm>
|
|
||||||
#else
|
|
||||||
#include <algorithm>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../DataStructures/ImportEdge.h"
|
|
||||||
#include "../typedefs.h"
|
|
||||||
|
|
||||||
typedef google::dense_hash_map<NodeID, NodeID> ExternalNodeMap;
|
|
||||||
|
|
||||||
template<typename EdgeT>
|
|
||||||
NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
|
|
||||||
NodeID n, source, target, id;
|
|
||||||
EdgeID m;
|
|
||||||
short locatable;
|
|
||||||
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
|
|
||||||
ExternalNodeMap ext2IntNodeMap;
|
|
||||||
ext2IntNodeMap.set_empty_key(UINT_MAX);
|
|
||||||
in >> n;
|
|
||||||
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;)
|
|
||||||
for (NodeID i=0; i<n;i++) {
|
|
||||||
in >> id >> ycoord >> xcoord;
|
|
||||||
int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id));
|
|
||||||
ext2IntNodeMap.insert(make_pair(id, i));
|
|
||||||
}
|
|
||||||
in >> m;
|
|
||||||
VERBOSE(cout << " and " << m << " edges ..." << flush;)
|
|
||||||
|
|
||||||
edgeList.reserve(m);
|
|
||||||
for (EdgeID i=0; i<m; i++) {
|
|
||||||
EdgeWeight weight;
|
|
||||||
short type;
|
|
||||||
NodeID nameID;
|
|
||||||
int length;
|
|
||||||
in >> source >> target >> length >> dir >> weight >> type >> nameID;
|
|
||||||
assert(length > 0);
|
|
||||||
assert(weight > 0);
|
|
||||||
assert(0<=dir && dir<=2);
|
|
||||||
|
|
||||||
bool forward = true;
|
|
||||||
bool backward = true;
|
|
||||||
if (dir == 1) backward = false;
|
|
||||||
if (dir == 2) forward = false;
|
|
||||||
|
|
||||||
if(length == 0)
|
|
||||||
{ cerr << "loaded null length edge" << endl; exit(1); }
|
|
||||||
|
|
||||||
// translate the external NodeIDs to internal IDs
|
|
||||||
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
|
||||||
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
|
|
||||||
{
|
|
||||||
cerr << "after " << edgeList.size() << " edges" << endl;
|
|
||||||
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
|
|
||||||
cerr << "unresolved source NodeID: " << source << endl; exit(0);
|
|
||||||
}
|
|
||||||
source = intNodeID->second;
|
|
||||||
intNodeID = ext2IntNodeMap.find(target);
|
|
||||||
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); }
|
|
||||||
target = intNodeID->second;
|
|
||||||
|
|
||||||
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
|
|
||||||
|
|
||||||
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type );
|
|
||||||
edgeList.push_back(inputEdge);
|
|
||||||
}
|
|
||||||
ext2IntNodeMap.clear();
|
|
||||||
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
|
|
||||||
cout << "ok" << endl;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename EdgeT>
|
|
||||||
void readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
|
||||||
while(!in.eof())
|
|
||||||
{
|
|
||||||
EdgeT g;
|
|
||||||
EdgeData e;
|
|
||||||
|
|
||||||
int distance;
|
|
||||||
bool shortcut;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
bool forwardTurn;
|
|
||||||
bool backwardTurn;
|
|
||||||
short type;
|
|
||||||
NodeID middle;
|
|
||||||
NodeID source;
|
|
||||||
NodeID target;
|
|
||||||
|
|
||||||
in.read((char *)&(distance), sizeof(int));
|
|
||||||
assert(distance > 0);
|
|
||||||
in.read((char *)&(forwardTurn), sizeof(bool));
|
|
||||||
in.read((char *)&(backwardTurn), sizeof(bool));
|
|
||||||
in.read((char *)&(shortcut), sizeof(bool));
|
|
||||||
in.read((char *)&(forward), sizeof(bool));
|
|
||||||
in.read((char *)&(backward), sizeof(bool));
|
|
||||||
in.read((char *)&(middle), sizeof(NodeID));
|
|
||||||
in.read((char *)&(type), sizeof(short));
|
|
||||||
in.read((char *)&(source), sizeof(NodeID));
|
|
||||||
in.read((char *)&(target), sizeof(NodeID));
|
|
||||||
e.backward = backward; e.distance = distance; e.forward = forward; e.middleName.middle = middle; e.shortcut = shortcut; e.type = type;
|
|
||||||
e.forwardTurn = forwardTurn; e.backwardTurn = backwardTurn;
|
|
||||||
g.data = e; g.source = source; g.target = target;
|
|
||||||
|
|
||||||
edgeList->push_back(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif // CREATEGRAPH_H
|
|
Loading…
Reference in New Issue
Block a user