22#include " ../include/Properties.h"
33#include < cmath>
44#include " Math.h"
5+ #include < fstream>
6+ #include < sstream>
7+ #include < vector>
58
69Math::Math (/* args */ )
710{
@@ -33,6 +36,19 @@ double Math1::calculateWindKoef(const cell *c, directions InvestigatedDirection)
3336
3437double Math1::calculateGroundSlopeKoef (directions InvestigatedDirection, int altitudeDifference) const
3538{
39+ clock_t start = clock ();
40+
41+ SlopeMetaData meta = {bool (static_cast <int >(InvestigatedDirection) / int (2 )), altitudeDifference};
42+
43+ // auto a = slope_result_[meta];
44+ // if (a != 0)
45+ // {
46+ // clock_t per_iteration = clock() - start;
47+ // slope_timer = per_iteration+slope_timer;
48+ // slope_counter++;
49+ // return a;
50+ // }
51+
3652 double coef = 0 ;
3753 if (InvestigatedDirection == directions::North || InvestigatedDirection == directions::West ||
3854 InvestigatedDirection == directions::East || InvestigatedDirection == directions::South)
@@ -44,8 +60,13 @@ double Math1::calculateGroundSlopeKoef(directions InvestigatedDirection, int alt
4460 coef = atan2 (static_cast <double >(altitudeDifference), static_cast <double >(cellSizeInMeters () * sqrt (2.0 )));
4561 }
4662 double result = std::exp (0.5 * coef);
47- SlopeMetaData meta = {InvestigatedDirection, altitudeDifference};
48- result_slope_[meta]++;
63+ // SlopeMetaData meta = {bool(static_cast<int>(InvestigatedDirection) / int(2)), altitudeDifference};
64+ slope_counter_[meta]++;
65+ // slope_result_[meta] = result;
66+
67+ clock_t per_iteration = clock () - start;
68+ slope_timer = per_iteration+slope_timer;
69+ slope_counter++;
4970 return result;
5071}
5172
@@ -65,28 +86,61 @@ bool Math1::willSpreadThroughOne(const cell *c, directions InvestigatedDirection
6586 return int (fireKoeff * slopeKoeff * 100 ) + (rand () % 30 ) > throughPercentage ();
6687}
6788
68- Math1::~Math1 ( )
89+ bool to_bool (std::string const &s )
6990{
70- printf (" slope profiling\n " );
71- std::map<int , int > slope_distribution;
72- for (auto &&i : result_slope_)
73- {
74- printf (" %d,%d;%d\n " , i.first .altitude_difference_ , static_cast <int >(i.first .investigated_direction_ ), i.second );
75- slope_distribution[i.second ]++;
76- }
77- printf (" slope distribution\n " );
78- for (auto &&i : slope_distribution)
79- {
80- printf (" %d;%d\n " , i.first , i.second );
81- }
82- printf (" wind profiling\n " );
83- for (auto &&i : result_wind_)
84- {
85- printf (" %2.2f;%d\n " , i.first , i.second );
86- }
87- printf (" overall profiling\n " );
88- for (auto &&i : result_overall)
91+ return s != " 0" ;
92+ }
93+
94+ Math1::Math1 ()
95+ {
96+ std::ifstream csvFile{" data/slope.csv" };
97+ std::string row;
98+ while (std::getline (csvFile, row))
8999 {
90- printf (" %d;%d\n " , i.first , i.second );
100+ std::stringstream rowStream (row);
101+ std::string col;
102+ std::vector<std::string> cols;
103+ while (std::getline (rowStream, col, ' ,' ))
104+ {
105+ cols.push_back (col);
106+ }
107+ auto a = atoi (cols[0 ].c_str ());
108+ slope_result_[SlopeMetaData{to_bool (cols[0 ].c_str ()), a}] = atof (cols[2 ].c_str ());
91109 }
110+ csvFile.close ();
111+ slope_counter = 0 ;
112+ slope_timer = 0 ;
113+ }
114+
115+ Math1::~Math1 ()
116+ {
117+ printf (" total time %f, overall counts %d" , (double )(slope_timer), slope_counter);
118+ // printf("slope profiling\n");
119+ // std::map<int, int> slope_distribution;
120+
121+ // for (auto &&i : slope_result_)
122+ // {
123+ // printf("%d,%d,%f\n", i.first.altitude_difference_, i.first.diagonal_direction_, i.second);
124+ // }
125+
126+ // for (auto &&i : slope_counter_)
127+ // {
128+ // printf("%d,%d;%d\n", i.first.altitude_difference_, i.first.diagonal_direction_, i.second);
129+ // slope_distribution[i.second]++;
130+ // }
131+ // printf("slope distribution\n");
132+ // for (auto &&i : slope_distribution)
133+ // {
134+ // printf("%d;%d\n", i.first, i.second);
135+ // }
136+ // printf("wind profiling\n");
137+ // for (auto &&i : result_wind_)
138+ // {
139+ // printf("%2.2f;%d\n", i.first, i.second);
140+ // }
141+ // printf("overall profiling\n");
142+ // for (auto &&i : result_overall)
143+ // {
144+ // printf("%d;%d\n", i.first, i.second);
145+ // }
92146}
0 commit comments