Fixes bad alloc for large graphs
This commit is contained in:
parent
effee46011
commit
43bbf953c1
@ -42,8 +42,11 @@ private:
|
||||
parent = p;
|
||||
}
|
||||
};
|
||||
#ifdef _MANYCORES
|
||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
|
||||
#else
|
||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
|
||||
|
||||
#endif
|
||||
struct _ThreadData {
|
||||
_Heap* _heapForward;
|
||||
_Heap* _heapBackward;
|
||||
@ -99,11 +102,8 @@ public:
|
||||
}
|
||||
|
||||
void Run() {
|
||||
|
||||
double time = _Timestamp();
|
||||
|
||||
RemoveUselessShortcuts();
|
||||
|
||||
time = _Timestamp() - time;
|
||||
cout << "Postprocessing Time: " << time << " s" << endl;
|
||||
}
|
||||
@ -159,7 +159,11 @@ private:
|
||||
#else
|
||||
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
||||
#endif
|
||||
try {
|
||||
_firstEdge.resize( _numNodes + 1 );
|
||||
} catch(...) {
|
||||
cerr << "Not enough RAM on machine" << endl;
|
||||
}
|
||||
_firstEdge[0] = 0;
|
||||
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
|
||||
while ( _graph[i].source != node )
|
||||
|
@ -96,6 +96,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
|
||||
edgeList.push_back(inputEdge);
|
||||
}
|
||||
ext2IntNodeMap.clear();
|
||||
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
|
||||
cout << "ok" << endl;
|
||||
return n;
|
||||
}
|
||||
|
@ -338,8 +338,8 @@ public:
|
||||
private:
|
||||
unsigned FillCell(std::vector<GridEdgeData>& entriesWithSameRAMIndex, unsigned fileOffset )
|
||||
{
|
||||
vector<char> tmpBuffer;
|
||||
tmpBuffer.resize(32*32*4096,0);
|
||||
vector<char> * tmpBuffer = new vector<char>();
|
||||
tmpBuffer->resize(32*32*4096,0);
|
||||
unsigned indexIntoTmpBuffer = 0;
|
||||
unsigned numberOfWrittenBytes = 0;
|
||||
assert(indexOutFile.is_open());
|
||||
@ -417,16 +417,18 @@ private:
|
||||
//write contents of tmpbuffer to disk
|
||||
for(int i = 0; i < indexIntoTmpBuffer; i++)
|
||||
{
|
||||
indexOutFile.write(&tmpBuffer[i], sizeof(char));
|
||||
indexOutFile.write(&(tmpBuffer->at(i)), sizeof(char));
|
||||
numberOfWrittenBytes += sizeof(char);
|
||||
}
|
||||
|
||||
delete tmpBuffer;
|
||||
delete cellMap;
|
||||
return numberOfWrittenBytes;
|
||||
}
|
||||
|
||||
unsigned FlushEntriesWithSameFileIndexToBuffer(const std::vector<GridEdgeData> &vectorWithSameFileIndex, vector<char>& tmpBuffer, const unsigned index)
|
||||
unsigned FlushEntriesWithSameFileIndexToBuffer(const std::vector<GridEdgeData> &vectorWithSameFileIndex, vector<char> * tmpBuffer, const unsigned index)
|
||||
{
|
||||
tmpBuffer->resize(tmpBuffer->size()+(sizeof(NodeID)+sizeof(NodeID)+4*sizeof(int)+sizeof(unsigned))*vectorWithSameFileIndex.size() );
|
||||
unsigned counter = 0;
|
||||
unsigned max = UINT_MAX;
|
||||
|
||||
@ -441,44 +443,44 @@ private:
|
||||
char * start = (char *)&et->edge.start;
|
||||
for(int i = 0; i < sizeof(NodeID); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = start[i];
|
||||
tmpBuffer->at(index+counter) = start[i];
|
||||
counter++;
|
||||
}
|
||||
char * target = (char *)&et->edge.target;
|
||||
for(int i = 0; i < sizeof(NodeID); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = target[i];
|
||||
tmpBuffer->at(index+counter) = target[i];
|
||||
counter++;
|
||||
}
|
||||
char * slat = (char *) &(et->edge.startCoord.lat);
|
||||
for(int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = slat[i];
|
||||
tmpBuffer->at(index+counter) = slat[i];
|
||||
counter++;
|
||||
}
|
||||
char * slon = (char *) &(et->edge.startCoord.lon);
|
||||
for(int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = slon[i];
|
||||
tmpBuffer->at(index+counter) = slon[i];
|
||||
counter++;
|
||||
}
|
||||
char * tlat = (char *) &(et->edge.targetCoord.lat);
|
||||
for(int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = tlat[i];
|
||||
tmpBuffer->at(index+counter) = tlat[i];
|
||||
counter++;
|
||||
}
|
||||
char * tlon = (char *) &(et->edge.targetCoord.lon);
|
||||
for(int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = tlon[i];
|
||||
tmpBuffer->at(index+counter) = tlon[i];
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
char * umax = (char *) &max;
|
||||
for(int i = 0; i < sizeof(unsigned); i++)
|
||||
{
|
||||
tmpBuffer[index+counter] = umax[i];
|
||||
tmpBuffer->at(index+counter) = umax[i];
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
|
@ -93,9 +93,9 @@ int main (int argc, char *argv[])
|
||||
Percent p(edgeList.size());
|
||||
for(NodeID i = 0; i < edgeList.size(); i++)
|
||||
{
|
||||
p.printIncrement();
|
||||
if(!edgeList[i].isLocatable())
|
||||
continue;
|
||||
p.printIncrement();
|
||||
int slat = int2ExtNodeMap->at(edgeList[i].source()).lat;
|
||||
int slon = int2ExtNodeMap->at(edgeList[i].source()).lon;
|
||||
int tlat = int2ExtNodeMap->at(edgeList[i].target()).lat;
|
||||
@ -123,9 +123,12 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
mapOutFile.close();
|
||||
int2ExtNodeMap->clear();
|
||||
delete int2ExtNodeMap;
|
||||
|
||||
cout << "initializing contractor ..." << flush;
|
||||
Contractor* contractor = new Contractor( n, edgeList );
|
||||
|
||||
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
|
||||
cout << "ok" << endl;
|
||||
contractor->Run();
|
||||
|
||||
cout << "checking data sanity ..." << flush;
|
||||
@ -143,8 +146,11 @@ int main (int argc, char *argv[])
|
||||
ofstream edgeOutFile(edgeOut, ios::binary);
|
||||
|
||||
//Serializing the edge list.
|
||||
cout << "Serializing edges " << flush;
|
||||
p.reinit(cleanedEdgeList.size());
|
||||
for(std::vector< GridEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++)
|
||||
{
|
||||
p.printIncrement();
|
||||
int distance= it->data.distance;
|
||||
assert(distance > 0);
|
||||
bool shortcut= it->data.shortcut;
|
||||
@ -168,5 +174,4 @@ int main (int argc, char *argv[])
|
||||
|
||||
delete cleanup;
|
||||
delete contractor;
|
||||
delete int2ExtNodeMap;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ int main (int argc, char *argv[])
|
||||
time = get_timestamp();
|
||||
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
|
||||
|
||||
std::vector< GridEdge> * edgelist = new std::vector< GridEdge>();
|
||||
std::vector< GridEdge> * edgeList = new std::vector< GridEdge>();
|
||||
while(!in.eof())
|
||||
{
|
||||
GridEdge g;
|
||||
@ -89,7 +89,7 @@ int main (int argc, char *argv[])
|
||||
e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut;
|
||||
g.data = e; g.source = source; g.target = target;
|
||||
|
||||
edgelist->push_back(g);
|
||||
edgeList->push_back(g);
|
||||
}
|
||||
|
||||
in.close();
|
||||
@ -99,8 +99,8 @@ int main (int argc, char *argv[])
|
||||
nodeInfoHelper->initNNGrid(in2);
|
||||
cout << "in " << get_timestamp() - time << "s" << endl;
|
||||
// time = get_timestamp();
|
||||
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgelist);
|
||||
delete edgelist;
|
||||
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgeList);
|
||||
delete edgeList;
|
||||
// cout << "checking data sanity ..." << flush;
|
||||
// NodeID numberOfNodes = graph->GetNumberOfNodes();
|
||||
// for ( NodeID node = 0; node < numberOfNodes; ++node ) {
|
||||
|
Loading…
Reference in New Issue
Block a user