-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIVariableTracker.h
More file actions
202 lines (149 loc) · 4.23 KB
/
IVariableTracker.h
File metadata and controls
202 lines (149 loc) · 4.23 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* IVariableTracker.h
*
* Created on: 19 Jun 2014
* Author: rusty
*/
#ifndef IVARIABLETRACKER_H_
#define IVARIABLETRACKER_H_
#include <vector>
using namespace std;
class IVariableTracker{
public:
virtual ~IVariableTracker(){}
virtual void store(int masterClock, IFunctionalResponse* response) = 0;
virtual bool save(string suffix, int simID) = 0;
virtual bool returnSeries(vector<vector <vector<double> > >& series) = 0;
};
class BiomassTracker:public IVariableTracker
{
private:
int unitCount, timestepCount;
double dt;
RM_Nsp_Parameters* parameters;
IDynamicalUnit** units;
vector <vector<vector<double> > >biomassTimeseries;
public:
~BiomassTracker(){}
BiomassTracker(int timestepCount, int unitCount, double dt, RM_Nsp_Parameters* parameters, IDynamicalUnit** units){
this->unitCount = unitCount;
this->timestepCount = timestepCount;
this-> dt = dt;
this->parameters = parameters;
this->units = units;
biomassTimeseries.resize(timestepCount+1,vector<vector <double> >(unitCount,vector<double>(unitCount,0))); // only stores Biomass flows between species which are directly interacting in the model
}
void store(int masterClock, IFunctionalResponse* response){
for (int i=0;i<unitCount;i++){
for (int j=0; j<unitCount;j++){
biomassTimeseries.at(masterClock).at(i).at(j) = response->getResponse(i,j,unitCount,parameters->couplingMatrix,units, masterClock, parameters);
}
}
}
bool save(string suffix, int simID){
stringstream ID_ss;
ID_ss << simID;
string fname = "sim"+ID_ss.str()+"_"+suffix+".biomassTimeseries";
ofstream ofile;
ofile.open(fname.c_str());
if (!ofile){return false;}
print(ofile);
ofile.close();
return true;
}
void print(ofstream& os){
for (int t=0; t<=timestepCount; t++){
os << t*dt << ", ";
for (int i=0;i<unitCount;i++){
for (int j=0; j<unitCount;j++){
os << biomassTimeseries.at(t).at(i).at(j) << ", ";
}
}
os << endl;
}
}
bool returnSeries(vector<vector <vector<double> > >& series){
try
{
series = biomassTimeseries;
}
catch(int e)
{
return false;
}
return true;
}
};
class InteractionTracker:public IVariableTracker
{
private:
int unitCount, timestepCount;
double dt;
RM_Nsp_Parameters* parameters;
IDynamicalUnit** units;
vector <vector<vector<double> > >interactionTimeseries;
public:
~InteractionTracker(){}
InteractionTracker(int timestepCount, int unitCount, double dt, RM_Nsp_Parameters* parameters, IDynamicalUnit** units){
this->unitCount = unitCount;
this->timestepCount = timestepCount;
this-> dt = dt;
this->parameters = parameters;
this->units = units;
interactionTimeseries.resize(timestepCount+1,vector<vector <double> >(unitCount,vector<double>(unitCount,0))); // only stores Biomass flows between species which are directly interacting in the model
}
void store(int masterClock, IFunctionalResponse* response){
for (int i=0;i<unitCount;i++){
for (int j=0; j<unitCount;j++){
interactionTimeseries.at(masterClock).at(i).at(j) = response->getInteractionStrength(i,j,unitCount,parameters->couplingMatrix,units, masterClock, parameters);
}
}
}
bool save(string suffix, int simID){
stringstream ID_ss;
ID_ss << simID;
string fname = "sim"+ID_ss.str()+"_"+suffix+".interactionTimeseries";
ofstream ofile;
ofile.open(fname.c_str());
if (!ofile){return false;}
print(ofile);
ofile.close();
return true;
}
void print(ofstream& os){
for (int t=0; t<=timestepCount; t++){
os << t*dt << ", ";
for (int i=0;i<unitCount;i++){
for (int j=0; j<unitCount;j++){
os << interactionTimeseries.at(t).at(i).at(j) << ", ";
}
}
os << endl;
}
}
bool returnSeries(vector<vector <vector<double> > >& series){
try
{
series = interactionTimeseries;
}
catch(int e)
{
return false;
}
return true;
}
};
class NullTracker:public IVariableTracker
{
private:
public:
~NullTracker(){}
NullTracker(){
}
void store(int masterClock, IFunctionalResponse* response){}
bool save(string suffix, int simID){return true;}
bool returnSeries(vector<vector <vector<double> > >& series){
return true;
}
};
#endif /* IVARIABLETRACKER_H_ */