-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.cpp
More file actions
71 lines (57 loc) · 1.93 KB
/
storage.cpp
File metadata and controls
71 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#include <random>
/*
PLACEHOLDER: shows how to update in place, since passing in by reference
*/
vector<vector<vector<LandCell> > > sampleNextStates(vector<vector<LandCell> >& state, double distanceConstant, int total){
vector<vector<vector<LandCell> > > futureStates;
vector<vector<double> > probabilities(state.size(), vector<double>(state[0].size()));
int observationDistance = 2;
//Goes through each point to build probability of there being a fire
for(int i = 0; i < state.size(); i++){
for(int j = 0; j < state[0].size(); j++){
if(!state[i][j].fire && state[i][j].fuel > 0){
double prob = 1;
for(int nI = max(0, i - observationDistance); nI < min(int(state.size()), i + observationDistance); nI++){
for(int nJ = max(0, j - observationDistance); nJ < min(int(state.size()), j + observationDistance); nJ++){
if(i != nI && j != nJ){
prob *= 1 - (pow(1.0 / calculateDistance(i, j, nI, nJ) / distanceConstant, 2) * (state[nI][nJ].fire ? 1 : 0));
}
}
}
prob = 1 - prob;
probabilities[i][j] = prob;
}
else
probabilities[i][j] = 0;
}
}
//Builds a future sample for each
for(int t = 0; t < total; t++){
futureStates.push_back(vector<vector<LandCell> >(state.size(), vector<LandCell>(state[0].size())));
// Uses Bernoulli distribution in order to model if a fire exists or doesn't exist at a certain place
for(int i = 0; i < state.size(); i++){
for(int j = 0; j < state[0].size(); j++){
futureStates[futureStates.size() - 1][i][j] = state[i][j];
if(!state[i][j].fire){
bernoulli_distribution b(probabilities[i][j]);
futureStates[futureStates.size() - 1][i][j].fire = b(gen);
}
}
}
}
for(int i = 0 ; i < total; i++){
printData(futureStates[i]);
cout << endl;
}
exit(0);
return futureStates;
}
int main(){
}