C
chenbo09
Hello! I am trying to use priority queue to store my nodes, and I need
to insert and retrieve elements very frequently. The size of the queue
increases dramatically at the beginning and starts to reduce after the
queue reaches its maximum size in the process.
The queue contains objects with three data members, i.e., row number,
column number, elevation. The object with the smallest elevation will
be the first element in the queue.
I am trying to implement an algorithm proposed by a published research
paper, the authored wrote "The algorithm could process a gird with 500
* 1000 cells in 2 seconds", while it seems that it took my code 2
hours to finish the task. I observed the intermediate output and found
that the maximum size of my queue was about 20,000.
The following is my code, please help, thanks a lot!
********************************************************
while( !theQueue.empty())
{
tempNode = theQueue.top();
row = tempNode.row;
col = tempNode.col;
theQueue.pop();
z = DEMFill.get_cellValue(row, col);
for(i = 0; i < 8; i++)
{
irow = Get_rowTo(i, row);
icol = Get_colTo(i, col);
if(DEM.is_inGrid(irow, icol) && DEM.is_InternalCell(irow, icol) &&
DEMFill.is_nodataCell(irow, icol))
{
double iz = DEM.get_cellValue(irow, icol);
if( iz < z) { iz = z; }
DEMFill.set_cellValue(irow, icol, iz);
progress++;
tempNode.row = irow;
tempNode.col = icol;
tempNode.spill = iz;
//theQueue.push( tempNode );
}
}
if ((progress % 5000) == 0)
{
cout << theQueue.size() << " " << progress << " " <<
DEMFill.get_nValidCells() << endl;
}
if (progress == DEMFill.get_nValidCells())
{
cout << "Finished!" << endl;
break;
}
}
to insert and retrieve elements very frequently. The size of the queue
increases dramatically at the beginning and starts to reduce after the
queue reaches its maximum size in the process.
The queue contains objects with three data members, i.e., row number,
column number, elevation. The object with the smallest elevation will
be the first element in the queue.
I am trying to implement an algorithm proposed by a published research
paper, the authored wrote "The algorithm could process a gird with 500
* 1000 cells in 2 seconds", while it seems that it took my code 2
hours to finish the task. I observed the intermediate output and found
that the maximum size of my queue was about 20,000.
The following is my code, please help, thanks a lot!
********************************************************
while( !theQueue.empty())
{
tempNode = theQueue.top();
row = tempNode.row;
col = tempNode.col;
theQueue.pop();
z = DEMFill.get_cellValue(row, col);
for(i = 0; i < 8; i++)
{
irow = Get_rowTo(i, row);
icol = Get_colTo(i, col);
if(DEM.is_inGrid(irow, icol) && DEM.is_InternalCell(irow, icol) &&
DEMFill.is_nodataCell(irow, icol))
{
double iz = DEM.get_cellValue(irow, icol);
if( iz < z) { iz = z; }
DEMFill.set_cellValue(irow, icol, iz);
progress++;
tempNode.row = irow;
tempNode.col = icol;
tempNode.spill = iz;
//theQueue.push( tempNode );
}
}
if ((progress % 5000) == 0)
{
cout << theQueue.size() << " " << progress << " " <<
DEMFill.get_nValidCells() << endl;
}
if (progress == DEMFill.get_nValidCells())
{
cout << "Finished!" << endl;
break;
}
}