Skip to content

Commit 5060a78

Browse files
some updates
1 parent 1c17cbb commit 5060a78

File tree

12 files changed

+112
-32
lines changed

12 files changed

+112
-32
lines changed

data/wind.csv

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
0,5.000000,1.000000
2-
1,5.000000,0.093164
3-
2,5.000000,0.000717
1+
0,2.000000,1.000000
2+
1,2.000000,0.386990
3+
2,2.000000,0.055236
4+
4,2.000000,0.040888
5+
3,2.000000,0.018460
46
3,5.000000,0.000046
5-
4,5.000000,0.000338
6-
5,5.000000,0.042282
7+
2,5.000000,0.000717
8+
1,5.000000,0.093164
9+
0,5.000000,1.000000
10+
4,5.000000,0.000338

include/CellStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class CellStorage
8484

8585
void saveFiresToJson();
8686

87+
void uploadFromTxt();
88+
8789
CellStorage* CopySquare(int xMin, int yMin, int xMax, int yMax) const;
8890

8991
};

include/Math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Math1 final : public Math
8080
{
8181
private:
8282
mutable std::unordered_map<SlopeMetaData, int> slope_counter_;
83+
mutable std::map<double, int> result_slope_;
8384
mutable std::unordered_map<SlopeMetaData, double> slope_result_;
8485
mutable std::map<double, int> result_wind_;
8586
mutable std::map<int, int> result_overall;

include/Metric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Metric
1111
Metric(const Metric& m) = default;
1212
~Metric();
1313
void calculateVariables(const CellStorage& cellStorage, std::vector<std::pair<int, int>>& realFirePoints, std::vector<std::pair<int, int>>& burntPoints);
14+
void calculateVariablesFrom2Storages(const CellStorage& cellStorage, const CellStorage& other);
1415
virtual double compute() const = 0;
1516
};
1617

include/ProfilingDecorator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ProfilingDecorator final : public Math
3838
Math *primary_class_;
3939
mutable int positive_counter_;
4040
mutable int counter_;
41+
mutable clock_t overall_timer_;
4142
mutable std::unordered_map<metaData, int> results_;
4243
mutable std::unordered_map<directions, int> results_directions_;
4344

include/Wind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ class Wind
2626
/// @return angle in degrees
2727
int angleBetweenDirections(directions d) const;
2828

29+
int directionDifference(directions d) const;
30+
2931
};

src/CellStorage.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@ void CellStorage::saveFiresToJson()
202202
// std::cout << event << std::endl;
203203
}
204204

