minor changes

This commit is contained in:
Dennis Luxen 2011-03-15 15:20:14 +00:00
parent e695e269b1
commit 3db44b3ce1

View File

@ -43,11 +43,11 @@ private:
}
};
#ifdef _MANYCORES
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
#else
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
#endif
struct _ThreadData {
struct _ThreadData {
_Heap* _heapForward;
_Heap* _heapBackward;
_ThreadData( NodeID nodes ) {
@ -59,15 +59,15 @@ struct _ThreadData {
delete _heapBackward;
delete _heapForward;
}
};
union _MiddleName {
};
union _MiddleName {
NodeID nameID;
NodeID middle;
};
};
public:
struct Edge {
struct Edge {
NodeID source;
NodeID target;
struct EdgeData {
@ -97,23 +97,23 @@ struct Edge {
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 );
}
};
};
ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) {
ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) {
_graph = edges;
_numNodes = numNodes;
}
}
~ContractionCleanup() {
~ContractionCleanup() {
}
}
void Run() {
void Run() {
RemoveUselessShortcuts();
}
}
template< class EdgeT >
void GetData( std::vector< EdgeT >& edges ) {
template< class EdgeT >
void GetData( std::vector< EdgeT >& edges ) {
for ( int edge = 0, endEdges = ( int ) _graph.size(); edge != endEdges; ++edge ) {
EdgeT newEdge;
newEdge.source = _graph[edge].source;
@ -130,57 +130,57 @@ void GetData( std::vector< EdgeT >& edges ) {
edges.push_back( newEdge );
}
#ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort( edges.begin(), edges.end() );
__gnu_parallel::sort( edges.begin(), edges.end() );
#else
sort( edges.begin(), edges.end() );
#endif
}
}
private:
class AllowForwardEdge {
public:
class AllowForwardEdge {
public:
bool operator()( const Edge& data ) const {
return data.data.forward;
}
};
};
class AllowBackwardEdge {
public:
class AllowBackwardEdge {
public:
bool operator()( const Edge& data ) const {
return data.data.backward;
}
};
};
double _Timestamp() {
double _Timestamp() {
struct timeval tp;
gettimeofday(&tp, NULL);
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
}
}
void BuildOutgoingGraph() {
void BuildOutgoingGraph() {
//sort edges by source
#ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
__gnu_parallel::sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
#else
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
#endif
try {
try {
_firstEdge.resize( _numNodes + 1 );
} catch(...) {
} catch(...) {
cerr << "Not enough RAM on machine" << endl;
}
_firstEdge[0] = 0;
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
}
_firstEdge[0] = 0;
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
while ( _graph[i].source != node )
_firstEdge[++node] = i;
if ( i == ( NodeID ) _graph.size() - 1 )
while ( node < _numNodes )
_firstEdge[++node] = ( int ) _graph.size();
}
}
}
}
void RemoveUselessShortcuts() {
void RemoveUselessShortcuts() {
int maxThreads = omp_get_max_threads();
std::vector < _ThreadData* > threadData;
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
@ -238,9 +238,9 @@ void RemoveUselessShortcuts() {
for ( int threadNum = 0; threadNum < maxThreads; ++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 int distance = heapForward->GetKey( node );
@ -276,9 +276,9 @@ template< class EdgeAllowed, class StallEdgeAllowed > void _ComputeStep( _Heap*
}
}
}
}
}
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->_heapBackward->Clear();
//insert source into heap
@ -305,10 +305,10 @@ int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vec
return std::numeric_limits< unsigned >::max();
return targetDistance;
}
NodeID _numNodes;
std::vector< Edge > _graph;
std::vector< unsigned > _firstEdge;
}
NodeID _numNodes;
std::vector< Edge > _graph;
std::vector< unsigned > _firstEdge;
};
#endif // CONTRACTIONCLEANUP_H_INCLUDED