Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 88 additions & 91 deletions Cell2Fire/Cell2Fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,107 +1414,102 @@ Cell2Fire::GetMessages(const std::unordered_map<int, std::vector<int>>& sendMess
if (this->messagesSent && !this->repeatFire)
{

// frequency array
std::unordered_map<int, int> globalMessagesList;
for (auto& sublist : sendMessageList)
{
for (int val : sublist.second)
{
if (globalMessagesList.find(val) == globalMessagesList.end())
{
globalMessagesList[val] = 1;
}
else
{
globalMessagesList[val] = globalMessagesList[val] + 1;
}
}
}

// Initialize cells if needed (getting messages)
for (auto& _bc : globalMessagesList)
{
int bc = _bc.first;
if (this->Cells_Obj.find(bc) == this->Cells_Obj.end()
&& this->burntCells.find(bc) == this->burntCells.end())
{
// Initialize cell, insert it inside the unordered map
InitCell(bc);
it = this->Cells_Obj.find(bc);
}
}

// Get burnt loop
if (this->args.verbose)
{
for (auto& _bc : globalMessagesList)
{
printf("CELL %d inside global message list \n", _bc.first);
}
}

std::unordered_set<int> burntList;
bool checkBurnt;
for (auto& _bc : globalMessagesList)
// frequency array
// std::unordered_map<int, int> globalMessagesList;
for (auto& sublist : sendMessageList)
{
// printf("\n\nWE ARE DEBUGGING!!!! CELL TO BE ANALYZED GET BURNT IS
// %d\n", _bc.first);
int bc = _bc.first;
if (this->burntCells.find(bc) == this->burntCells.end())
for (int bc : sublist.second)
{
if (this->Cells_Obj.find(bc) == this->Cells_Obj.end())
if (this->Cells_Obj.find(bc) == this->Cells_Obj.end()
&& this->burntCells.find(bc) == this->burntCells.end())
{

// Initialize cell, insert it inside the unordered map
InitCell(bc);
it = this->Cells_Obj.find(bc);
}
else
it = this->Cells_Obj.find(bc);

// Check if burnable, then check potential ignition
if (it->second.fType != 0)
{
checkBurnt = it->second.get_burned(this->fire_period[this->year - 1],
1,
this->year,
df,
this->coef_ptr,
this->args_ptr,
&this->wdf[this->weatherPeriod],
this->activeCrown,
this->perimeterCells);
}
else
if ((this->burntCells.find(bc) == this->burntCells.end() && !this->args_ptr->AllMessages)
|| this->args_ptr->AllMessages)
{
checkBurnt = false;
}
if (this->Cells_Obj.find(bc) == this->Cells_Obj.end())
{

// Print-out regarding the burnt cell
if (this->args.verbose)
{
std::cout << "\nCell " << it->second.realId << " got burnt (1 true, 0 false): " << checkBurnt
<< std::endl;
}
// Initialize cell, insert it inside the unordered map
InitCell(bc);
it = this->Cells_Obj.find(bc);
}
else
it = this->Cells_Obj.find(bc);

// Update the burntlist
if (checkBurnt)
{
burntList.insert(it->second.realId);
// Check if burnable, then check potential ignition
if (it->second.fType != 0)
{
checkBurnt = it->second.get_burned(this->fire_period[this->year - 1],
1,
this->year,
df,
this->coef_ptr,
this->args_ptr,
&this->wdf[this->weatherPeriod],
this->activeCrown,
this->perimeterCells);
}
else
{
checkBurnt = false;
}

// Cleaning step
// Fire can't be propagated back
int cellNum = it->second.realId - 1;
for (auto& angle : it->second.angleToNb)
// Print-out regarding the burnt cell
if (this->args.verbose)
{
int origToNew = angle.first;
// Which neighbor am I to the burnt cell
int newToOrig = (origToNew + 180) % 360;
int adjCellNum = angle.second; // Check
auto adjIt = Cells_Obj.find(adjCellNum);
if (adjIt != Cells_Obj.end())
std::cout << "\nCell " << it->second.realId << " got burnt (1 true, 0 false): " << checkBurnt
<< std::endl;
}

// Update the burntlist
if (checkBurnt)
{
burntList.insert(it->second.realId);

// emitter->second.ROSAngleDir.erase()
// std::cout << "step " << this->fire_period[this->year - 1] << " Cell " << it->second.realId
// << " got burnt by " << emitter->second.realId << " with emitter angle to nb "
// << emitter->second.angleDict[it->second.realId] << endl;
if (this->args_ptr->AllMessages)
{
adjIt->second.ROSAngleDir.erase(newToOrig);
auto emitter = this->Cells_Obj.find(sublist.first);
emitter->second.ROSAngleDir.erase(emitter->second.angleDict[it->second.realId]);
it->second.ROSAngleDir.erase(it->second.angleDict[sublist.first]);
/*cout << "burned " << bc << endl;
cout << "\t from " << emitter->second.realId << " erased " << it->second.realId << " angle "
<< emitter->second.angleDict[it->second.realId] << endl;
cout << "\t from " << it->second.realId << " erased " << emitter->second.realId << " angle "
<< it->second.angleDict[emitter->second.realId] << endl;
*/
}
else
{
auto lt = this->availCells.find(bc);
if (lt != this->availCells.end())
{
this->availCells.erase(bc);
// cout << this->fire_period[0] << " erased from availCells " << bc << endl;
}
for (auto& angle : it->second.angleToNb)
{
int origToNew = angle.first;
// Which neighbor am I to the burnt cell
int newToOrig = (origToNew + 180) % 360;
int adjCellNum = angle.second; // Check
auto adjIt = Cells_Obj.find(adjCellNum);
if (adjIt != Cells_Obj.end())
{
adjIt->second.ROSAngleDir.erase(newToOrig);
// cout << "from " << adjIt->second.realId << " erased " << it->second.realId <<
// endl;
}
}
}
}
}
Expand All @@ -1536,13 +1531,15 @@ Cell2Fire::GetMessages(const std::unordered_map<int, std::vector<int>>& sendMess
{
this->burningCells.insert(bc);
}

for (auto& bc : burningCells)
if (this->args_ptr->AllMessages)
{
auto lt = this->availCells.find(bc);
if (lt != this->availCells.end())
for (auto& bc : burningCells)
{
this->availCells.erase(bc);
auto lt = this->availCells.find(bc);
if (lt != this->availCells.end())
{
this->availCells.erase(bc);
}
}
}

Expand Down
Loading
Loading