205+
void CellStorage::uploadFromTxt()
206+
{
207+
std::ifstream txt_file{"previous.txt"};
208+
if (!txt_file.is_open()) {
209+
std::cerr << "Не удалось открыть файл с предыдущими данными" << std::endl;
210+
return;
211+
}
212+
std::string line;
213+
size_t currentLine = 0;
214+
215+
while (std::getline(txt_file, line)) {
216+
for (size_t i = 0; i < line.size(); i++)
217+
{
218+
terrain_[currentLine][i].get()->setState(static_cast<cellState>(line[i]-'0'));
219+
}
220+
currentLine++;
221+
222+
}
223+
txt_file.close();
224+
}
205225
std::vector<std::pair<int, int>> CellStorage::getRelativeFirePoints() const
206226
{
207227
// important note that result must be sorted!

src/Math.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ double Math1::calculateWindKoef(const cell *c, directions InvestigatedDirection)
3030
{
3131
return double(1);
3232
}
33-
WindMetaData meta = {abs(static_cast<int>(wind->getWindDirection()) - static_cast<int>(InvestigatedDirection)), wind->getWindSpeed()};
33+
34+
WindMetaData meta = {wind->directionDifference(InvestigatedDirection), wind->getWindSpeed()};
3435
auto a = wind_result_[meta];
3536
if (a != 0){
3637
clock_t per_iteration = clock() - start;
@@ -56,14 +57,17 @@ double Math1::calculateGroundSlopeKoef(directions InvestigatedDirection, int alt
5657

5758
SlopeMetaData meta = {bool(static_cast<int>(InvestigatedDirection) / int(2)), altitudeDifference};
5859

59-
// auto a = slope_result_[meta];
60-
// if (a != 0)
61-
// {
62-
// clock_t per_iteration = clock() - start;
63-
// slope_timer = per_iteration+slope_timer;
64-
// slope_counter++;
65-
// return a;
66-
// }
60+
auto a = slope_result_[meta];
61+
if (a != 0)
62+
{
63+
clock_t per_iteration = clock() - start;
64+
slope_timer = per_iteration+slope_timer;
65+
slope_counter++;
66+
slope_counter_[meta]++;
67+
slope_result_[meta] = a;
68+
result_slope_[a]++;
69+
return a;
70+
}
6771

6872
double coef = 0;
6973
if (InvestigatedDirection == directions::North || InvestigatedDirection == directions::West ||
@@ -133,9 +137,9 @@ bool Math1::willSpread(const cell *c, directions InvestigatedDirection, int alti
133137
double slopeKoeff = calculateGroundSlopeKoef(InvestigatedDirection, altitudeDifference);
134138
double biomassKoeff = calculateBiomassKoef(c);
135139
double moistureKoeff = calculateMoistureKoeff(c->getWind().get()->getMoistureCoeff());
136-
int result = fireKoeff * slopeKoeff * biomassKoeff * moistureKoeff * 100 - 40;
140+
int result = fireKoeff * slopeKoeff * biomassKoeff * moistureKoeff * 100 / 2;
137141
result_overall[result]++;
138-
return result + (rand() % 100) > ignitionPercentage();
142+
return result > (rand() % 100);
139143
}
140144

141145
bool Math1::willSpreadThroughOne(const cell *c, directions InvestigatedDirection, int altitudeDifference) const

src/Metric.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ void Metric::calculateVariables(const CellStorage &cellStorage, std::vector<std:
3838
d = allArea - a - b - c - d;
3939
}
4040

41+
void Metric::calculateVariablesFrom2Storages(const CellStorage &cellStorage, const CellStorage &other)
42+
{
43+
for (size_t i = 0; i < getXArea(); i++)
44+
{
45+
for (size_t j = 0; j < getYArea(); j++)
46+
{
47+
auto state = cellStorage.getState(i, j);
48+
auto other_state = other.getState(i, j);
49+
if ((state == cellState::Fire and other_state == cellState::Fire) or (state == cellState::Burnt and other_state == cellState::Burnt))
50+
{
51+
++a;
52+
}
53+
else if (state == cellState::Fire or state == cellState::Burnt)
54+
{
55+
++b;
56+
}
57+
else if (other_state == cellState::Fire or other_state == cellState::Burnt)
58+
{
59+
++c;
60+
}
61+
else
62+
{
63+
++d;
64+
}
65+
}
66+
}
67+
}
68+
4169
double SimpsonMetric::compute() const
4270
{
4371
return double(a) / double(std::min(a + b, a + c));

src/ProfilingDecorator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ ProfilingDecorator::ProfilingDecorator(Math *formula)
99

1010
bool ProfilingDecorator::willSpread(const cell *c, directions InvestigatedDirection, int altitudeDifference) const
1111
{
12+
clock_t start = clock();
13+
int direction_difference = c->getWind().get()->directionDifference(InvestigatedDirection);
14+
if (direction_difference > 1){
15+
return false;
16+
}
1217
auto result = this->primary_class_->willSpread(c, InvestigatedDirection, altitudeDifference);
18+
clock_t per_iteration = clock() - start;
19+
overall_timer_ = per_iteration+overall_timer_;
1320
metaData key = {InvestigatedDirection, altitudeDifference, c->getWind().get()->getWindDirection(), c->getWind().get()->getWindSpeed()};
1421
results_[key]++;
1522
this->counter_++;

0 commit comments

Comments
 (0)