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