introducing tuning parameters
This commit is contained in:
parent
7562795b4b
commit
e695e269b1
@ -101,7 +101,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
template< class InputEdge >
|
template< class InputEdge >
|
||||||
Contractor( int nodes, std::vector< InputEdge >& inputEdges ) {
|
Contractor( int nodes, std::vector< InputEdge >& inputEdges, unsigned eqf = 2, unsigned oqf = 1, unsigned df = 1) : edgeQuotionFactor(eqf), originalQuotientFactor(oqf), depthFactor(df), maxDepth(0) {
|
||||||
|
|
||||||
std::vector< _ImportEdge > edges;
|
std::vector< _ImportEdge > edges;
|
||||||
edges.reserve( 2 * inputEdges.size() );
|
edges.reserve( 2 * inputEdges.size() );
|
||||||
for ( typename std::vector< InputEdge >::const_iterator i = inputEdges.begin(), e = inputEdges.end(); i != e; ++i ) {
|
for ( typename std::vector< InputEdge >::const_iterator i = inputEdges.begin(), e = inputEdges.end(); i != e; ++i ) {
|
||||||
@ -111,14 +112,12 @@ public:
|
|||||||
|
|
||||||
edge.data.distance = std::max((int)i->weight(), 1 );
|
edge.data.distance = std::max((int)i->weight(), 1 );
|
||||||
assert( edge.data.distance > 0 );
|
assert( edge.data.distance > 0 );
|
||||||
|
#ifdef DEBUG
|
||||||
if ( edge.data.distance > 24 * 60 * 60 * 10 ) {
|
if ( edge.data.distance > 24 * 60 * 60 * 10 ) {
|
||||||
cout << "Edge Weight too large -> May lead to invalid CH" << endl;
|
cout << "Edge Weight too large -> May lead to invalid CH" << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( edge.data.distance <= 0 ) {
|
#endif
|
||||||
cout << "Edge Weight too small -> May lead to invalid CH or Crashes"<< endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
edge.data.shortcut = false;
|
edge.data.shortcut = false;
|
||||||
edge.data.middleName.nameID = i->name();
|
edge.data.middleName.nameID = i->name();
|
||||||
edge.data.type = i->type();
|
edge.data.type = i->type();
|
||||||
@ -197,6 +196,8 @@ public:
|
|||||||
delete _levelInformation;
|
delete _levelInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetNumberOfLevels() const { return maxDepth; }
|
||||||
|
|
||||||
template< class InputEdge >
|
template< class InputEdge >
|
||||||
void CheckForAllOrigEdges(std::vector< InputEdge >& inputEdges) {
|
void CheckForAllOrigEdges(std::vector< InputEdge >& inputEdges) {
|
||||||
for(unsigned int i = 0; i < inputEdges.size(); i++) {
|
for(unsigned int i = 0; i < inputEdges.size(); i++) {
|
||||||
@ -248,15 +249,12 @@ public:
|
|||||||
nodePriority[x] = _Evaluate( data, &nodeData[x], x );
|
nodePriority[x] = _Evaluate( data, &nodeData[x], x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << "ok" << endl;
|
cout << "ok" << endl << "preprocessing ..." << flush;
|
||||||
|
|
||||||
cout << "preprocessing ..." << flush;
|
|
||||||
|
|
||||||
while ( levelID < numberOfNodes ) {
|
while ( levelID < numberOfNodes ) {
|
||||||
const int last = ( int ) remainingNodes.size();
|
const int last = ( int ) remainingNodes.size();
|
||||||
|
|
||||||
//determine independent node set
|
//determine independent node set
|
||||||
double timeLast = _Timestamp();
|
|
||||||
#pragma omp parallel for schedule ( guided )
|
#pragma omp parallel for schedule ( guided )
|
||||||
for ( int i = 0; i < last; ++i ) {
|
for ( int i = 0; i < last; ++i ) {
|
||||||
const NodeID node = remainingNodes[i].first;
|
const NodeID node = remainingNodes[i].first;
|
||||||
@ -265,7 +263,6 @@ public:
|
|||||||
_NodePartitionor functor;
|
_NodePartitionor functor;
|
||||||
const std::vector < std::pair < NodeID, bool > >::const_iterator first = stable_partition( remainingNodes.begin(), remainingNodes.end(), functor );
|
const std::vector < std::pair < NodeID, bool > >::const_iterator first = stable_partition( remainingNodes.begin(), remainingNodes.end(), functor );
|
||||||
const int firstIndependent = first - remainingNodes.begin();
|
const int firstIndependent = first - remainingNodes.begin();
|
||||||
timeLast = _Timestamp();
|
|
||||||
|
|
||||||
//contract independent nodes
|
//contract independent nodes
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@ -336,9 +333,9 @@ public:
|
|||||||
p.printStatus(levelID);
|
p.printStatus(levelID);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( _DynamicGraph::NodeIterator n = 0; n < _graph->GetNumberOfNodes(); n++ ) {
|
for ( _DynamicGraph::NodeIterator n = 0; n < _graph->GetNumberOfNodes(); n++ ) {
|
||||||
_levelInformation->Add(nodeData[n].depth, n);
|
_levelInformation->Add(nodeData[n].depth, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) {
|
for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) {
|
||||||
delete threadData[threadNum];
|
delete threadData[threadNum];
|
||||||
@ -347,6 +344,7 @@ public:
|
|||||||
cout << "[contractor] checking sanity of generated data ..." << flush;
|
cout << "[contractor] checking sanity of generated data ..." << flush;
|
||||||
_CheckCH<_EdgeData>();
|
_CheckCH<_EdgeData>();
|
||||||
cout << "ok" << endl;
|
cout << "ok" << endl;
|
||||||
|
std::cout << "[contractor] max level: " << maxDepth << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Edge >
|
template< class Edge >
|
||||||
@ -380,14 +378,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LevelInformation * GetLevelInformation() {
|
LevelInformation * GetLevelInformation() {
|
||||||
return _levelInformation;
|
return _levelInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double _Timestamp() {
|
|
||||||
return time(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _ConstructCH( _DynamicGraph* _graph );
|
bool _ConstructCH( _DynamicGraph* _graph );
|
||||||
|
|
||||||
void _Dijkstra( NodeID source, const int maxDistance, const unsigned numTargets, _ThreadData* data ){
|
void _Dijkstra( NodeID source, const int maxDistance, const unsigned numTargets, _ThreadData* data ){
|
||||||
@ -408,9 +402,9 @@ private:
|
|||||||
if ( distance > maxDistance )
|
if ( distance > maxDistance )
|
||||||
return;
|
return;
|
||||||
if( heap.GetData( node ).target ) {
|
if( heap.GetData( node ).target ) {
|
||||||
targetsFound++;
|
targetsFound++;
|
||||||
if ( targetsFound >= numTargets )
|
if ( targetsFound >= numTargets )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//iterate over all edges of node
|
//iterate over all edges of node
|
||||||
@ -439,11 +433,14 @@ private:
|
|||||||
|
|
||||||
//perform simulated contraction
|
//perform simulated contraction
|
||||||
_Contract< true > ( data, node, &stats );
|
_Contract< true > ( data, node, &stats );
|
||||||
|
if(nodeData->depth > maxDepth) {
|
||||||
|
#pragma omp critical
|
||||||
|
maxDepth = nodeData->depth;
|
||||||
|
}
|
||||||
// Result will contain the priority
|
// Result will contain the priority
|
||||||
if ( stats.edgesDeleted == 0 || stats.originalEdgesDeleted == 0 )
|
if ( stats.edgesDeleted == 0 || stats.originalEdgesDeleted == 0 )
|
||||||
return 1 * nodeData->depth;
|
return depthFactor * nodeData->depth;
|
||||||
return 2 * ((( double ) stats.edgesAdded ) / stats.edgesDeleted ) + 1 * ((( double ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + 1 * nodeData->depth;
|
return edgeQuotionFactor * ((( double ) stats.edgesAdded ) / stats.edgesDeleted ) + originalQuotientFactor * ((( double ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + depthFactor * nodeData->depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Edge >
|
template< class Edge >
|
||||||
@ -483,8 +480,9 @@ private:
|
|||||||
const NodeID source = _graph->GetTarget( inEdge );
|
const NodeID source = _graph->GetTarget( inEdge );
|
||||||
if ( Simulate ) {
|
if ( Simulate ) {
|
||||||
assert( stats != NULL );
|
assert( stats != NULL );
|
||||||
stats->edgesDeleted++;
|
unsigned factor = (inData.forward && inData.backward ? 2 : 1 );
|
||||||
stats->originalEdgesDeleted += inData.originalEdges;
|
stats->edgesDeleted+=factor;
|
||||||
|
stats->originalEdgesDeleted += factor*inData.originalEdges;
|
||||||
}
|
}
|
||||||
if ( !inData.backward )
|
if ( !inData.backward )
|
||||||
continue;
|
continue;
|
||||||
@ -510,9 +508,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( Simulate )
|
if( Simulate )
|
||||||
_Dijkstra( source, maxDistance, 500, data );
|
_Dijkstra( source, maxDistance, 500, data );
|
||||||
else
|
else
|
||||||
_Dijkstra( source, maxDistance, 1000, data );
|
_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 );
|
||||||
@ -525,8 +523,8 @@ private:
|
|||||||
if ( pathDistance <= distance ) {
|
if ( pathDistance <= distance ) {
|
||||||
if ( Simulate ) {
|
if ( Simulate ) {
|
||||||
assert( stats != NULL );
|
assert( stats != NULL );
|
||||||
stats->edgesAdded += 2;
|
stats->edgesAdded++;
|
||||||
stats->originalEdgesAdded += 2 * ( outData.originalEdges + inData.originalEdges );
|
stats->originalEdgesAdded += ( outData.originalEdges + inData.originalEdges );
|
||||||
} else {
|
} else {
|
||||||
_ImportEdge newEdge;
|
_ImportEdge newEdge;
|
||||||
newEdge.source = source;
|
newEdge.source = source;
|
||||||
@ -565,12 +563,6 @@ private:
|
|||||||
|
|
||||||
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
|
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
|
||||||
const NodeID u = neighbours[i];
|
const NodeID u = neighbours[i];
|
||||||
//_DynamicGraph::EdgeIterator edge = _graph->FindEdge( u, node );
|
|
||||||
//assert( edge != _graph->EndEdges( u ) );
|
|
||||||
//while ( edge != _graph->EndEdges( u ) ) {
|
|
||||||
// _graph->DeleteEdge( u, edge );
|
|
||||||
// edge = _graph->FindEdge( u, node );
|
|
||||||
//}
|
|
||||||
_graph->DeleteEdgesTo( u, node );
|
_graph->DeleteEdgesTo( u, node );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,7 +637,10 @@ private:
|
|||||||
LevelInformation * _levelInformation;
|
LevelInformation * _levelInformation;
|
||||||
_DynamicGraph* _graph;
|
_DynamicGraph* _graph;
|
||||||
std::vector<NodeID> * _components;
|
std::vector<NodeID> * _components;
|
||||||
|
unsigned edgeQuotionFactor;
|
||||||
|
unsigned originalQuotientFactor;
|
||||||
|
unsigned depthFactor;
|
||||||
|
int maxDepth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTRACTOR_H_INCLUDED
|
#endif // CONTRACTOR_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user