@@ -86,11 +86,54 @@ double Math1::calculateGroundSlopeKoef(directions InvestigatedDirection, int alt
8686 return result;
8787}
8888
89+ double Math1::calculateBiomassKoef (const cell *c) const
90+ {
91+ int coeff = -1 ;
92+ switch (c->getBiomass ())
93+ {
94+ case 0 ... 100 :
95+ coeff = -0.4 ;
96+ break ;
97+ case 101 ... 150 :
98+ coeff = 0 ;
99+ break ;
100+ case 151 ... 300 :
101+ coeff = 0.3 ;
102+ break ;
103+ default :
104+ throw std::invalid_argument (" received strange value in biomass" );
105+ break ;
106+ }
107+ return double (1 +coeff);
108+ }
109+
110+ double Math1::calculateMoistureKoeff (int moisture_percentage) const
111+ {
112+ clock_t start = clock ();
113+
114+ auto a = moisture_result_[moisture_percentage];
115+ if (a != 0 ){
116+ clock_t per_iteration = clock () - start;
117+ moisture_timer_ = per_iteration+moisture_timer_;
118+ moisture_counter_++;
119+ return moisture_result_[moisture_percentage];
120+ };
121+
122+ double result = 2 * exp (-0.111 * moisture_percentage / 100 );
123+ moisture_result_[moisture_percentage] = result;
124+ clock_t per_iteration = clock () - start;
125+ moisture_timer_ = per_iteration+moisture_timer_;
126+ moisture_counter_++;
127+ return result;
128+ }
129+
89130bool Math1::willSpread (const cell *c, directions InvestigatedDirection, int altitudeDifference) const
90131{
91132 double fireKoeff = calculateWindKoef (c, InvestigatedDirection);
92133 double slopeKoeff = calculateGroundSlopeKoef (InvestigatedDirection, altitudeDifference);
93- int result = fireKoeff * slopeKoeff * 100 - 40 ;
134+ double biomassKoeff = calculateBiomassKoef (c);
135+ double moistureKoeff = calculateMoistureKoeff (c->getWind ().get ()->getMoistureCoeff ());
136+ int result = fireKoeff * slopeKoeff * biomassKoeff * moistureKoeff * 100 - 40 ;
94137 result_overall[result]++;
95138 return result + (rand () % 100 ) > ignitionPercentage ();
96139}
@@ -108,6 +151,7 @@ bool to_bool(std::string const &s)
108151}
109152
110153Math1::Math1 ()
154+ :slope_timer(0 ), slope_counter(0 ), wind_timer_(0 ), wind_counter_(0 ), moisture_timer_(0 ), moisture_counter_(0 )
111155{
112156 std::ifstream csvFile{" data/slope.csv" };
113157 std::string row;
@@ -139,16 +183,26 @@ Math1::Math1()
139183 wind_result_[WindMetaData{atoi (cols[0 ].c_str ()), a}] = atof (cols[2 ].c_str ());
140184 }
141185 csvFile2.close ();
142- slope_counter = 0 ;
143- slope_timer = 0 ;
144- wind_counter_ = 0 ;
145- wind_timer_ = 0 ;
186+ std::ifstream csvFile3{" data/moisture.csv" };
187+ while (std::getline (csvFile3, row))
188+ {
189+ std::stringstream rowStream (row);
190+ std::string col;
191+ std::vector<std::string> cols;
192+ while (std::getline (rowStream, col, ' ,' ))
193+ {
194+ cols.push_back (col);
195+ }
196+ moisture_result_[atoi (cols[0 ].c_str ())] = atof (cols[1 ].c_str ());
197+ }
198+ csvFile3.close ();
146199}
147200
148201Math1::~Math1 ()
149202{
150203 printf (" total time %f, overall counts %d\n " , (double )(slope_timer), slope_counter);
151204 printf (" total time %f, overall counts %d\n " , (double )(wind_timer_), wind_counter_);
205+ printf (" total time %f, overall counts %d\n " , (double )(moisture_timer_), moisture_counter_);
152206 // printf("slope profiling\n");
153207 // std::map<int, int> slope_distribution;
154208
0 commit comments