From be34eebda7e2f763e3dfaf36fbc4f3ad48a55d60 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 14 Mar 2011 18:01:02 +0000 Subject: [PATCH] Writing level information into seperate file --- Contractor/Contractor.h | 118 ++++-------------------------- DataStructures/LevelInformation.h | 47 ++++++++++++ Util/GraphLoader.h | 19 ++++- createHierarchy.cpp | 24 +++++- 4 files changed, 98 insertions(+), 110 deletions(-) create mode 100644 DataStructures/LevelInformation.h diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 98af582eb..f511c8c3b 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #endif #include "../DataStructures/DynamicGraph.h" +#include "../DataStructures/LevelInformation.h" #include "../DataStructures/Percent.h" #include #include @@ -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: template< class InputEdge > @@ -256,12 +188,13 @@ public: cout << "ok" << endl << "removed " << edges.size() - edge << " edges of " << edges.size() << endl; edges.resize( edge ); _graph = new _DynamicGraph( nodes, edges ); - std::vector< _ImportEdge >().swap( edges ); + _levelInformation = new LevelInformation(); } ~Contractor() { delete _graph; + delete _levelInformation; } template< class InputEdge > @@ -284,7 +217,6 @@ public: void Run() { const NodeID numberOfNodes = _graph->GetNumberOfNodes(); - _LogData log; Percent p (numberOfNodes); unsigned maxThreads = omp_get_max_threads(); @@ -295,7 +227,6 @@ public: cout << "Contractor is using " << maxThreads << " threads" << endl; NodeID levelID = 0; - NodeID iteration = 0; std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes ); std::vector< double > nodePriority( numberOfNodes ); std::vector< _PriorityData > nodeData( numberOfNodes ); @@ -309,8 +240,6 @@ public: nodeData[remainingNodes[x].first].bias = x; cout << "initializing elimination PQ ..." << flush; - _LogItem statistics0; - statistics0.updating = _Timestamp(); #pragma omp parallel { _ThreadData* data = threadData[omp_get_thread_num()]; @@ -321,15 +250,9 @@ public: } cout << "ok" << endl; - statistics0.updating = _Timestamp() - statistics0.updating; - log.Insert( statistics0 ); cout << "preprocessing ..." << flush; - // log.PrintHeader(); - // statistics0.PrintStatistics( 0 ); while ( levelID < numberOfNodes ) { - _LogItem statistics; - statistics.iteration = iteration++; const int last = ( int ) remainingNodes.size(); //determine independent node set @@ -342,8 +265,6 @@ public: _NodePartitionor functor; const std::vector < std::pair < NodeID, bool > >::const_iterator first = stable_partition( remainingNodes.begin(), remainingNodes.end(), functor ); const int firstIndependent = first - remainingNodes.begin(); - statistics.nodes = last - firstIndependent; - statistics.independent += _Timestamp() - timeLast; timeLast = _Timestamp(); //contract independent nodes @@ -358,8 +279,6 @@ public: } std::sort( data->insertedEdges.begin(), data->insertedEdges.end() ); } - statistics.contraction += _Timestamp() - timeLast; - timeLast = _Timestamp(); #pragma omp parallel { @@ -367,11 +286,9 @@ public: #pragma omp for schedule ( guided ) nowait for ( int position = firstIndependent ; position < last; ++position ) { NodeID x = remainingNodes[position].first; - _DeleteIncommingEdges( data, x ); + _DeleteIncomingEdges( data, x ); } } - statistics.removing += _Timestamp() - timeLast; - timeLast = _Timestamp(); //insert new edges for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) { @@ -400,8 +317,6 @@ public: } std::vector< _ImportEdge >().swap( data.insertedEdges ); } - statistics.inserting += _Timestamp() - timeLast; - timeLast = _Timestamp(); //update priorities #pragma omp parallel @@ -413,21 +328,18 @@ public: _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 levelID += last - firstIndependent; remainingNodes.resize( firstIndependent ); std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes ); - log.Insert( statistics ); 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++ ) { delete threadData[threadNum]; } @@ -467,6 +379,10 @@ public: } } + LevelInformation * GetLevelInformation() { + return _levelInformation; + } + private: double _Timestamp() { return time(NULL); @@ -628,19 +544,12 @@ private: 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; } - bool _DeleteIncommingEdges( _ThreadData* data, NodeID node ) { + bool _DeleteIncomingEdges( _ThreadData* data, NodeID node ) { std::vector < NodeID > neighbours; //find all neighbours @@ -733,6 +642,7 @@ private: return true; } + LevelInformation * _levelInformation; _DynamicGraph* _graph; std::vector * _components; diff --git a/DataStructures/LevelInformation.h b/DataStructures/LevelInformation.h new file mode 100644 index 000000000..8e839528c --- /dev/null +++ b/DataStructures/LevelInformation.h @@ -0,0 +1,47 @@ +/* + * LevelInformation.h + * + * Created on: 10.03.2011 + * Author: dennis + */ + +#ifndef LEVELINFORMATION_H_ +#define LEVELINFORMATION_H_ + +#include + +class LevelInformation { +public: + LevelInformation() { + levelInfos = new std::vector >(); + } + ~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 & GetLevel(unsigned level) { + assert(level < levelInfos->size()); + return (*levelInfos)[level]; + } + + void Reset() { + delete levelInfos; + levelInfos = new std::vector >(); + } + +private: + std::vector > * levelInfos; +}; + +#endif /* LEVELINFORMATION_H_ */ diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index a38c161b1..ed442c55c 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -265,9 +265,10 @@ NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector -void readHSGRFromStream(istream &in, vector * edgeList) { - while(!in.eof()) - { +unsigned readHSGRFromStream(istream &in, vector * edgeList) { + unsigned numberOfNodes = 0; + ExternalNodeMap nodeMap; nodeMap.set_empty_key(UINT_MAX); + while(!in.eof()) { EdgeT g; EdgeData e; @@ -297,8 +298,18 @@ void readHSGRFromStream(istream &in, vector * edgeList) { e.forwardTurn = forwardTurn; e.backwardTurn = backwardTurn; 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); } - + return numberOfNodes+1; } #endif // CREATEGRAPH_H diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 89db8d44b..bf1c320f5 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -44,6 +44,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Contractor/Contractor.h" #include "Contractor/ContractionCleanup.h" #include "DataStructures/BinaryHeap.h" +#include "DataStructures/LevelInformation.h" #include "DataStructures/NNGrid.h" #include "DataStructures/TurnInfoFactory.h" #include "Util/BaseConfiguration.h" @@ -101,15 +102,18 @@ int main (int argc, char *argv[]) { char edgeOut[1024]; char ramIndexOut[1024]; char fileIndexOut[1024]; + char levelInfoOut[1024]; strcpy(nodeOut, argv[1]); strcpy(edgeOut, argv[1]); strcpy(ramIndexOut, argv[1]); strcpy(fileIndexOut, argv[1]); + strcpy(levelInfoOut, argv[1]); strcat(nodeOut, ".nodes"); strcat(edgeOut, ".hsgr"); strcat(ramIndexOut, ".ramIndex"); strcat(fileIndexOut, ".fileIndex"); + strcat(levelInfoOut, ".levels"); ofstream mapOutFile(nodeOut, ios::binary); WritableGrid * g = new WritableGrid(); @@ -139,9 +143,9 @@ int main (int argc, char *argv[]) { g->ConstructGrid(ramIndexOut, fileIndexOut); delete g; + unsigned numberOfNodes = int2ExtNodeMap->size(); //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.close(); @@ -156,6 +160,22 @@ int main (int argc, char *argv[]) { cout << "checking data sanity ..." << flush; contractor->CheckForAllOrigEdges(edgeList); 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 & 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; contractor->GetEdges( contractedEdges ); delete contractor;