diff --git a/Cell2Fire/Cell2Fire.cpp b/Cell2Fire/Cell2Fire.cpp index e5391438..a6dc516e 100644 --- a/Cell2Fire/Cell2Fire.cpp +++ b/Cell2Fire/Cell2Fire.cpp @@ -1414,107 +1414,102 @@ Cell2Fire::GetMessages(const std::unordered_map>& sendMess if (this->messagesSent && !this->repeatFire) { - // frequency array - std::unordered_map 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 burntList; bool checkBurnt; - for (auto& _bc : globalMessagesList) + // frequency array + // std::unordered_map 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; + } + } } } } @@ -1536,13 +1531,15 @@ Cell2Fire::GetMessages(const std::unordered_map>& 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); + } } } diff --git a/Cell2Fire/Cell2Fire.vcxproj b/Cell2Fire/Cell2Fire.vcxproj index c8ae8071..d11af77a 100644 --- a/Cell2Fire/Cell2Fire.vcxproj +++ b/Cell2Fire/Cell2Fire.vcxproj @@ -1,162 +1,162 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - {051FD94B-D4FC-4BDA-9AF4-9551628A6952} - Win32Proj - 10.0 - - - - Application - true - v143 - - - Application - false - v143 - - - Application - true - v143 - - - Application - false - v143 - - - - - - - - - - - - - - - - - - - - - true - - - true - - - $(SolutionDir)$(Platform)\$(Configuration)\ - - - - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - - - MachineX86 - true - Windows - - - - - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDLL - Level3 - ProgramDatabase - - - MachineX86 - true - Windows - true - true - - - - - .\include\boost_1_84_0;.\include\dirent-1.25\include;.\include\vcpkg\installed\x64-windows\include - _USE_MATH_DEFINES - stdcpp14 - true - - - Console - - - - - .\include\dirent-1.25\include;.\include\boost_1_84_0;.\include\vcpkg\installed\x64-windows\include - _USE_MATH_DEFINES - stdcpp14 - true - - - Console - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {051FD94B-D4FC-4BDA-9AF4-9551628A6952} + Win32Proj + 10.0 + + + + Application + true + v143 + + + Application + false + v143 + + + Application + true + v143 + + + Application + false + v143 + + + + + + + + + + + + + + + + + + + + + true + + + true + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + + + MachineX86 + true + Windows + + + + + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Windows + true + true + + + + + .\include\boost_1_84_0;.\include\dirent-1.25\include;.\include\vcpkg\installed\x64-windows\include + _USE_MATH_DEFINES + stdcpp14 + true + + + Console + + + + + .\include\dirent-1.25\include;.\include\boost_1_84_0;.\include\vcpkg\installed\x64-windows\include + _USE_MATH_DEFINES + stdcpp14 + true + + + Console + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Cell2Fire/Cell2Fire.vcxproj.filters b/Cell2Fire/Cell2Fire.vcxproj.filters index 0716cc2a..019e5cf4 100644 --- a/Cell2Fire/Cell2Fire.vcxproj.filters +++ b/Cell2Fire/Cell2Fire.vcxproj.filters @@ -1,105 +1,105 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + \ No newline at end of file diff --git a/Cell2Fire/Cells.cpp b/Cell2Fire/Cells.cpp index 003b8f28..75055255 100644 --- a/Cell2Fire/Cells.cpp +++ b/Cell2Fire/Cells.cpp @@ -1197,18 +1197,6 @@ Cells::get_burned(int period, return false; } -/* Old functions - Returns void - - Inputs: - AdjacentCells dictionary{string:[array integers]} -*/ -// void Cells::set_Adj(std::unordered_map & adjacentCells) { -// // WORKING CHECK OK -// // TODO: in python, these are pointers, maybe make these pointers too :P -// this->adjacents = adjacentCells; -// } - /** * @brief Sets a cell's fire status (0: Available, 1: Burning, 2: Burnt, 3: * Harvested, 4: Non Fuel). diff --git a/Cell2Fire/ReadArgs.cpp b/Cell2Fire/ReadArgs.cpp index 3d641918..99ef4eb1 100644 --- a/Cell2Fire/ReadArgs.cpp +++ b/Cell2Fire/ReadArgs.cpp @@ -106,6 +106,7 @@ parseArgs(int argc, char* argv[], arguments* args_ptr) bool out_stats = false; bool bbo_tuning = false; bool allow_cros = false; + bool all_messages = false; //--out-messages if (cmdOptionExists(argv, argv + argc, "--output-messages")) @@ -199,6 +200,18 @@ parseArgs(int argc, char* argv[], arguments* args_ptr) printf("FinalGrid: %s \n", btoa(out_finalgrid)); } + //--all-messages + if (cmdOptionExists(argv, argv + argc, "--all-messages")) + { + all_messages = true; + printf("Save all messages: %d \n", all_messages); + if (!out_messages) + { + printf("OutMessages: %s \n", btoa(true)); + out_messages = true; + } + } + //--Prom_tuned // if (cmdOptionExists(argv, argv + argc, "--PromTuned")) { // prom_tuned = true; @@ -597,6 +610,7 @@ parseArgs(int argc, char* argv[], arguments* args_ptr) args_ptr->Stats = out_stats; args_ptr->BBOTuning = bbo_tuning; args_ptr->AllowCROS = allow_cros; + args_ptr->AllMessages = all_messages; } void diff --git a/Cell2Fire/ReadArgs.h b/Cell2Fire/ReadArgs.h index aa92b410..542e9487 100644 --- a/Cell2Fire/ReadArgs.h +++ b/Cell2Fire/ReadArgs.h @@ -16,7 +16,8 @@ typedef struct { std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator; bool OutMessages, OutFl, OutIntensity, OutRos, OutCrown, OutCrownConsumption, OutSurfConsumption, Trajectories, - NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS; + NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS, + AllMessages; float ROSCV, ROSThreshold, CROSThreshold, HFIThreshold, HFactor, FFactor, BFactor, EFactor, FirePeriodLen; float CBDFactor, CCFFactor, ROS10Factor, CROSActThreshold; int MinutesPerWP, MaxFirePeriods, TotalYears, TotalSims, NWeatherFiles, IgnitionRadius, seed, nthreads, FMC, diff --git a/test/target_results.zip b/test/target_results.zip index c48d428d..b95ee8bd 100644 Binary files a/test/target_results.zip and b/test/target_results.zip differ diff --git a/test/test.ps1 b/test/test.ps1 index 1964f66c..4f174120 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -9,55 +9,75 @@ $WarningPreference = "SilentlyContinue" # Run simulations foreach ($format in "asc", "tif") { foreach ($model in "fbp", "kitral", "sb", "portugal") { - Write-Output "Running $model-$format" - $outputDir = "test_results/$model-$format" - - # Create (or clean) output folder - if (Test-Path $outputDir) { - Get-ChildItem -Path $outputDir -Recurse -Force | Remove-Item -Force - } else { - New-Item -ItemType Directory -Force -Path $outputDir | Out-Null - } - - # Determine arguments based on model - switch ($model) { - "fbp" { - $additionalArgs = "--cros" - $simCode = "C" + foreach ($msg in "all", "normal") + { + Write-Output "Running $model-$format-$msg" + $outputDir = "test_results/$model-$format-$msg" + + # Create (or clean) output folder + if (Test-Path $outputDir) + { + Get-ChildItem -Path $outputDir -Recurse -Force | Remove-Item -Force } - "sb" { - $additionalArgs = "--scenario 1" - $simCode = "S" + else + { + New-Item -ItemType Directory -Force -Path $outputDir | Out-Null } - "portugal" { - $additionalArgs = "--scenario 1" - $simCode = "P" + + # Determine arguments based on model + switch ($model) + { + "fbp" { + $additionalArgs = "--cros" + $simCode = "C" + } + "sb" { + $additionalArgs = "--scenario 1" + $simCode = "S" + } + "portugal" { + $additionalArgs = "--scenario 1" + $simCode = "P" + } + "kitral" { + $additionalArgs = "" + $simCode = "K" + } } - "kitral" { - $additionalArgs = "" - $simCode = "K" + switch ($msg) + { + "all" { + $msgs = "--all-messages" + } + "normal" { + $msgs = "--output-messages" + } } - } - # Build argument list and run simulation - $cmdArgs = @( - "--input-instance-folder", "model/$model-$format", - "--output-folder", $outputDir, - "--nsims", "113", - "--output-messages", "--grids", "--out-intensity", "--ignitionsLog", - "--sim", $simCode, - "--seed", "123" - ) - if ($additionalArgs) { - $cmdArgs += $additionalArgs.Split(" ") - } - $logFile = "$outputDir/log.txt" + # Build argument list and run simulation + $cmdArgs = @( + "--input-instance-folder", "model/$model-$format", + "--output-folder", $outputDir, + "--nsims", "113", + "--output-messages", "--grids", "--out-intensity", "--ignitionsLog", + "--sim", $simCode, + "--seed", "123" + ) + if ($additionalArgs) + { + $cmdArgs += $additionalArgs.Split(" ") + }if ($msgs) + { + $cmdArgs += $msgs.Split(" ") + } + $logFile = "$outputDir/log.txt" - # Run the simulation and tee the output to a log file - & .\..\Cell2Fire\x64\Release\Cell2Fire.exe @cmdArgs *> $logFile 2>$null - (Get-Content $logFile) -replace '\\', '/' | Set-Content $logFile - (Get-Content $logFile | Select-String -pattern 'version:' -notmatch) | Set-Content $logFile - (Get-Content "$outputDir/ignition_and_weather_log.csv") -replace '\\', '/' | Set-Content "$outputDir/ignition_and_weather_log.csv" + # Run the simulation and tee the output to a log file + & .\..\Cell2Fire\x64\Release\Cell2Fire.exe @cmdArgs *> $logFile 2> $null + (Get-Content $logFile) -replace '\\', '/' | Set-Content $logFile + (Get-Content $logFile | Select-String -pattern 'version:' -notmatch) | Set-Content $logFile + (Get-Content "$outputDir/ignition_and_weather_log.csv") -replace '\\', '/' | Set-Content "$outputDir/ignition_and_weather_log.csv" + } } } diff --git a/test/test.sh b/test/test.sh index 8cc298df..285a42fa 100755 --- a/test/test.sh +++ b/test/test.sh @@ -17,30 +17,37 @@ unzip -q target_results.zip PATH=../Cell2Fire:$PATH # run -set -x # enable debug tracing +# set -x # enable debug tracing for format in asc tif; do for model in fbp kitral sb portugal; do - echo running $model-$format - output_folder=test_results/$model-$format - mkdir -p $output_folder - rm -rf $output_folder/* - if [ "$model" == "fbp" ]; then - additional_args="--cros" - sim_code="C" - elif [ "$model" == "sb" ]; then - additional_args="--scenario 1" - sim_code="S" - elif [ "$model" == "portugal" ]; then - additional_args="--scenario 1" - sim_code="P" - elif [ "$model" == "kitral" ]; then - additional_args="" - sim_code="K" - fi - Cell2Fire$1 --input-instance-folder model/$model-$format --output-folder $output_folder --nsims 113 --output-messages --grids --out-intensity --sim ${sim_code} --seed 123 --ignitionsLog $additional_args >test_results/$model-$format/log.txt + for msg in all normal; do + echo running $model-$format-$msg + output_folder=test_results/$model-$format-$msg + mkdir -p $output_folder + rm -rf $output_folder/* + if [ "$model" == "fbp" ]; then + additional_args="--cros" + sim_code="C" + elif [ "$model" == "sb" ]; then + additional_args="--scenario 1" + sim_code="S" + elif [ "$model" == "portugal" ]; then + additional_args="--scenario 1 " + sim_code="P" + elif [ "$model" == "kitral" ]; then + additional_args="" + sim_code="K" + fi + if [ "$msg" == "all" ]; then + msgs="--all-messages" + elif [ "$msg" == "normal" ]; then + msgs="--output-messages" + fi + Cell2Fire$1 --input-instance-folder model/$model-$format --output-folder $output_folder --nsims 113 --grids --out-intensity --sim ${sim_code} --seed 123 --ignitionsLog ${msgs} ${additional_args} >test_results/$model-$format-$msg/log.txt + done done done -set +x # disable debug tracing +# set +x # disable debug tracing # find difference between directories and files @@ -49,11 +56,11 @@ dir1="test_results" dir2="target_results" # get the list of files in each directory -dir1_files=$(find "$dir1" -type f | sort) -dir1_num_files=$(ls -1 $dir1_files | wc -l) +# dir1_files=$(find "$dir1" -type f | sort) +dir1_num_files=$(find "$dir1" -type f | wc -l) # echo $dir1_files $dir1_num_files -dir2_files=$(find "$dir2" -type f | sort) -dir2_num_files=$(ls -1 $dir2_files | wc -l) +# dir2_files=$(find "$dir2" -type f | sort) +dir2_num_files=$(find "$dir2" -type f | wc -l) # echo $dir2_files $dir2_num_files # check if the number of files in each directory is equal @@ -64,7 +71,7 @@ if [ $dir1_num_files -ne $dir2_num_files ]; then exit 1 fi # delete version line -find test_results/ -name log.txt -type f | xargs sed -i -e '/version:/d' +find test_results/ -name log.txt -type f -exec sed -i -e '/^version:/d' {} \; # use diff to compare the files in each directory diff_output=$(diff -rq "$dir1" "$dir2")