Writing level information into seperate file
This commit is contained in:
parent
229812cd95
commit
be34eebda7
@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#endif
|
#endif
|
||||||
#include "../DataStructures/DynamicGraph.h"
|
#include "../DataStructures/DynamicGraph.h"
|
||||||
|
#include "../DataStructures/LevelInformation.h"
|
||||||
#include "../DataStructures/Percent.h"
|
#include "../DataStructures/Percent.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -97,75 +98,6 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LogItem {
|
|
||||||
unsigned iteration;
|
|
||||||
NodeID nodes;
|
|
||||||
double contraction;
|
|
||||||
double independent;
|
|
||||||
double inserting;
|
|
||||||
double removing;
|
|
||||||
double updating;
|
|
||||||
|
|
||||||
_LogItem() {
|
|
||||||
iteration = nodes = contraction = independent = inserting = removing = updating = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetTotalTime() const {
|
|
||||||
return contraction + independent + inserting + removing + updating;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintStatistics( int interation ) const {
|
|
||||||
cout << iteration << "\t" << nodes << "\t" << independent << "\t" << contraction << "\t" << inserting << "\t" << removing << "\t" << updating << endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class _LogData {
|
|
||||||
public:
|
|
||||||
|
|
||||||
std::vector < _LogItem > iterations;
|
|
||||||
|
|
||||||
unsigned GetNIterations() {
|
|
||||||
return ( unsigned ) iterations.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
_LogItem GetSum() const {
|
|
||||||
_LogItem sum;
|
|
||||||
sum.iteration = ( unsigned ) iterations.size();
|
|
||||||
|
|
||||||
for ( int i = 0, e = ( int ) iterations.size(); i < e; ++i ) {
|
|
||||||
sum.nodes += iterations[i].nodes;
|
|
||||||
sum.contraction += iterations[i].contraction;
|
|
||||||
sum.independent += iterations[i].independent;
|
|
||||||
sum.inserting += iterations[i].inserting;
|
|
||||||
sum.removing += iterations[i].removing;
|
|
||||||
sum.updating += iterations[i].updating;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintHeader() const {
|
|
||||||
cout << "Iteration\tNodes\tIndependent\tContraction\tInserting\tRemoving\tUpdating" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintSummary() const {
|
|
||||||
PrintHeader();
|
|
||||||
GetSum().PrintStatistics(( int ) iterations.size() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Print() const {
|
|
||||||
PrintHeader();
|
|
||||||
for ( int i = 0, e = ( int ) iterations.size(); i < e; ++i ) {
|
|
||||||
iterations[i].PrintStatistics( i );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Insert( const _LogItem& data ) {
|
|
||||||
iterations.push_back( data );
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template< class InputEdge >
|
template< class InputEdge >
|
||||||
@ -256,12 +188,13 @@ public:
|
|||||||
cout << "ok" << endl << "removed " << edges.size() - edge << " edges of " << edges.size() << endl;
|
cout << "ok" << endl << "removed " << edges.size() - edge << " edges of " << edges.size() << endl;
|
||||||
edges.resize( edge );
|
edges.resize( edge );
|
||||||
_graph = new _DynamicGraph( nodes, edges );
|
_graph = new _DynamicGraph( nodes, edges );
|
||||||
|
|
||||||
std::vector< _ImportEdge >().swap( edges );
|
std::vector< _ImportEdge >().swap( edges );
|
||||||
|
_levelInformation = new LevelInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Contractor() {
|
~Contractor() {
|
||||||
delete _graph;
|
delete _graph;
|
||||||
|
delete _levelInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class InputEdge >
|
template< class InputEdge >
|
||||||
@ -284,7 +217,6 @@ public:
|
|||||||
|
|
||||||
void Run() {
|
void Run() {
|
||||||
const NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
const NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
||||||
_LogData log;
|
|
||||||
Percent p (numberOfNodes);
|
Percent p (numberOfNodes);
|
||||||
|
|
||||||
unsigned maxThreads = omp_get_max_threads();
|
unsigned maxThreads = omp_get_max_threads();
|
||||||
@ -295,7 +227,6 @@ public:
|
|||||||
cout << "Contractor is using " << maxThreads << " threads" << endl;
|
cout << "Contractor is using " << maxThreads << " threads" << endl;
|
||||||
|
|
||||||
NodeID levelID = 0;
|
NodeID levelID = 0;
|
||||||
NodeID iteration = 0;
|
|
||||||
std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes );
|
std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes );
|
||||||
std::vector< double > nodePriority( numberOfNodes );
|
std::vector< double > nodePriority( numberOfNodes );
|
||||||
std::vector< _PriorityData > nodeData( numberOfNodes );
|
std::vector< _PriorityData > nodeData( numberOfNodes );
|
||||||
@ -309,8 +240,6 @@ public:
|
|||||||
nodeData[remainingNodes[x].first].bias = x;
|
nodeData[remainingNodes[x].first].bias = x;
|
||||||
|
|
||||||
cout << "initializing elimination PQ ..." << flush;
|
cout << "initializing elimination PQ ..." << flush;
|
||||||
_LogItem statistics0;
|
|
||||||
statistics0.updating = _Timestamp();
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
_ThreadData* data = threadData[omp_get_thread_num()];
|
_ThreadData* data = threadData[omp_get_thread_num()];
|
||||||
@ -321,15 +250,9 @@ public:
|
|||||||
}
|
}
|
||||||
cout << "ok" << endl;
|
cout << "ok" << endl;
|
||||||
|
|
||||||
statistics0.updating = _Timestamp() - statistics0.updating;
|
|
||||||
log.Insert( statistics0 );
|
|
||||||
cout << "preprocessing ..." << flush;
|
cout << "preprocessing ..." << flush;
|
||||||
// log.PrintHeader();
|
|
||||||
// statistics0.PrintStatistics( 0 );
|
|
||||||
|
|
||||||
while ( levelID < numberOfNodes ) {
|
while ( levelID < numberOfNodes ) {
|
||||||
_LogItem statistics;
|
|
||||||
statistics.iteration = iteration++;
|
|
||||||
const int last = ( int ) remainingNodes.size();
|
const int last = ( int ) remainingNodes.size();
|
||||||
|
|
||||||
//determine independent node set
|
//determine independent node set
|
||||||
@ -342,8 +265,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();
|
||||||
statistics.nodes = last - firstIndependent;
|
|
||||||
statistics.independent += _Timestamp() - timeLast;
|
|
||||||
timeLast = _Timestamp();
|
timeLast = _Timestamp();
|
||||||
|
|
||||||
//contract independent nodes
|
//contract independent nodes
|
||||||
@ -358,8 +279,6 @@ public:
|
|||||||
}
|
}
|
||||||
std::sort( data->insertedEdges.begin(), data->insertedEdges.end() );
|
std::sort( data->insertedEdges.begin(), data->insertedEdges.end() );
|
||||||
}
|
}
|
||||||
statistics.contraction += _Timestamp() - timeLast;
|
|
||||||
timeLast = _Timestamp();
|
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
@ -367,11 +286,9 @@ public:
|
|||||||
#pragma omp for schedule ( guided ) nowait
|
#pragma omp for schedule ( guided ) nowait
|
||||||
for ( int position = firstIndependent ; position < last; ++position ) {
|
for ( int position = firstIndependent ; position < last; ++position ) {
|
||||||
NodeID x = remainingNodes[position].first;
|
NodeID x = remainingNodes[position].first;
|
||||||
_DeleteIncommingEdges( data, x );
|
_DeleteIncomingEdges( data, x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statistics.removing += _Timestamp() - timeLast;
|
|
||||||
timeLast = _Timestamp();
|
|
||||||
|
|
||||||
//insert new edges
|
//insert new edges
|
||||||
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
@ -400,8 +317,6 @@ public:
|
|||||||
}
|
}
|
||||||
std::vector< _ImportEdge >().swap( data.insertedEdges );
|
std::vector< _ImportEdge >().swap( data.insertedEdges );
|
||||||
}
|
}
|
||||||
statistics.inserting += _Timestamp() - timeLast;
|
|
||||||
timeLast = _Timestamp();
|
|
||||||
|
|
||||||
//update priorities
|
//update priorities
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@ -413,21 +328,18 @@ public:
|
|||||||
_UpdateNeighbours( &nodePriority, &nodeData, data, x );
|
_UpdateNeighbours( &nodePriority, &nodeData, data, x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statistics.updating += _Timestamp() - timeLast;
|
|
||||||
timeLast = _Timestamp();
|
|
||||||
|
|
||||||
//output some statistics
|
|
||||||
// statistics.PrintStatistics( iteration + 1 );
|
|
||||||
//LogVerbose( wxT( "Printed" ) );
|
|
||||||
|
|
||||||
//remove contracted nodes from the pool
|
//remove contracted nodes from the pool
|
||||||
levelID += last - firstIndependent;
|
levelID += last - firstIndependent;
|
||||||
remainingNodes.resize( firstIndependent );
|
remainingNodes.resize( firstIndependent );
|
||||||
std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes );
|
std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes );
|
||||||
log.Insert( statistics );
|
|
||||||
p.printStatus(levelID);
|
p.printStatus(levelID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( _DynamicGraph::NodeIterator n = 0; n < _graph->GetNumberOfNodes(); 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];
|
||||||
}
|
}
|
||||||
@ -467,6 +379,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LevelInformation * GetLevelInformation() {
|
||||||
|
return _levelInformation;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double _Timestamp() {
|
double _Timestamp() {
|
||||||
return time(NULL);
|
return time(NULL);
|
||||||
@ -628,19 +544,12 @@ private:
|
|||||||
data->insertedEdges.push_back( newEdge );
|
data->insertedEdges.push_back( newEdge );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*else if ( !Simulate ) {
|
|
||||||
Witness witness;
|
|
||||||
witness.source = source;
|
|
||||||
witness.target = target;
|
|
||||||
witness.middle = node;
|
|
||||||
witnessList.push_back( witness );
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _DeleteIncommingEdges( _ThreadData* data, NodeID node ) {
|
bool _DeleteIncomingEdges( _ThreadData* data, NodeID node ) {
|
||||||
std::vector < NodeID > neighbours;
|
std::vector < NodeID > neighbours;
|
||||||
|
|
||||||
//find all neighbours
|
//find all neighbours
|
||||||
@ -733,6 +642,7 @@ private:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LevelInformation * _levelInformation;
|
||||||
_DynamicGraph* _graph;
|
_DynamicGraph* _graph;
|
||||||
std::vector<NodeID> * _components;
|
std::vector<NodeID> * _components;
|
||||||
|
|
||||||
|
47
DataStructures/LevelInformation.h
Normal file
47
DataStructures/LevelInformation.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* LevelInformation.h
|
||||||
|
*
|
||||||
|
* Created on: 10.03.2011
|
||||||
|
* Author: dennis
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LEVELINFORMATION_H_
|
||||||
|
#define LEVELINFORMATION_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LevelInformation {
|
||||||
|
public:
|
||||||
|
LevelInformation() {
|
||||||
|
levelInfos = new std::vector<std::vector<unsigned> >();
|
||||||
|
}
|
||||||
|
~LevelInformation() {
|
||||||
|
delete levelInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Add(const unsigned level, const unsigned entry) {
|
||||||
|
if(levelInfos->size() <= level)
|
||||||
|
levelInfos->resize(level+1);
|
||||||
|
assert(levelInfos->size() >= level);
|
||||||
|
(*levelInfos)[level].push_back(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned GetNumberOfLevels() const {
|
||||||
|
return levelInfos->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned> & GetLevel(unsigned level) {
|
||||||
|
assert(level < levelInfos->size());
|
||||||
|
return (*levelInfos)[level];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reset() {
|
||||||
|
delete levelInfos;
|
||||||
|
levelInfos = new std::vector<std::vector<unsigned> >();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::vector<unsigned> > * levelInfos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* LEVELINFORMATION_H_ */
|
@ -265,9 +265,10 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename EdgeT>
|
template<typename EdgeT>
|
||||||
void readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
unsigned readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
||||||
while(!in.eof())
|
unsigned numberOfNodes = 0;
|
||||||
{
|
ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX);
|
||||||
|
while(!in.eof()) {
|
||||||
EdgeT g;
|
EdgeT g;
|
||||||
EdgeData e;
|
EdgeData e;
|
||||||
|
|
||||||
@ -297,8 +298,18 @@ void readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
|
|||||||
e.forwardTurn = forwardTurn; e.backwardTurn = backwardTurn;
|
e.forwardTurn = forwardTurn; e.backwardTurn = backwardTurn;
|
||||||
g.data = e; g.source = source; g.target = target;
|
g.data = e; g.source = source; g.target = target;
|
||||||
|
|
||||||
|
if(source > numberOfNodes)
|
||||||
|
numberOfNodes = source;
|
||||||
|
if(target > numberOfNodes)
|
||||||
|
numberOfNodes = target;
|
||||||
|
if(middle > numberOfNodes)
|
||||||
|
numberOfNodes = middle;
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "loaded edge (" << source << "," << target << ")" << std::endl;
|
||||||
|
|
||||||
edgeList->push_back(g);
|
edgeList->push_back(g);
|
||||||
}
|
}
|
||||||
|
return numberOfNodes+1;
|
||||||
}
|
}
|
||||||
#endif // CREATEGRAPH_H
|
#endif // CREATEGRAPH_H
|
||||||
|
@ -44,6 +44,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "Contractor/Contractor.h"
|
#include "Contractor/Contractor.h"
|
||||||
#include "Contractor/ContractionCleanup.h"
|
#include "Contractor/ContractionCleanup.h"
|
||||||
#include "DataStructures/BinaryHeap.h"
|
#include "DataStructures/BinaryHeap.h"
|
||||||
|
#include "DataStructures/LevelInformation.h"
|
||||||
#include "DataStructures/NNGrid.h"
|
#include "DataStructures/NNGrid.h"
|
||||||
#include "DataStructures/TurnInfoFactory.h"
|
#include "DataStructures/TurnInfoFactory.h"
|
||||||
#include "Util/BaseConfiguration.h"
|
#include "Util/BaseConfiguration.h"
|
||||||
@ -101,15 +102,18 @@ int main (int argc, char *argv[]) {
|
|||||||
char edgeOut[1024];
|
char edgeOut[1024];
|
||||||
char ramIndexOut[1024];
|
char ramIndexOut[1024];
|
||||||
char fileIndexOut[1024];
|
char fileIndexOut[1024];
|
||||||
|
char levelInfoOut[1024];
|
||||||
strcpy(nodeOut, argv[1]);
|
strcpy(nodeOut, argv[1]);
|
||||||
strcpy(edgeOut, argv[1]);
|
strcpy(edgeOut, argv[1]);
|
||||||
strcpy(ramIndexOut, argv[1]);
|
strcpy(ramIndexOut, argv[1]);
|
||||||
strcpy(fileIndexOut, argv[1]);
|
strcpy(fileIndexOut, argv[1]);
|
||||||
|
strcpy(levelInfoOut, argv[1]);
|
||||||
|
|
||||||
strcat(nodeOut, ".nodes");
|
strcat(nodeOut, ".nodes");
|
||||||
strcat(edgeOut, ".hsgr");
|
strcat(edgeOut, ".hsgr");
|
||||||
strcat(ramIndexOut, ".ramIndex");
|
strcat(ramIndexOut, ".ramIndex");
|
||||||
strcat(fileIndexOut, ".fileIndex");
|
strcat(fileIndexOut, ".fileIndex");
|
||||||
|
strcat(levelInfoOut, ".levels");
|
||||||
ofstream mapOutFile(nodeOut, ios::binary);
|
ofstream mapOutFile(nodeOut, ios::binary);
|
||||||
|
|
||||||
WritableGrid * g = new WritableGrid();
|
WritableGrid * g = new WritableGrid();
|
||||||
@ -139,9 +143,9 @@ int main (int argc, char *argv[]) {
|
|||||||
g->ConstructGrid(ramIndexOut, fileIndexOut);
|
g->ConstructGrid(ramIndexOut, fileIndexOut);
|
||||||
delete g;
|
delete g;
|
||||||
|
|
||||||
|
unsigned numberOfNodes = int2ExtNodeMap->size();
|
||||||
//Serializing the node map.
|
//Serializing the node map.
|
||||||
for(NodeID i = 0; i < int2ExtNodeMap->size(); i++)
|
for(NodeID i = 0; i < int2ExtNodeMap->size(); i++) {
|
||||||
{
|
|
||||||
mapOutFile.write((char *)&(int2ExtNodeMap->at(i)), sizeof(NodeInfo));
|
mapOutFile.write((char *)&(int2ExtNodeMap->at(i)), sizeof(NodeInfo));
|
||||||
}
|
}
|
||||||
mapOutFile.close();
|
mapOutFile.close();
|
||||||
@ -156,6 +160,22 @@ int main (int argc, char *argv[]) {
|
|||||||
cout << "checking data sanity ..." << flush;
|
cout << "checking data sanity ..." << flush;
|
||||||
contractor->CheckForAllOrigEdges(edgeList);
|
contractor->CheckForAllOrigEdges(edgeList);
|
||||||
cout << "ok" << endl;
|
cout << "ok" << endl;
|
||||||
|
LevelInformation * levelInfo = contractor->GetLevelInformation();
|
||||||
|
ofstream levelOutFile(levelInfoOut, ios::binary);
|
||||||
|
unsigned numberOfLevels = levelInfo->GetNumberOfLevels();
|
||||||
|
levelOutFile.write((char *)&numberOfLevels, sizeof(unsigned));
|
||||||
|
for(unsigned currentLevel = 0; currentLevel < levelInfo->GetNumberOfLevels(); currentLevel++ ) {
|
||||||
|
std::vector<unsigned> & level = levelInfo->GetLevel(currentLevel);
|
||||||
|
unsigned sizeOfLevel = level.size();
|
||||||
|
levelOutFile.write((char *)&sizeOfLevel, sizeof(unsigned));
|
||||||
|
for(unsigned currentLevelEntry = 0; currentLevelEntry < sizeOfLevel; currentLevelEntry++) {
|
||||||
|
unsigned node = level[currentLevelEntry];
|
||||||
|
assert(node < numberOfNodes);
|
||||||
|
levelOutFile.write((char *)&node, sizeof(unsigned));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
levelOutFile.close();
|
||||||
|
delete levelInfo;
|
||||||
std::vector< ContractionCleanup::Edge > contractedEdges;
|
std::vector< ContractionCleanup::Edge > contractedEdges;
|
||||||
contractor->GetEdges( contractedEdges );
|
contractor->GetEdges( contractedEdges );
|
||||||
delete contractor;
|
delete contractor;
|
||||||
|
Loading…
Reference in New Issue
Block a user