-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombo.cpp
More file actions
86 lines (80 loc) · 1.96 KB
/
combo.cpp
File metadata and controls
86 lines (80 loc) · 1.96 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <vector>
#include <set>
#include <iostream>
#include <random>
namespace combo
{
using namespace std;
// Normal distribution -> "https://stackoverflow.com/a/13445752"
float randomf()
{
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(20,180);
return (float) ((float)dist(rng))/100.0;
}
void addCheck(const vector<vector<float>> &matrix, set<pair<int,int>> &checked, float &bag, const int i, const int j, const int nil) //ignore mess
{
if(checked.insert({i, j}).second)
{
bag += matrix[i][j];
//cout << "added " << i << " " << j << endl;
}
else
{
//cout << "out of bounds, so adding nil" << endl;
bag += nil;
}
}
//1to1 modified discrete convolution
vector<vector<float>> d_convolve(vector<vector<float>> matrix, float nil, const float airTemp, const float airTransfer)
{
vector<vector<float>> r = matrix;
int side = matrix.size();
for(int i = 0; i < side; ++i)
{
for(int j = 0; j < side; ++j) //overflows on all sides
{
set<pair<int,int>> checked;
float avg = 0;
addCheck(matrix, checked, avg, i, j, nil);
bool w,a,s,d;
w = i!=0; a = j!=0; s = i!=side-1; d = j!=side-1;
vector<pair<int,int>> combination = {{i-w,j-a},{i-w,j+d},{i-w,j},{i,j-a},{i,j+d},{i+s,j-a},{i+s,j+d},{i+s,j}};
for(auto c : combination)
{
addCheck(matrix, checked, avg, c.first, c.second, nil);
}
avg /= 9;
r[i][j] = avg - (avg-airTemp)*airTransfer*randomf(); //MODLINE
}
}
return r;
}
void print(const vector<vector<float>> &matrix)
{
for(auto i : matrix)
{
for(auto j : i)
{
cout << j << " ";
}
cout << endl;
}
cout << endl;
}
void log(const vector<vector<float>> &matrix, string &timeLog)
{
timeLog += "$map1 << EOD\n";
for(auto i : matrix)
{
for(auto j : i)
{
timeLog += to_string(j)+" ";
}
timeLog += "\n";
}
timeLog += "EOD\n";
timeLog += "plot $map1 matrix with image\n";
}
};