diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 34c9b62fa..3d3e86e6e 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -138,30 +138,13 @@ static void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate& template class NNGrid { - struct _ThreadData{ - _ThreadData(const char * iif) { - stream.open(iif, std::ios::in | std::ios::binary); - } - ~_ThreadData() { - stream.close(); - } - ifstream stream; - }; - - typedef HashTable ThreadLookupTable; public: - ThreadLookupTable threadLookup; - NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector(); }} - NNGrid(const char* rif, const char* iif, unsigned numberOfThreads = omp_get_num_procs()) { + NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()) { + iif = _i; ramIndexTable.resize((1024*1024), UINT_MAX); -// indexInFile.open(iif, std::ios::in | std::ios::binary); ramInFile.open(rif, std::ios::in | std::ios::binary); - - for(int i = 0; i< omp_get_num_procs(); i++) { - indexFileStreams.push_back(new _ThreadData(iif)); - } } ~NNGrid() { @@ -170,12 +153,6 @@ public: if (WriteAccess) { delete entries; } - - for(unsigned i = 0; i< indexFileStreams.size(); i++) { - delete indexFileStreams[i]; - } - threadLookup.EraseAll(); - ramIndexTable.clear(); } void OpenIndexFiles() { @@ -526,21 +503,21 @@ private: } void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_Edge>& result) { - unsigned threadID = threadLookup.Find(boost_thread_id_hash(boost::this_thread::get_id())); +// unsigned threadID = threadLookup.Find(boost_thread_id_hash(boost::this_thread::get_id())); unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex); unsigned startIndexInFile = ramIndexTable[ramIndex]; // ifstream indexInFile( indexFileStreams[threadID]->stream ); if(startIndexInFile == UINT_MAX){ return; } - + std::ifstream localStream(iif, std::ios::in | std::ios::binary); std::vector cellIndex; cellIndex.resize(32*32); google::dense_hash_map< unsigned, unsigned > * cellMap = new google::dense_hash_map< unsigned, unsigned >(1024); cellMap->set_empty_key(UINT_MAX); - indexFileStreams[threadID]->stream.seekg(startIndexInFile); + localStream.seekg(startIndexInFile); unsigned lineBase = ramIndex/1024; lineBase = lineBase*32*32768; @@ -561,7 +538,7 @@ private: unsigned numOfElementsInCell = 0; for(int i = 0; i < 32*32; i++) { - indexFileStreams[threadID]->stream.read((char *)&cellIndex[i], sizeof(unsigned)); + localStream.read((char *)&cellIndex[i], sizeof(unsigned)); numOfElementsInCell += cellIndex[i]; } assert(cellMap->find(fileIndex) != cellMap->end()); @@ -571,18 +548,18 @@ private: return; } unsigned position = cellIndex[cellMap->find(fileIndex)->second] + 32*32*sizeof(unsigned) ; - indexFileStreams[threadID]->stream.seekg(position); + localStream.seekg(position); unsigned numberOfEdgesInFileBucket = 0; NodeID start, target; int slat, slon, tlat, tlon; do{ - indexFileStreams[threadID]->stream.read((char *)&(start), sizeof(NodeID)); - if(start == UINT_MAX || indexFileStreams[threadID]->stream.eof()) + localStream.read((char *)&(start), sizeof(NodeID)); + if(localStream.eof() || start == UINT_MAX) break; - indexFileStreams[threadID]->stream.read((char *)&(target), sizeof(NodeID)); - indexFileStreams[threadID]->stream.read((char *)&(slat), sizeof(int)); - indexFileStreams[threadID]->stream.read((char *)&(slon), sizeof(int)); - indexFileStreams[threadID]->stream.read((char *)&(tlat), sizeof(int)); - indexFileStreams[threadID]->stream.read((char *)&(tlon), sizeof(int)); + localStream.read((char *)&(target), sizeof(NodeID)); + localStream.read((char *)&(slat), sizeof(int)); + localStream.read((char *)&(slon), sizeof(int)); + localStream.read((char *)&(tlat), sizeof(int)); + localStream.read((char *)&(tlon), sizeof(int)); _Edge e(start, target); e.startCoord.lat = slat; @@ -593,7 +570,7 @@ private: result.push_back(e); numberOfEdgesInFileBucket++; } while(true); - + localStream.close(); delete cellMap; } @@ -643,9 +620,9 @@ private: ofstream indexOutFile; ifstream ramInFile; - std::vector < _ThreadData* > indexFileStreams; stxxl::vector * entries; std::vector ramIndexTable; //4 MB for first level index in RAM + const char * iif; }; } diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index add8b8b8c..bf0e9e796 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -71,9 +71,6 @@ public: readOnlyGrid->FindNearestPointOnEdge(input, output); } - inline void RegisterThread(const unsigned k, const unsigned v) { - readOnlyGrid->threadLookup.Add(k, v); - } private: vector<_Coordinate> * int2ExtNodeMap; ReadOnlyGrid * readOnlyGrid; diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 9b3f05d35..e41550c10 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -83,8 +83,8 @@ public: bool startReverse = false; bool targetReverse = false; - _Heap * _forwardHeap = new _Heap(nodeHelpDesk->getNumberOfNodes()); - _Heap * _backwardHeap = new _Heap(nodeHelpDesk->getNumberOfNodes()); + _Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes()); + _Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes()); NodeID middle = ( NodeID ) 0; unsigned int _upperbound = std::numeric_limits::max(); @@ -102,8 +102,6 @@ public: } if(currentEdge == UINT_MAX){ - delete _forwardHeap; - delete _backwardHeap; return _upperbound; } @@ -128,39 +126,33 @@ public: getNodeInfo(phantomNodes->startNode2, result); EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance; - _forwardHeap->Insert(phantomNodes->startNode2, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode2); - _backwardHeap->Insert(phantomNodes->startNode1, absDouble( w-w*phantomNodes->targetRatio), phantomNodes->startNode1); + _forwardHeap.Insert(phantomNodes->startNode2, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode2); + _backwardHeap.Insert(phantomNodes->startNode1, absDouble( w-w*phantomNodes->targetRatio), phantomNodes->startNode1); } - } else if(phantomNodes->startNode1 != UINT_MAX) - { + } else if(phantomNodes->startNode1 != UINT_MAX) { EdgeID edge = _graph->FindEdge( phantomNodes->startNode1, phantomNodes->startNode2); if(edge == UINT_MAX){ edge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 ); startReverse = true; } if(edge == UINT_MAX){ - delete _forwardHeap; - delete _backwardHeap; return _upperbound; } const EdgeData& ed = _graph->GetEdgeData(edge); EdgeWeight w = ed.distance; if( (ed.backward && !startReverse) || (ed.forward && startReverse) ) - _forwardHeap->Insert(phantomNodes->startNode1, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode1); + _forwardHeap.Insert(phantomNodes->startNode1, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode1); if( (ed.backward && startReverse) || (ed.forward && !startReverse) ) - _forwardHeap->Insert(phantomNodes->startNode2, absDouble(w-w*phantomNodes->startRatio), phantomNodes->startNode2); + _forwardHeap.Insert(phantomNodes->startNode2, absDouble(w-w*phantomNodes->startRatio), phantomNodes->startNode2); } - if(phantomNodes->targetNode1 != UINT_MAX && !onSameEdgeReversed) - { + if(phantomNodes->targetNode1 != UINT_MAX && !onSameEdgeReversed) { EdgeID edge = _graph->FindEdge( phantomNodes->targetNode1, phantomNodes->targetNode2); if(edge == UINT_MAX){ edge = _graph->FindEdge( phantomNodes->targetNode2, phantomNodes->targetNode1 ); targetReverse = true; } if(edge == UINT_MAX){ - delete _forwardHeap; - delete _backwardHeap; return _upperbound; } @@ -168,33 +160,30 @@ public: EdgeWeight w = ed.distance; if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) ) - _backwardHeap->Insert(phantomNodes->targetNode2, absDouble( w*phantomNodes->targetRatio), phantomNodes->targetNode2); + _backwardHeap.Insert(phantomNodes->targetNode2, absDouble( w*phantomNodes->targetRatio), phantomNodes->targetNode2); if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) ) - _backwardHeap->Insert(phantomNodes->targetNode1, absDouble(w-w*phantomNodes->startRatio), phantomNodes->targetNode1); + _backwardHeap.Insert(phantomNodes->targetNode1, absDouble(w-w*phantomNodes->startRatio), phantomNodes->targetNode1); } // double time = get_timestamp(); NodeID sourceHeapNode = 0; NodeID targetHeapNode = 0; if(onSameEdgeReversed) { - sourceHeapNode = _forwardHeap->Min(); - targetHeapNode = _backwardHeap->Min(); + sourceHeapNode = _forwardHeap.Min(); + targetHeapNode = _backwardHeap.Min(); } - while(_forwardHeap->Size() + _backwardHeap->Size() > 0) - { - if ( _forwardHeap->Size() > 0 ) { - _RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound ); + while(_forwardHeap.Size() + _backwardHeap.Size() > 0) { + if ( _forwardHeap.Size() > 0 ) { + _RoutingStep( &_forwardHeap, &_backwardHeap, true, &middle, &_upperbound ); } - if ( _backwardHeap->Size() > 0 ) { - _RoutingStep( _backwardHeap, _forwardHeap, false, &middle, &_upperbound ); + if ( _backwardHeap.Size() > 0 ) { + _RoutingStep( &_backwardHeap, &_forwardHeap, false, &middle, &_upperbound ); } } // std::cout << "[debug] computing distance took " << get_timestamp() - time << std::endl; // time = get_timestamp(); if ( _upperbound == std::numeric_limits< unsigned int >::max() || onSameEdge ) { - delete _forwardHeap; - delete _backwardHeap; return _upperbound; } @@ -202,7 +191,7 @@ public: deque< NodeID > packedPath; while ( onSameEdgeReversed ? pathNode != sourceHeapNode : pathNode != phantomNodes->startNode1 && pathNode != phantomNodes->startNode2 ) { - pathNode = _forwardHeap->GetData( pathNode ).parent; + pathNode = _forwardHeap.GetData( pathNode ).parent; packedPath.push_front( pathNode ); } // NodeID realStart = pathNode; @@ -210,19 +199,16 @@ public: pathNode = middle; while ( onSameEdgeReversed ? pathNode != targetHeapNode : pathNode != phantomNodes->targetNode2 && pathNode != phantomNodes->targetNode1 ){ - pathNode = _backwardHeap->GetData( pathNode ).parent; + pathNode = _backwardHeap.GetData( pathNode ).parent; packedPath.push_back( pathNode ); } path->push_back( _PathData(packedPath[0]) ); - for(deque::size_type i = 0; i < packedPath.size()-1; i++) - { + for(deque::size_type i = 0; i < packedPath.size()-1; i++) { _UnpackEdge(packedPath[i], packedPath[i+1], path); } packedPath.clear(); - delete _forwardHeap; - delete _backwardHeap; // std::cout << "[debug] unpacking path took " << get_timestamp() - time << std::endl; return _upperbound/10;