Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
30 changes: 24 additions & 6 deletions Cell2Fire/Cell2Fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ __maintainer__ = "Jaime Carrasco, Cristobal Pais, David Woodruff, David Palacios

// Include libraries
#include <omp.h>
#include <typeinfo>
#include <stdio.h>
#include <stdlib.h>
#include <string>
Expand Down Expand Up @@ -48,6 +49,7 @@ std::unordered_map<int, std::vector<float>> BBOFactors;
std::unordered_map<int, std::vector<int>> HarvestedCells;
std::vector<int> NFTypesCells;
std::unordered_map<int,int> IgnitionHistory;
std::vector<int> initialPoints;

/******************************************************************************
Utils
Expand Down Expand Up @@ -289,7 +291,7 @@ Cell2Fire::Cell2Fire(arguments _args) : CSVWeather(_args.InFolder + "Weather.csv
std::vector<int> IgnitionPoints;

if(this->args.Ignitions){
//DEBUGstd::cout << "\nWe have specific ignition points:" << std::endl;
//DEBUG std::cout << "\nWe have specific ignition points:" << std::endl;

/* Ignition points */
std::string ignitionFile = args.InFolder + "Ignitions.csv";
Expand All @@ -310,9 +312,11 @@ Cell2Fire::Cell2Fire(arguments _args) : CSVWeather(_args.InFolder + "Weather.csv

// Ignition points
this->IgnitionPoints = std::vector<int>(IgnitionYears, 0);
//std::cout << this->IgnitionPoints[1] << std::endl;

CSVIgnitions.parseIgnitionDF(this->IgnitionPoints, IgnitionsDF, IgnitionYears);
//this->IgnitionSets = std::vector<unordered_set<int>>(this->IgnitionPoints.size());
this->IgnitionSets = std::vector<std::vector<int>>(this->args.TotalYears);
this->IgnitionSets = std::vector<std::vector<int>>(args.TotalYears);


// Ignition radius
Expand Down Expand Up @@ -780,7 +784,7 @@ bool Cell2Fire::RunIgnition(std::default_random_engine generator, int ep){
std::uniform_int_distribution<int> distribution(1, this->nCells);

// No Ignitions provided
if (this->args.Ignitions == 0) {
if (this->args.Ignitions == "random" || this->args.Ignitions == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El tipo de Ignition actualmente es Bool, tiene que pasarse a string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matiasuno hiciste este cambio?

while (true) {
microloops = 0;
while (true) {
Expand Down Expand Up @@ -849,8 +853,19 @@ bool Cell2Fire::RunIgnition(std::default_random_engine generator, int ep){
}

// Ignitions with provided points from CSV
else {
int temp = IgnitionPoints[this->year-1];
else if (args.Ignitions == "raster") {

if (initialPoints.empty()) {
initialPoints = this->IgnitionPoints;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agregar identación

}

std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(1,initialPoints.size());
int rd = dist(rng);

int temp = initialPoints[rd-1];
initialPoints.erase(initialPoints.begin() + rd-1);

// If ignition Radius != 0, sample from the Radius set
if (this->args.IgnitionRadius > 0){
Expand Down Expand Up @@ -908,7 +923,10 @@ bool Cell2Fire::RunIgnition(std::default_random_engine generator, int ep){

}


else {
std::cerr << "Error: ignition mode not found" << std::endl;
return;
}


// If ignition occurs, we update the forest status
Expand Down
1 change: 1 addition & 0 deletions Cell2Fire/Cell2Fire.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Cell2Fire {
std::vector<float>RateOfSpreads;
std::vector<float>FlameLengths;
std::vector<std::vector<int>> IgnitionSets;
std::vector<int> initialPoints;
// std::vector<int> IgnitionHistory;

// Sets
Expand Down
2 changes: 1 addition & 1 deletion Cell2Fire/ReadCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void CSVReader::parseIgnitionDF(std::vector<int> & ig, std::vector<std::vector<s

// Set values
ig[i-1]= igcell;

std::cout << igcell << std::endl;
// Next pointer
//ig_ptr++;
}
Expand Down
2 changes: 1 addition & 1 deletion data/CanadianFBP/400cellsC1-asc/Ignitions.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Year,Ncell
1,205
1,305
2,350
3,100
4,380
31 changes: 16 additions & 15 deletions test/test.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ set -x # enable debug tracing
# run
for format in asc tif; do
for model in fbp kitral sb; 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" == "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-ros --out-intensity --sim ${sim_code} --seed 123 --ignitionsLog $additional_args > test_results/$model-$format/log.txt
for ignition_mode in random raster; 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" == "kitral" ]; then
additional_args=""
sim_code="K"
fi
Cell2Fire$1 --input-instance-folder model/$model-$format --output-folder $output_folder --nsims 113 --ignitions-$ignition_mode --output-messages --grids --out-ros --out-intensity --sim ${sim_code} --seed 123 --ignitionsLog $additional_args > test_results/$model-$format-$ignition_mode/log.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El ignition mode tiene que ser el adecuado para que funcione el test. Aparte hay que hacer un chequeo del funcionamiento de los puntos múltiples.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matiasuno Resolviste esto?

done
done
set +x # disable debug tracing
Expand Down