-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWormAgent.cpp
237 lines (190 loc) · 4.42 KB
/
WormAgent.cpp
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* WormAgent.cpp
*/
#include "WormAgent.h"
#include "random.h"
// ****************************
// Constructors and Destructors
// ****************************
// The constructor
WormAgent::WormAgent(int entero)
{
InitialiseSensors();
}
// The destructor
WormAgent::~WormAgent()
{
InitialiseSensors();
}
// *********
// Setting paremeters
// *********
void WormAgent::SetParameters(TVector<double> &v)
{
alpha = v(1);
K_hill = v(2);
delta = v(3);
delta_PKG = v(4);
gamma = v(5);
beta = v(6);
delta_ca = v(7);
b = v(8);
beta_DAG = v(9);
delta_DAG = v(10);
alpha_glu = v(11);
alpha_delta = v(12);
theta = v(13);
tau = v(14);
inhWeight = v(15);
b_inh = v(16);
theta_inh = v(17);
excWeight = v(18);
b_exc = v(19);
theta_exc = v(20);
omega_low = v(21);
omega_high = v(22);
V_low = v(23);
alpha_glu_low = v(24);
C_breed = v(25);
}
// *******
// Initialising
// *******
void WormAgent::InitialiseSensors(){
cGMP = 0.0;
PKG = 0.0;
Ca = 0.0;
DAG = 0.0;
AIB = 0.0;
chemConHistory.SetBounds(1, len_chem);
}
void WormAgent::InitialiseSensorHistory()
{
timer = 0;
for (int i = timer; i < (int)(0.5*RunDuration/StepSize); i++)
chemConHistory[i] = C_breed;
for (int i = (int)(0.5*RunDuration/StepSize); i < (int)(RunDuration/StepSize); i++)
chemConHistory[i] = C_back;
}
// *******
// Resetting
// *******
void WormAgent::ResetAgentsBody(RandomState &rs)
{
double tempangle = rs.UniformRandom(0,2*Pi);
#ifdef GRAD_CONE
distanceToCentre = 0.0;
#endif
#ifdef GRAD_INVCONE
distanceToCentre = 0.0;
#endif
#ifdef GRAD_GAUS
distanceToCentre = 0.0;
#endif
#ifdef GRAD_STEP
distanceToCentre = 0.0;
#endif
px = cos(tempangle)*distanceToCentre;
py = sin(tempangle)*distanceToCentre;
vx = 0.0;
vy = 0.0;
cGMP = 0.0;
PKG = 0.0;
Ca = 0.0;
DAG = 0.0;
AIB = 0.0;
orient = rs.UniformRandom(0,2*Pi);
}
// *******
// Updating
// *******
void WormAgent::UpdateChemCon( RandomState &rs )
{
distanceToPeak = sqrt( pow((px-pos_x_peak),2) + pow((py-pos_y_peak),2) );
distanceToMin = sqrt( pow((px-pos_x_peak_min),2) + pow((py-pos_y_peak),2) );
#ifdef GRAD_CONE
chemCon = -distanceToPeak*gradSteepness;
#endif
#ifdef GRAD_INVCONE
chemCon = distanceToPeak*gradSteepness;
#endif
#ifdef GRAD_GAUS
chemCon = C_max*exp(-(pow(distanceToPeak,2))/ChemDiffConst) +C_back -C_min*exp(-(pow(distanceToMin,2))/ChemDiffConst);
#endif
#ifdef GRAD_ISO
chemCon = - (fabs((distanceToPeak - MaxDist)*gradSteepness));
#endif
#ifdef GRAD_STEP
chemCon = chemConHistory[timer];
timer++;
#endif
}
void WormAgent::UpdateChemConstante( RandomState &rs )
{
chemCon = C_breed;
}
void WormAgent::UpdateSensors(double stepsize)
{
der_cGMP = alpha*hill_repressor(chemCon, K_hill) - delta*cGMP;
der_PKG = gamma*cGMP - delta_PKG*PKG;
I_se = cGMP - PKG;
der_Ca = beta*tanh(I_se, b) - delta_ca*Ca;
der_DAG = beta_DAG*Ca - delta_DAG*DAG;
if (DAG>=theta){
glu_basal = alpha_glu_low + alpha_glu;
}
else{
glu_basal = alpha_glu_low;
}
der_AIB = (inhWeight*(-sig(b_inh*(glu_basal + alpha_delta*Ca) + theta_inh) + 1) + excWeight*sig(b_exc*(glu_basal + alpha_delta*Ca) + theta_exc) - AIB)/tau;
cGMP += stepsize * der_cGMP;
PKG += stepsize * der_PKG;
Ca += stepsize * der_Ca;
DAG += stepsize * der_DAG;
AIB += stepsize * der_AIB;
}
void WormAgent::PrintDetail( ofstream &file, double timestep)
{
file << timestep-Preexposure << " ";
file << chemCon << " ";
file << cGMP << " ";
file << PKG << " ";
file << Ca << " ";
file << DAG << " ";
file << (AIB-1.1)/0.02 << " ";
file << glu_basal << " ";
file << proba_final << " ";
file << px << " ";
file << py << " ";
file << endl;
}
// Step the bacteria simulation
void WormAgent::Step(double StepSize, RandomState &rs, double timestep)
{
if (AIB<=V_low){
proba_completa = StepSize*omega_low;
}
else {
proba_completa = StepSize*omega_high;
}
proba_final = proba_completa;
if (rs.UniformRandom(0.0, 1.0) < proba_final){
SetOrientation(rs.UniformRandom(0, 2*Pi));
}
// Update the velocity
vx = cos(orient) * MaxVel; //MaxVel
vy = sin(orient) * MaxVel; //MaxVel
// Move the agent
px += StepSize * vx;
py += StepSize * vy;
if ( (pow(px,2) + pow(py,2)) > pow(MaxDist,2)){
while ((pow(px,2) + pow(py,2)) > pow(MaxDist,2)) {
SetOrientation(rs.UniformRandom(0, 2*Pi));;
vx = cos(orient) * MaxVel; //MaxVel
vy = sin(orient) * MaxVel; //MaxVel
// Move the agent
px += StepSize * vx;
py += StepSize * vy;
}
}
}