-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulationFuncs.h
227 lines (191 loc) · 5.11 KB
/
SimulationFuncs.h
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
#ifndef SIMULATION_H_INCLUDED
#define SIMULATION_H_INCLUDED
#include "RandomFuncs.h"
#include "MidgeLifeAndDiffusion.h"
#include "SetupFuncs.h"
#include "TransportRisk.h"
#include "const_parameters.h"
#include "Declarations.h"
#include "controls.h"
//Functions that do simulation and reading out of simulation results
//~ double NumOfInfCattle(){
//~ sum = 0;
//~ for(int k = 0;k<N;k++){
//~ }
//~ }
void SpatialAutoCorrOnDay(){
double ACGrid[NumGridPointsACS][NumGridPointsACE];
for(int i =0 ; i<NumGridPointsACS ; i++){
for(int j =0 ; j<NumGridPointsACE ; j++){
ACGrid[i][j] = 0.7540*RandN(RandGenerator);
}
}
}
void ReadInAllData(){
ReadInTempData();
ReadInRainData();
ReadInCovarianceMatrix();
ReadInLHSamples();
ConstructFarmPopulation();
ReadInFarmData();
ReadInMovementData();
}
void ResetEpidemic(const gsl_rng * r,int RN){
std::cout<<"Reseting epidemic"<<std::endl;
ResetFarms();
ResetMidgeGrid();
#ifdef GENERATEPARAMETERSRANDOMLY
DrawParamsFromPrior(r);
#endif
#ifdef USEDEFINEDPARAMETERS
DrawParamsFromLHSamples(RN);
#endif
SolveFarmBitingPreference(PreferenceForSheep,AttractPowScaler);
SimulationDay = StartDayOfYear;
InterruptedMovements = 0;
DaysOfMovementBan = 0;
TotalFarmDaysMovementBanned = 0;
TotalFarmDaysAffectedByControl = 0;
NumOfSheepDeaths = 0;
NumberOfFarmsChecked= 0;
NumberOfTests = 0;
NumberOfPosTests = 0;
NumOfSheepDeaths = 0;
NumberOfMovementTransmission = 0;
NumberOfRiskyMovesBlocked = 0;
BTVObserved = false;
ActiveSurveillancePerformed = false;
RestrictionZonesImplemented = false;
InitialiseEpidemicAtCounty();
}
void SimulateEpidemicForOneDay(const gsl_rng * r){
#ifdef DAILYREADOUT
std::cout<<"Simulating day "<<SimulationDay<<std::endl;
#endif
//Check if global control measure are to be implemented
if(BTVObserved && !RestrictionZonesImplemented){
SetUpRestrictionZone(FirstDetectedFarmID, PZRadius, SZRadius);
if(!ActiveSurveillancePerformed)
{
PerformActiveSurveillance();
}
}
MidgeMortalityAndIncubation();
MovementTransmission();
MidgeDiffusionForADay();
SpatialAutoCorrOnDay();
for(int k = 0;k<N;k++){
farms[k]->GetWeatherToday();
farms[k]->AnimalDeathsAndRecoveries(r);
farms[k]->TransmissionMidgesToHosts(r);
farms[k]->TransmissionHostsToMidges();
}
SimulationDay++;
}
void DefineOutputFileName(char** file_end){
ss.clear();
ss.str("");
bool NormalOutput = true;
#ifdef USEDEFINEDPARAMETERS
ss<<"./DATA/LHS_Results_L_"<<DiffusionLengthScale<<"_BR_"<<BanRadius<<"_init_CN_"<<OutbreakCounty<<"_end_day_"<<NumDays<<"_PZ_"<<PZRadius<<"_SZ_"<< SZRadius<<"_"<<file_end[1]<<".txt";
ss>> OutputFilename;
#endif
#ifdef GENERATEPARAMETERSRANDOMLY
ss<<"./DATA/RAND_Results_L_"<<DiffusionLengthScale<<"_BR_"<<BanRadius<<"_init_CN_"<<OutbreakCounty<<"_end_day_"<<NumDays<<"_PZ_"<<PZRadius<<"_SZ_"<< SZRadius<<"_"<<file_end[1]<<".txt";
ss>> OutputFilename;
#endif
}
void PrintSpatialEpidemicOutToFile(){
char buffer[100];
std::stringstream filenamess;
filenamess.clear();
filenamess.str("");
filenamess<<"./IMAGE/AffectedFarmsImageDay_"<<SimulationDay<<".txt";
filenamess>>buffer;
std::ofstream out(buffer);
for(int i = 0; i<N;i++){
if(farms[i]->NumOfInfCattle() + farms[i]->NumOfInfSheep() + farms[i]->R_cattle + farms[i]->R_sheep > 0){
out<<farms[i]->x[0]<<", "<<farms[i]->x[1]<<", "<<farms[i]->S_cattle<<", "<<farms[i]->NumOfInfCattle()<<", "<<farms[i]->R_cattle<<", "<<farms[i]->S_sheep<<", "<<farms[i]->NumOfInfSheep()<<", "<<farms[i]->R_sheep<<std::endl;
}
}
out.close();
}
//Functions for reading out the state of the system
double TotalNumberOfSusCattle(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->S_cattle;
}
return sum;
}
double TotalNumberOfInfCattle(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->NumOfInfCattle();
}
return sum;
}
double TotalNumberOfRecCattle(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->R_cattle;
}
return sum;
}
double TotalNumberOfSusSheep(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->S_sheep;
}
return sum;
}
double TotalNumberOfInfSheep(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->NumOfInfSheep();
}
return sum;
}
double TotalNumberOfRecSheep(){
double sum = 0;
for(int k = 0;k<N;k++){
sum += farms[k]->R_sheep;
}
return sum;
}
double TotalNumberOfMovementBannedFarms(){
double sum = 0;
for(int k = 0;k<N;k++){
if(farms[k]->MovementBanned){sum = sum+1;}
}
return sum;
}
double TotalNumberOfPZFarms(){
double sum = 0;
for(int k = 0;k<N;k++){
if(farms[k]->ProtectionZone){sum = sum+1;}
}
return sum;
}
double TotalNumberOfSZFarms(){
double sum = 0;
for(int k = 0;k<N;k++){
if(farms[k]->SurveillanceZone){sum = sum+1;}
}
return sum;
}
double TotalNumberOfInfectedFarms(){
double sum = 0;
for(int k = 0;k<N;k++){
if(farms[k]->NumOfInfCattle() + farms[k]->NumOfInfSheep() > 0){sum = sum+1;}
}
return sum;
}
double TotalNumberOfAffectedFarms(){
double sum = 0;
for(int k = 0;k<N;k++){
if(farms[k]->NumOfInfCattle() + farms[k]->NumOfInfSheep() + farms[k]->R_cattle + farms[k]->R_sheep > 0){sum = sum+1;}
}
return sum;
}
#endif