forked from mrc-ide/covid-sim
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CovidSim.cpp
5479 lines (5100 loc) · 286 KB
/
CovidSim.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
(c) 2004-20 Neil Ferguson, Imperial College London ([email protected])
*/
#include <errno.h>
#include <stddef.h>
#include <string>
#include <iostream>
#include <thread> // only for std::thread::hardware_concurrency()
#include <any>
#include <boost/program_options.hpp>
// #include "CovidSim.h"
// #include "binio.h"
// #include "Rand.h"
// #include "Error.h"
// #include "Dist.h"
// #include "Kernels.h"
// #include "Bitmap.h"
// #include "Model.h"
#include "Parameters.h"
#include "ParametersReader.h"
// #include "SetupModel.h"
// #include "SharedFuncs.h"
// #include "ModelMacros.h"
// #include "InfStat.h"
// #include "CalcInfSusc.h"
// #include "Update.h"
// #ifdef _OPENMP
#include <omp.h>
// #endif // _OPENMP
//************************************************************ To move somewhere else
/*
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b)) // already implemented in std
#endif
void ReadParams(char*, char*);
void ReadInterventions(char*);
int GetXMLNode(FILE*, const char*, const char*, char*, int);
void ReadAirTravel(char*);
void InitModel(int); //adding run number as a parameter for event log: ggilani - 15/10/2014
void SeedInfection(double, int*, int, int); //adding run number as a parameter for event log: ggilani - 15/10/2014
int RunModel(int); //adding run number as a parameter for event log: ggilani - 15/10/2014
void TravelReturnSweep(double);
void TravelDepartSweep(double);
void InfectSweep(double, int); //added int as argument to InfectSweep to record run number: ggilani - 15/10/14
void IncubRecoverySweep(double, int); //added int as argument to record run number: ggilani - 15/10/14
int TreatSweep(double);
//void HospitalSweep(double); //added hospital sweep function: ggilani - 10/11/14
void DigitalContactTracingSweep(double); // added function to update contact tracing number
void SaveDistribs(void);
void SaveOriginDestMatrix(void); //added function to save origin destination matrix so it can be done separately to the main results: ggilani - 13/02/15
void SaveResults(void);
void SaveSummaryResults(void);
void SaveRandomSeeds(void); //added this function to save random seeds for each run: ggilani - 09/03/17
void SaveEvents(void); //added this function to save infection events from all realisations: ggilani - 15/10/14
void LoadSnapshot(void);
void SaveSnapshot(void);
void RecordInfTypes(void);
void RecordSample(double, int);
void CalcOriginDestMatrix_adunit(void); //added function to calculate origin destination matrix: ggilani 28/01/15
int GetInputParameter(FILE*, FILE*, const char*, const char*, void*, int, int, int);
int GetInputParameter2(FILE*, FILE*, const char*, const char*, void*, int, int, int);
int GetInputParameter3(FILE*, const char*, const char*, void*, int, int, int);
///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** /////
///// ***** ///// ***** ///// ***** ///// ***** ///// ***** GLOBAL VARIABLES (some structures in CovidSim.h file and some containers) - memory allocated later.
///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** /////
param P;
person* Hosts;
household* Households;
popvar State, StateT[MAX_NUM_THREADS];
cell* Cells; // Cells[i] is the i'th cell
cell ** CellLookup; // CellLookup[i] is a pointer to the i'th populated cell
microcell* Mcells, ** McellLookup;
place** Places;
adminunit AdUnits[MAX_ADUNITS];
//// Time Series defs:
//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every quantity in results. Mostly used in RecordSample.
//// TSMeanNE and TSVarNE are the mean and variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct time series. TSMean and TSVar are pointers that point to either extinct or non-extinct.
results* TimeSeries, * TSMean, * TSVar, * TSMeanNE, * TSVarNE, * TSMeanE, * TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar
airport* Airports;
bitmap_header* bmh;
//added declaration of pointer to events log: ggilani - 10/10/2014
events* InfEventLog;
int* nEvents;
double inftype[INFECT_TYPE_MASK], inftype_av[INFECT_TYPE_MASK], infcountry[MAX_COUNTRIES], infcountry_av[MAX_COUNTRIES], infcountry_num[MAX_COUNTRIES];
double indivR0[MAX_SEC_REC][MAX_GEN_REC], indivR0_av[MAX_SEC_REC][MAX_GEN_REC];
double inf_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], denom_household[MAX_HOUSEHOLD_SIZE + 1];
double inf_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], AgeDist[NUM_AGE_GROUPS], AgeDist2[NUM_AGE_GROUPS];
double case_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], case_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1];
double PropPlaces[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES];
double PropPlacesC[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES], AirTravelDist[MAX_DIST];
double PeakHeightSum, PeakHeightSS, PeakTimeSum, PeakTimeSS;
// These allow up to about 2 billion people per pixel, which should be ample.
int32_t *bmPopulation; // The population in each bitmap pixel. Special value -1 means "country boundary"
int32_t *bmInfected; // The number of infected people in each bitmap pixel.
int32_t *bmRecovered; // The number of recovered people in each bitmap pixel.
int32_t *bmTreated; // The number of treated people in each bitmap pixel.
char OutFile[1024], OutFileBase[1024], OutDensFile[1024], SnapshotLoadFile[1024], SnapshotSaveFile[1024], AdunitFile[1024];
int ns, DoInitUpdateProbs, InterruptRun = 0;
int PlaceDistDistrib[NUM_PLACE_TYPES][MAX_DIST], PlaceSizeDistrib[NUM_PLACE_TYPES][MAX_PLACE_SIZE];
/* int NumPC,NumPCD; */
#define MAXINTFILE 10
//***************************************************************************** End - To move somewhere else
namespace po = boost::program_options;
int main(int argc, char* argv[])
{
po::options_description options{"Executable options"};
options.add_options()("nThread", po::value<int>()->default_value(1), "The number of parallel threads to use");
options.add_options()("adminF", po::value<std::string>(), "--adminFile Description--");
options.add_options()("preParamF", po::value<std::string>(), "--PreParamFile Description--");
options.add_options()("paramF", po::value<std::string>(), "--ParamFile Description-- Mandatory");
options.add_options()("popDensityF", po::value<std::string>(), "--DensityFile Description--");
options.add_options()("networkLoad", po::value<std::string>(), "--NetworkFile Load Description-- Cannot be used in combination with Network Save");
options.add_options()("networkSave", po::value<std::string>(), "--NetworkFile Save Description-- Cannot be used in combination with Network Load");
options.add_options()("airTravelF", po::value<std::string>(), "--AirTravelFile Description--");
options.add_options()("schoolF", po::value<std::string>(), "--SchoolFile Description--");
options.add_options()("regDemogF", po::value<std::string>(), "--RegDemogFile Description--");
options.add_options()("interventionFiles", po::value<std::vector<std::string>>()->multitoken() , "--InterventionFiles Description--");
options.add_options()("outputPrefix", po::value<std::string>(), "--Output Prefix Description-- Mandatory");
options.add_options()("setupSeed1", po::value<long int>()->default_value(42), "Setup random seed 1");
options.add_options()("setupSeed2", po::value<long int>()->default_value(42), "Setup random seed 2");
options.add_options()("runSeed1", po::value<long int>()->default_value(42), "Run random seed 1");
options.add_options()("runSeed2", po::value<long int>()->default_value(42), "Run random seed 2");
options.add_options()("r0Scale", po::value<float>()->default_value(1.5), "R0 Scaling");
po::variables_map varMap;
po::store(po::parse_command_line(argc, argv, options), varMap);
po::notify(varMap);
if(varMap.count("help"))
{
std::cout << options << std::endl;
return 1;
}
else if(varMap["outputPrefix"].empty())
{
std::cout << "Missing output files prefix, aborting" << std::endl;
return 1;
}
else if(varMap["paramF"].empty())
{
std::cout << "Missing the input parameter file, aborting" << std::endl;
return 1;
}
else if(!varMap["networkLoad"].empty() && !varMap["networkSave"].empty())
{
std::cout << "Cannot load and save a network at the same time, aborting" << std::endl;
return 1;
}
else if(varMap["adminF"].empty())
{
std::cout << "Missing the Admin Param File, aborting" << std::endl;
return 1;
}
else if(varMap["preParamF"].empty())
{
std::cout << "Missing the Pre-Param File, aborting" << std::endl;
return 1;
}
std::vector<std::string> interventionFiles;
if(varMap.count("interventionFiles") > 0)
{
interventionFiles = varMap["interventionFiles"].as<std::vector<std::string>>();
}
//Taking up space here to clearly show every parameter entry in the trolley
ParametersSP runParametersTrolley(new Parameters());
//Mandatory params ?
runParametersTrolley->SetValue("AdminParamFile", varMap["adminF"].as<std::string>());
runParametersTrolley->SetValue("ParamFile", varMap["paramF"].as<std::string>());
runParametersTrolley->SetValue("PreParamFile", varMap["preParamF"].as<std::string>());
runParametersTrolley->SetValue("OutputPrefix", varMap["outputPrefix"].as<std::string>());
//Optionnal params?
// Consider doing something like this eventually
// std::vector<std::string> optionsKeys = {"nThread", "popDensityF", "networkLoad", "networkSave", "setupSeed1", "setupSeed2", "runSeed1", "runSeed2"};
// std::vector<std::string> trolleyKeys = {"NThread", "PopDensityFile", "NetworkFileLoad", "NetworkFileSave", "SetupSeed1", "SetupSeed2", "RunSeed1", "RunSeed2"};
// std::vector<std::any> defaultValues = {1, "", "", }
runParametersTrolley->SetValue("NThread", varMap["nThread"].as<int>());
runParametersTrolley->SetValue("SetupSeed1", varMap["setupSeed1"].as<long int>());
runParametersTrolley->SetValue("SetupSeed2", varMap["setupSeed2"].as<long int>());
runParametersTrolley->SetValue("RunSeed1", varMap["runSeed1"].as<long int>());
runParametersTrolley->SetValue("RunSeed2", varMap["runSeed2"].as<long int>());
if(!varMap["popDensityF"].empty())
{
runParametersTrolley->SetValue("PopDensityFile", varMap["popDensityF"].as<std::string>());
runParametersTrolley->ModifyValue("DoHeteroDensity", 1);
runParametersTrolley->ModifyValue("DoPeriodicBoundaries", 0);
}
if(!varMap["networkLoad"].empty())
{
runParametersTrolley->SetValue("NetworkFileLoad", varMap["networkLoad"].as<std::string>());
runParametersTrolley->ModifyValue("LoadSaveNetwork", 1);
}
else if(!varMap["networkSave"].empty())
{
runParametersTrolley->SetValue("NetworkFileSave", varMap["networkSave"].as<std::string>());
runParametersTrolley->ModifyValue("LoadSaveNetwork", 2);
}
if(!varMap["r0Scale"].empty())
{
runParametersTrolley->ModifyValue("R0Scale", varMap["r0Scale"].as<float>());
}
else
{
runParametersTrolley->ModifyValue("R0Scale", 1.5f);
}
// else if (argv[i][1] == 'R' && argv[i][2] == ':')
// {
// sscanf(&argv[i][3], "%lf", &P.R0scale);
// }
// else if (argv[i][1] == 'K' && argv[i][2] == 'P' && argv[i][3] == ':') //added Kernel Power and Offset scaling so that it can easily be altered from the command line in order to vary the kernel quickly: ggilani - 15/10/14
// {
// sscanf(&argv[i][4], "%lf", &P.KernelPowerScale);
// }
// else if (argv[i][1] == 'K' && argv[i][2] == 'O' && argv[i][3] == ':')
// {
// sscanf(&argv[i][4], "%lf", &P.KernelOffsetScale);
// }
// else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '1' && argv[i][5] == ':') // generic command line specified param - matched to #1 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP1);
// }
// else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '2' && argv[i][5] == ':') // generic command line specified param - matched to #2 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP2);
// }
// else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '3' && argv[i][5] == ':') // generic command line specified param - matched to #3 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP3);
// }
// else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '4' && argv[i][5] == ':') // generic command line specified param - matched to #4 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP4);
// }
// else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '5' && argv[i][5] == ':') // generic command line specified param - matched to #5 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP5);
// }
// else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '6' && argv[i][5] == ':') // generic command line specified param - matched to #6 in param file
// {
// sscanf(&argv[i][6], "%lf", &P.clP6);
// }
// else if (argv[i][1] == 'A' && argv[i][2] == 'P' && argv[i][3] == ':')
// {
// GotAP = 1;
// sscanf(&argv[i][3], "%s", AirTravelFile);
// }
// else if (argv[i][1] == 's' && argv[i][2] == ':')
// {
// GotScF = 1;
// sscanf(&argv[i][3], "%s", SchoolFile);
// }
// else if (argv[i][1] == 'T' && argv[i][2] == ':')
// {
// sscanf(&argv[i][3], "%i", &P.PreControlClusterIdCaseThreshold);
// }
// else if (argv[i][1] == 'C' && argv[i][2] == ':')
// {
// sscanf(&argv[i][3], "%i", &P.PlaceCloseIndepThresh);
// }
// else if (argv[i][1] == 'd' && argv[i][2] == ':')
// {
// P.DoAdunitDemog = 1;
// sscanf(&argv[i][3], "%s", RegDemogFile);
// }
// else if (argv[i][1] == 'c' && argv[i][2] == ':')
// {
// sscanf(&argv[i][3], "%i", &P.MaxNumThreads);
// }
// else if (argv[i][1] == 'M' && argv[i][2] == ':')
// {
// P.OutputDensFile = 1;
// sscanf(&argv[i][3], "%s", OutDensFile);
// }
// else if (argv[i][1] == 'I' && argv[i][2] == ':')
// {
// sscanf(&argv[i][3], "%s", InterventionFile[P.DoInterventionFile]);
// P.DoInterventionFile++;
// }
// else if (argv[i][1] == 'L' && argv[i][2] == 'S' && argv[i][3] == ':')
// {
// sscanf(&argv[i][4], "%s", SnapshotLoadFile);
// P.DoLoadSnapshot = 1;
// }
// else if (argv[i][1] == 'P' && argv[i][2] == 'P' && argv[i][3] == ':')
// {
// sscanf(&argv[i][4], "%s", PreParamFile);
// GotPP = 1;
// }
// else if (argv[i][1] == 'S' && argv[i][2] == 'S' && argv[i][3] == ':')
// {
// sscanf(&argv[i][4], "%s", buf);
// fprintf(stderr, "### %s\n", buf);
// sep = strchr(buf, ',');
// if (!sep)
// Perr = 1;
// else
// {
// P.DoSaveSnapshot = 1;
// *sep = ' ';
// sscanf(buf, "%lf %s", &(P.SnapshotSaveTime), SnapshotSaveFile);
// }
// }
// }
// if (((GotS) && (GotL)) || (!GotP) || (!GotO)) Perr = 1;
// }
///// END Read in command line arguments
// sprintf(OutFile, "%s", OutFileBase);
// fprintf(stderr, "Param=%s\nOut=%s\nDens=%s\n", ParamFile, OutFile, DensityFile);
std::cout << "Param=" << std::any_cast<std::string>(runParametersTrolley->GetValue("ParamFile")) << std::endl;
std::cout << "Out=" << std::any_cast<std::string>(runParametersTrolley->GetValue("OutputPrefix")) << std::endl;
std::cout << "Dens=" << std::any_cast<std::string>(runParametersTrolley->GetValue("PopDensityFile")) << std::endl;
// if (Perr) ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile [/AP:AirTravelFile] [/s:SchoolFile] [/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] [/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", argv[0]);
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
//// **** SET UP OMP / THREADS
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
// #ifdef _OPENMP
// P.NumThreads = omp_get_max_threads();
// if ((P.MaxNumThreads > 0) && (P.MaxNumThreads < P.NumThreads)) P.NumThreads = P.MaxNumThreads;
// if (P.NumThreads > MAX_NUM_THREADS)
// {
// fprintf(stderr, "Assigned number of threads (%d) > MAX_NUM_THREADS (%d)\n", P.NumThreads, MAX_NUM_THREADS);
// P.NumThreads = MAX_NUM_THREADS;
// }
std::cout << "Using " << std::any_cast<int>(runParametersTrolley->GetValue("NThread")) << " threads" << std::endl;
omp_set_num_threads(std::any_cast<int>(runParametersTrolley->GetValue("NThread")));
#pragma omp parallel default(shared)
{
fprintf(stderr, "Thread %i initialised\n", omp_get_thread_num());
}
/* fprintf(stderr,"int=%i\tfloat=%i\tdouble=%i\tint *=%i\n",(int) sizeof(int),(int) sizeof(float),(int) sizeof(double),(int) sizeof(int *));
#else
P.NumThreads = 1;
#endif
if (!GotPP)
{
sprintf(PreParamFile, ".." DIRECTORY_SEPARATOR "Pre_%s", ParamFile);
}
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
//// **** READ IN PARAMETERS, DATA ETC.
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
*/
ParametersReader::ReadInputParameters(runParametersTrolley);}
// if (GotScF) P.DoSchoolFile = 1;
// if (P.DoAirports)
// {
// if (!GotAP) ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile /AP:AirTravelFile [/s:SchoolFile] [/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] [/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", argv[0]);
// ReadAirTravel(AirTravelFile);
// }
/*
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
//// **** INITIALIZE
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
///// initialize model (for all realisations).
SetupModel(DensityFile, NetworkFile, SchoolFile, RegDemogFile);
for (i = 0; i < MAX_ADUNITS; i++) AdUnits[i].NI = 0;
if (P.DoInterventionFile > 0)
for (i = 0; i < P.DoInterventionFile; i++)
ReadInterventions(InterventionFile[i]);
fprintf(stderr, "Model setup in %lf seconds\n", ((double)(clock() - cl)) / CLOCKS_PER_SEC);
//print out number of calls to random number generator
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
//// **** RUN MODEL
//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// ****
P.NRactE = P.NRactNE = 0;
for (i = 0; (i < P.NumRealisations) && (P.NRactNE < P.NumNonExtinctRealisations) && (!InterruptRun); i++)
{
if (P.NumRealisations > 1)
{
sprintf(OutFile, "%s.%i", OutFileBase, i);
fprintf(stderr, "Realisation %i (time=%lf nr_ne=%i)\n", i + 1, ((double)(clock() - cl)) / CLOCKS_PER_SEC, P.NRactNE);
}
///// Set and save seeds
if (i == 0 || (P.ResetSeeds && P.KeepSameSeeds))
{
P.nextRunSeed1 = P.runSeed1;
P.nextRunSeed2 = P.runSeed2;
}
if (P.ResetSeeds) {
//save these seeds to file
SaveRandomSeeds();
}
// Now that we have set P.nextRunSeed* ready for the run, we need to save the values in case
// we need to reinitialise the RNG after the run is interrupted.
long thisRunSeed1 = P.nextRunSeed1;
long thisRunSeed2 = P.nextRunSeed2;
if (i == 0 || P.ResetSeeds) {
setall(&P.nextRunSeed1, &P.nextRunSeed2);
//fprintf(stderr, "%i, %i\n", P.newseed1,P.newseed2);
//fprintf(stderr, "%f\n", ranf());
}
///// initialize model (for this realisation).
InitModel(i); //passing run number into RunModel so we can save run number in the infection event log: ggilani - 15/10/2014
if (P.DoLoadSnapshot) LoadSnapshot();
while (RunModel(i))
{ // has been interrupted to reset holiday time. Note that this currently only happens in the first run, regardless of how many realisations are being run.
long tmp1 = thisRunSeed1;
long tmp2 = thisRunSeed2;
setall(&tmp1, &tmp2); // reset random number seeds to generate same run again after calibration.
InitModel(i);
}
if (P.OutputNonSummaryResults)
{
if (((!TimeSeries[P.NumSamples - 1].extinct) || (!P.OutputOnlyNonExtinct)) && (P.OutputEveryRealisation))
{
SaveResults();
}
}
if ((P.DoRecordInfEvents) && (P.RecordInfEventsPerRun == 1))
{
SaveEvents();
}
}
sprintf(OutFile, "%s", OutFileBase);
//Calculate origin destination matrix if needed
if ((P.DoAdUnits) && (P.DoOriginDestinationMatrix))
{
CalcOriginDestMatrix_adunit();
SaveOriginDestMatrix();
}
P.NRactual = P.NRactNE;
TSMean = TSMeanNE; TSVar = TSVarNE;
if ((P.DoRecordInfEvents) && (P.RecordInfEventsPerRun == 0))
{
SaveEvents();
}
sprintf(OutFile, "%s.avNE", OutFileBase);
SaveSummaryResults();
P.NRactual = P.NRactE;
TSMean = TSMeanE; TSVar = TSVarE;
sprintf(OutFile, "%s.avE", OutFileBase);
//SaveSummaryResults();
#ifdef WIN32_BM
Gdiplus::GdiplusShutdown(m_gdiplusToken);
#endif
fprintf(stderr, "Extinction in %i out of %i runs\n", P.NRactE, P.NRactNE + P.NRactE);
fprintf(stderr, "Model ran in %lf seconds\n", ((double)(clock() - cl)) / CLOCKS_PER_SEC);
fprintf(stderr, "Model finished\n");
}
void ReadParams(char* ParamFile, char* PreParamFile)
{
FILE* ParamFile_dat, * PreParamFile_dat, *AdminFile_dat;
double s, t, AgeSuscScale;
int i, j, k, f, nc, na;
char CountryNameBuf[128 * MAX_COUNTRIES], AdunitListNamesBuf[128 * MAX_ADUNITS];
char* CountryNames[MAX_COUNTRIES];
for (i = 0; i < MAX_COUNTRIES; i++) { CountryNames[i] = CountryNameBuf + 128 * i; CountryNames[i][0] = 0; }
char* AdunitListNames[MAX_ADUNITS];
for (i = 0; i < MAX_ADUNITS; i++) { AdunitListNames[i] = AdunitListNamesBuf + 128 * i; AdunitListNames[i][0] = 0; }
if (!(ParamFile_dat = fopen(ParamFile, "rb"))) ERR_CRITICAL("Unable to open parameter file\n");
PreParamFile_dat = fopen(PreParamFile, "rb");
if (!(AdminFile_dat = fopen(AdunitFile, "rb"))) AdminFile_dat = ParamFile_dat;
AgeSuscScale = 1.0;
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Update timestep", "%lf", (void*) & (P.TimeStep), 1, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling timestep", "%lf", (void*) & (P.SampleStep), 1, 1, 0);
if (P.TimeStep > P.SampleStep) ERR_CRITICAL("Update step must be smaller than sampling step\n");
t = ceil(P.SampleStep / P.TimeStep - 1e-6);
P.UpdatesPerSample = (int)t;
P.TimeStep = P.SampleStep / t;
P.TimeStepsPerDay = ceil(1.0 / P.TimeStep - 1e-6);
fprintf(stderr, "Update step = %lf\nSampling step = %lf\nUpdates per sample=%i\nTimeStepsPerDay=%lf\n", P.TimeStep, P.SampleStep, P.UpdatesPerSample, P.TimeStepsPerDay);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling time", "%lf", (void*) & (P.SampleTime), 1, 1, 0);
P.NumSamples = 1 + (int)ceil(P.SampleTime / P.SampleStep);
GetInputParameter(ParamFile_dat, AdminFile_dat, "Population size", "%i", (void*) & (P.PopSize), 1, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of realisations", "%i", (void*) & (P.NumRealisations), 1, 1, 0);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of non-extinct realisations", "%i", (void*) & (P.NumNonExtinctRealisations), 1, 1, 0)) P.NumNonExtinctRealisations = P.NumRealisations;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of cases defining small outbreak", "%i", (void*) & (P.SmallEpidemicCases), 1, 1, 0)) P.SmallEpidemicCases = -1;
P.NC = -1;
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of micro-cells per spatial cell width", "%i", (void*) & (P.NMCL), 1, 1, 0);
//added parameter to reset seeds after every run
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds for every run", "%i", (void*) & (P.ResetSeeds), 1, 1, 0)) P.ResetSeeds = 0;
if (P.ResetSeeds)
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Keep same seeds for every run", "%i", (void*) & (P.KeepSameSeeds), 1, 1, 0)) P.KeepSameSeeds = 0; //added this to control which seeds are used: ggilani 27/11/19
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds after intervention", "%i", (void*) & (P.ResetSeedsPostIntervention), 1, 1, 0)) P.ResetSeedsPostIntervention = 0;
if (P.ResetSeedsPostIntervention)
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time to reset seeds after intervention", "%i", (void*) & (P.TimeToResetSeeds), 1, 1, 0)) P.TimeToResetSeeds = 1000000;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include households", "%i", (void*) & (P.DoHouseholds), 1, 1, 0)) P.DoHouseholds = 1;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAge" , "%i", (void*) & (P.OutputAge) , 1, 1, 0)) P.OutputAge = 1; //// ON by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputSeverityAdminUnit" , "%i", (void*) & (P.OutputSeverityAdminUnit) , 1, 1, 0)) P.OutputSeverityAdminUnit = 1; //// ON by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputR0" , "%i", (void*) & (P.OutputR0) , 1, 1, 0)) P.OutputR0 = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputControls" , "%i", (void*) & (P.OutputControls) , 1, 1, 0)) P.OutputControls = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputCountry" , "%i", (void*) & (P.OutputCountry) , 1, 1, 0)) P.OutputCountry = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAdUnitVar" , "%i", (void*) & (P.OutputAdUnitVar) , 1, 1, 0)) P.OutputAdUnitVar = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputHousehold" , "%i", (void*) & (P.OutputHousehold) , 1, 1, 0)) P.OutputHousehold = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputInfType" , "%i", (void*) & (P.OutputInfType) , 1, 1, 0)) P.OutputInfType = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSeverity" , "%i", (void*) & (P.OutputNonSeverity) , 1, 1, 0)) P.OutputNonSeverity = 0; //// OFF by default.
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSummaryResults" , "%i", (void*) & (P.OutputNonSummaryResults) , 1, 1, 0)) P.OutputNonSummaryResults = 0; //// OFF by default.
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel resolution", "%i", (void*)&P.NKR, 1, 1, 0)) P.NKR = 4000000;
if (P.NKR < 2000000)
{
ERR_CRITICAL_FMT("[Kernel resolution] needs to be at least 2000000 - not %d", P.NKR);
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel higher resolution factor", "%i", (void*)&P.NK_HR, 1, 1, 0)) P.NK_HR = P.NKR / 1600;
if (P.NK_HR < 1 || P.NK_HR >= P.NKR)
{
ERR_CRITICAL_FMT("[Kernel higher resolution factor] needs to be in range [1, P.NKR = %d) - not %d", P.NKR, P.NK_HR);
}
if (P.DoHouseholds)
{
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Household size distribution", "%lf", (void*)P.HouseholdSizeDistrib[0], MAX_HOUSEHOLD_SIZE, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household attack rate", "%lf", (void*) & (P.HouseholdTrans), 1, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household transmission denominator power", "%lf", (void*) & (P.HouseholdTransPow), 1, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Correct age distribution after household allocation to exactly match specified demography", "%i", (void*)&(P.DoCorrectAgeDist), 1, 1, 0)) P.DoCorrectAgeDist = 0;
}
else
{
P.HouseholdTrans = 0.0;
P.HouseholdTransPow = 1.0;
P.HouseholdSizeDistrib[0][0] = 1.0;
for (i = 1; i < MAX_HOUSEHOLD_SIZE; i++)
P.HouseholdSizeDistrib[0][i] = 0;
}
for (i = 1; i < MAX_HOUSEHOLD_SIZE; i++)
P.HouseholdSizeDistrib[0][i] = P.HouseholdSizeDistrib[0][i] + P.HouseholdSizeDistrib[0][i - 1];
for (i = 0; i < MAX_HOUSEHOLD_SIZE; i++)
P.HouseholdDenomLookup[i] = 1 / pow(((double)(i + 1)), P.HouseholdTransPow);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include administrative units within countries", "%i", (void*) & (P.DoAdUnits), 1, 1, 0)) P.DoAdUnits = 1;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for countries", "%i", (void*) & (P.CountryDivisor), 1, 1, 0)) P.CountryDivisor = 1;
if (P.DoAdUnits)
{
char** AdunitNames, * AdunitNamesBuf;
if (!(AdunitNames = (char**)malloc(3 * ADUNIT_LOOKUP_SIZE * sizeof(char*)))) ERR_CRITICAL("Unable to allocate temp storage\n");
if (!(AdunitNamesBuf = (char*)malloc(3 * ADUNIT_LOOKUP_SIZE * 360 * sizeof(char)))) ERR_CRITICAL("Unable to allocate temp storage\n");
for (i = 0; i < ADUNIT_LOOKUP_SIZE; i++)
{
P.AdunitLevel1Lookup[i] = -1;
AdunitNames[3 * i] = AdunitNamesBuf + 3 * i * 360;
AdunitNames[3 * i + 1] = AdunitNamesBuf + 3 * i * 360 + 60;
AdunitNames[3 * i + 2] = AdunitNamesBuf + 3 * i * 360 + 160;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for level 1 administrative units", "%i", (void*)&(P.AdunitLevel1Divisor), 1, 1, 0)) P.AdunitLevel1Divisor = 1;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Mask for level 1 administrative units", "%i", (void*)&(P.AdunitLevel1Mask), 1, 1, 0)) P.AdunitLevel1Mask = 1000000000;
na = (GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Codes and country/province names for admin units", "%s", (void*)AdunitNames, 3 * ADUNIT_LOOKUP_SIZE, 1, 0)) / 3;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of countries to include", "%i", (void*)&nc, 1, 1, 0)) nc = 0;
if ((na > 0) && (nc>0))
{
P.DoAdunitBoundaries = (nc > 0);
nc = abs(nc);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "List of names of countries to include", "%s", (nc > 1) ? ((void*)CountryNames) : ((void*)CountryNames[0]), nc, 1, 0);
P.NumAdunits = 0;
for (i = 0; i < na; i++)
for (j = 0; j < nc; j++)
if ((AdunitNames[3 * i + 1][0]) && (!strcmp(AdunitNames[3 * i + 1], CountryNames[j])) && (atoi(AdunitNames[3 * i]) != 0))
{
AdUnits[P.NumAdunits].id = atoi(AdunitNames[3 * i]);
P.AdunitLevel1Lookup[(AdUnits[P.NumAdunits].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor] = P.NumAdunits;
if (strlen(AdunitNames[3 * i + 1]) < 100) strcpy(AdUnits[P.NumAdunits].cnt_name, AdunitNames[3 * i + 1]);
if (strlen(AdunitNames[3 * i + 2]) < 200) strcpy(AdUnits[P.NumAdunits].ad_name, AdunitNames[3 * i + 2]);
// fprintf(stderr,"%i %s %s ## ",AdUnits[P.NumAdunits].id,AdUnits[P.NumAdunits].cnt_name,AdUnits[P.NumAdunits].ad_name);
P.NumAdunits++;
}
}
else
{
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of level 1 administrative units to include", "%i", (void*) & (P.NumAdunits), 1, 1, 0)) P.NumAdunits = 0;
if (P.NumAdunits > 0)
{
P.DoAdunitBoundaries = 1;
if (P.NumAdunits > MAX_ADUNITS) ERR_CRITICAL("MAX_ADUNITS too small.\n");
GetInputParameter(PreParamFile_dat, AdminFile_dat, "List of level 1 administrative units to include", "%s", (P.NumAdunits > 1) ? ((void*)AdunitListNames) : ((void*)AdunitListNames[0]), P.NumAdunits, 1, 0);
na = P.NumAdunits;
for (i = 0; i < P.NumAdunits; i++)
{
f = 0;
if (na > 0)
{
for (j = 0; (j < na) && (!f); j++) f = (!strcmp(AdunitNames[3 * j + 2], AdunitListNames[i]));
if(f) k = atoi(AdunitNames[3 * (j-1)]);
}
if ((na == 0) || (!f)) k = atoi(AdunitListNames[i]);
AdUnits[i].id = k;
P.AdunitLevel1Lookup[(k % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor] = i;
for (j = 0; j < na; j++)
if (atoi(AdunitNames[3 * j]) == k)
{
if (strlen(AdunitNames[3 * j + 1]) < 100) strcpy(AdUnits[i].cnt_name, AdunitNames[3 * j + 1]);
if (strlen(AdunitNames[3 * j + 2]) < 200) strcpy(AdUnits[i].ad_name, AdunitNames[3 * j + 2]);
j = na;
}
}
}
else
P.DoAdunitBoundaries = 0;
}
free(AdunitNames);
free(AdunitNamesBuf);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output incidence by administrative unit", "%i", (void*) & (P.DoAdunitOutput), 1, 1, 0)) P.DoAdunitOutput = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Draw administrative unit boundaries on maps", "%i", (void*) & (P.DoAdunitBoundaryOutput), 1, 1, 0)) P.DoAdunitBoundaryOutput = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Correct administrative unit populations", "%i", (void*) & (P.DoCorrectAdunitPop), 1, 1, 0)) P.DoCorrectAdunitPop = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Fix population size at specified value", "%i", (void*) & (P.DoSpecifyPop), 1, 1, 0)) P.DoSpecifyPop = 0;
fprintf(stderr, "Using %i administrative units\n", P.NumAdunits);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for administrative unit codes for boundary plotting on bitmaps", "%i", (void*) & (P.AdunitBitmapDivisor), 1, 1, 0)) P.AdunitBitmapDivisor = 1;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only output household to place distance distribution for one administrative unit", "%i", (void*) & (P.DoOutputPlaceDistForOneAdunit), 1, 1, 0)) P.DoOutputPlaceDistForOneAdunit = 0;
if (P.DoOutputPlaceDistForOneAdunit)
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit for which household to place distance distribution to be output", "%i", (void*) & (P.OutputPlaceDistAdunit), 1, 1, 0)) P.DoOutputPlaceDistForOneAdunit = 0;
}
}
else
{
P.DoAdunitBoundaries = P.DoAdunitBoundaryOutput = P.DoAdunitOutput = P.DoCorrectAdunitPop = P.DoSpecifyPop = 0;
P.AdunitLevel1Divisor = 1; P.AdunitLevel1Mask = 1000000000;
P.AdunitBitmapDivisor = P.AdunitLevel1Divisor;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include age", "%i", (void*) & (P.DoAge), 1, 1, 0)) P.DoAge = 1;
if (!P.DoAge)
{
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.PropAgeGroup[0][i] = 1.0 / NUM_AGE_GROUPS;
for (i = 0; i < NUM_AGE_GROUPS; i++)
{
P.InitialImmunity[i] = 0;
P.AgeInfectiousness[i] = P.AgeSusceptibility[i] = 1;
P.RelativeSpatialContact[i] = P.RelativeTravelRate[i] = 1.0;
}
}
else
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity acts as partial immunity", "%i", (void*)&(P.DoPartialImmunity), 1, 1, 0)) P.DoPartialImmunity = 1;
if ((P.DoHouseholds)&&(!P.DoPartialImmunity))
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity applied to all household members", "%i", (void*) & (P.DoWholeHouseholdImmunity), 1, 1, 0)) P.DoWholeHouseholdImmunity = 0;
}
else
P.DoWholeHouseholdImmunity = 0;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity profile by age", "%lf", (void*)P.InitialImmunity, NUM_AGE_GROUPS, 1, 0))
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.InitialImmunity[i] = 0;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rates by age", "%lf", (void*)P.RelativeSpatialContact, NUM_AGE_GROUPS, 1, 0))
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.RelativeSpatialContact[i] = 1;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent infectiousness", "%lf", (void*)P.AgeInfectiousness, NUM_AGE_GROUPS, 1, 0))
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.AgeInfectiousness[i] = 1.0;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent susceptibility", "%lf", (void*)P.AgeSusceptibility, NUM_AGE_GROUPS, 1, 0))
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.AgeSusceptibility[i] = 1.0;
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Age distribution of population", "%lf", (void*)P.PropAgeGroup[0], NUM_AGE_GROUPS, 1, 0);
t = 0;
for (i = 0; i < NUM_AGE_GROUPS; i++)
t += P.PropAgeGroup[0][i];
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.PropAgeGroup[0][i] /= t;
t = 0;
for (i = 0; i < NUM_AGE_GROUPS; i++)
if (P.AgeSusceptibility[i] > t) t = P.AgeSusceptibility[i]; //peak susc has to be 1
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.AgeSusceptibility[i] /= t;
AgeSuscScale = t;
if (P.DoHouseholds) P.HouseholdTrans *= AgeSuscScale;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Relative travel rates by age", "%lf", (void*)P.RelativeTravelRate, NUM_AGE_GROUPS, 1, 0))
for (i = 0; i < NUM_AGE_GROUPS; i++)
P.RelativeTravelRate[i] = 1;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "WAIFW matrix", "%lf", (void*)P.WAIFW_Matrix, NUM_AGE_GROUPS, NUM_AGE_GROUPS, 0))
{
for (i = 0; i < NUM_AGE_GROUPS; i++)
for (j = 0; j < NUM_AGE_GROUPS; j++)
P.WAIFW_Matrix[i][j] = 1.0;
}
else
{
/* WAIFW matrix needs to be scaled to have max value of 1.
1st index of matrix specifies host being infected, second the infector.
Overall age variation in infectiousness/contact rates/susceptibility should be factored
out of WAIFW_matrix and put in Age dep infectiousness/susceptibility for efficiency.
t = 0;
for (i = 0; i < NUM_AGE_GROUPS; i++)
for (j = 0; j < NUM_AGE_GROUPS; j++)
if (P.WAIFW_Matrix[i][j] > t) t = P.WAIFW_Matrix[i][j];
if (t > 0)
{
for (i = 0; i < NUM_AGE_GROUPS; i++)
for (j = 0; j < NUM_AGE_GROUPS; j++)
P.WAIFW_Matrix[i][j] /= t;
}
else
{
for (i = 0; i < NUM_AGE_GROUPS; i++)
for (j = 0; j < NUM_AGE_GROUPS; j++)
P.WAIFW_Matrix[i][j] = 1.0;
}
}
P.DoDeath = 0;
t = 0;
for (i = 0; i < NUM_AGE_GROUPS; i++) t += P.AgeInfectiousness[i] * P.PropAgeGroup[0][i];
for (i = 0; i < NUM_AGE_GROUPS; i++) P.AgeInfectiousness[i] /= t;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include spatial transmission", "%i", (void*) & (P.DoSpatial), 1, 1, 0)) P.DoSpatial = 1;
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel type", "%i", (void*) & (P.MoveKernelType), 1, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale", "%lf", (void*) & (P.MoveKernelScale), 1, 1, 0);
if (P.KernelOffsetScale != 1)
{
P.MoveKernelScale *= P.KernelOffsetScale;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param", "%lf", (void*) & (P.MoveKernelP3), 1, 1, 0)) P.MoveKernelP3 = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 4th param", "%lf", (void*) & (P.MoveKernelP4), 1, 1, 0)) P.MoveKernelP4 = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel Shape", "%lf", (void*) & (P.MoveKernelShape), 1, 1, 0)) P.MoveKernelShape = 1.0;
if (P.KernelPowerScale != 1)
{
P.MoveKernelShape *= P.KernelPowerScale;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Type", "%i", (void*) & (P.AirportKernelType), 1, 1, 0)) P.AirportKernelType = P.MoveKernelType;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Scale", "%lf", (void*) & (P.AirportKernelScale), 1, 1, 0)) P.AirportKernelScale = P.MoveKernelScale;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Shape", "%lf", (void*) & (P.AirportKernelShape), 1, 1, 0)) P.AirportKernelShape = P.MoveKernelShape;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 3rd param", "%lf", (void*) & (P.AirportKernelP3), 1, 1, 0)) P.AirportKernelP3 = P.MoveKernelP3;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 4th param", "%lf", (void*) & (P.AirportKernelP4), 1, 1, 0)) P.AirportKernelP4 = P.MoveKernelP4;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include places", "%i", (void*)&(P.DoPlaces), 1, 1, 0)) P.DoPlaces = 1;
if (P.DoPlaces)
{
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of types of places", "%i", (void*)&(P.PlaceTypeNum), 1, 1, 0)) P.PlaceTypeNum = 0;
if (P.PlaceTypeNum == 0) P.DoPlaces = P.DoAirports = 0;
}
else
P.PlaceTypeNum = P.DoAirports = 0;
if (P.DoPlaces)
{
if (P.PlaceTypeNum > NUM_PLACE_TYPES) ERR_CRITICAL("Too many place types\n");
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 1 in place types", "%i", (void*)P.PlaceTypeAgeMin, P.PlaceTypeNum, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 1 in place types", "%i", (void*)P.PlaceTypeAgeMax, P.PlaceTypeNum, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Proportion of age group 1 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup), P.PlaceTypeNum, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Proportion of age group 2 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup2), P.PlaceTypeNum, 1, 0))
{
for (i = 0; i < NUM_PLACE_TYPES; i++)
{
P.PlaceTypePropAgeGroup2[i] = 0;
P.PlaceTypeAgeMin2[i] = 0;
P.PlaceTypeAgeMax2[i] = 1000;
}
}
else
{
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 2 in place types", "%i", (void*)P.PlaceTypeAgeMin2, P.PlaceTypeNum, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 2 in place types", "%i", (void*)P.PlaceTypeAgeMax2, P.PlaceTypeNum, 1, 0);
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Proportion of age group 3 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup3), P.PlaceTypeNum, 1, 0))
{
for (i = 0; i < NUM_PLACE_TYPES; i++)
{
P.PlaceTypePropAgeGroup3[i] = 0;
P.PlaceTypeAgeMin3[i] = 0;
P.PlaceTypeAgeMax3[i] = 1000;
}
}
else
{
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 3 in place types", "%i", (void*)P.PlaceTypeAgeMin3, P.PlaceTypeNum, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 3 in place types", "%i", (void*)P.PlaceTypeAgeMax3, P.PlaceTypeNum, 1, 0);
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel shape params for place types", "%lf", (void*) & (P.PlaceTypeKernelShape), P.PlaceTypeNum, 1, 0))
{
for (i = 0; i < NUM_PLACE_TYPES; i++)
{
P.PlaceTypeKernelShape[i] = P.MoveKernelShape;
P.PlaceTypeKernelScale[i] = P.MoveKernelScale;
}
}
else
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale params for place types", "%lf", (void*) & (P.PlaceTypeKernelScale), P.PlaceTypeNum, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param for place types", "%lf", (void*) & (P.PlaceTypeKernelP3), P.PlaceTypeNum, 1, 0))
{
for (i = 0; i < NUM_PLACE_TYPES; i++)
{
P.PlaceTypeKernelP3[i] = P.MoveKernelP3;
P.PlaceTypeKernelP4[i] = P.MoveKernelP4;
}
}
else
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel 4th param for place types", "%lf", (void*) & (P.PlaceTypeKernelP4), P.PlaceTypeNum, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of closest places people pick from (0=all) for place types", "%i", (void*) & (P.PlaceTypeNearestNeighb), P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeNearestNeighb[i] = 0;
if (P.DoAdUnits)
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Degree to which crossing administrative unit boundaries to go to places is inhibited", "%lf", (void*) & (P.InhibitInterAdunitPlaceAssignment), P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.InhibitInterAdunitPlaceAssignment[i] = 0;
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include air travel", "%i", (void*)&(P.DoAirports), 1, 1, 0)) P.DoAirports = 0;
if (!P.DoAirports)
{
// Airports disabled => all places are not to do with airports, and we
// have no hotels.
P.PlaceTypeNoAirNum = P.PlaceTypeNum;
P.HotelPlaceType = P.PlaceTypeNum;
}
else
{
// When airports are activated we must have at least one airport place
// // and a hotel type.
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Number of non-airport places", "%i", (void*)&(P.PlaceTypeNoAirNum), 1, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Hotel place type", "%i", (void*)&(P.HotelPlaceType), 1, 1, 0);
if (P.PlaceTypeNoAirNum >= P.PlaceTypeNum) {
ERR_CRITICAL_FMT("[Number of non-airport places] parameter (%d) is greater than number of places (%d).\n", P.PlaceTypeNoAirNum, P.PlaceTypeNum);
}
if (P.HotelPlaceType < P.PlaceTypeNoAirNum || P.HotelPlaceType >= P.PlaceTypeNum) {
ERR_CRITICAL_FMT("[Hotel place type] parameter (%d) not in the range [%d, %d)\n", P.HotelPlaceType, P.PlaceTypeNoAirNum, P.PlaceTypeNum);
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Scaling factor for input file to convert to daily traffic", "%lf", (void*) & (P.AirportTrafficScale), 1, 1, 0)) P.AirportTrafficScale = 1.0;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of hotel attendees who are local", "%lf", (void*) & (P.HotelPropLocal), 1, 1, 0)) P.HotelPropLocal = 0;
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Distribution of duration of air journeys", "%lf", (void*) & (P.JourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0))
{
P.JourneyDurationDistrib[0] = 1;
for (i = 0; i < MAX_TRAVEL_TIME; i++)
P.JourneyDurationDistrib[i] = 0;
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Distribution of duration of local journeys", "%lf", (void*) & (P.LocalJourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0))
{
P.LocalJourneyDurationDistrib[0] = 1;
for (i = 0; i < MAX_TRAVEL_TIME; i++)
P.LocalJourneyDurationDistrib[i] = 0;
}
P.MeanJourneyTime = P.MeanLocalJourneyTime = 0;
for (i = 0; i < MAX_TRAVEL_TIME; i++)
{
P.MeanJourneyTime += ((double)(i)) * P.JourneyDurationDistrib[i];
P.MeanLocalJourneyTime += ((double)(i)) * P.LocalJourneyDurationDistrib[i];
}
fprintf(stderr, "Mean duration of local journeys = %lf days\n", P.MeanLocalJourneyTime);
for (i = 1; i < MAX_TRAVEL_TIME; i++)
{
P.JourneyDurationDistrib[i] += P.JourneyDurationDistrib[i - 1];
P.LocalJourneyDurationDistrib[i] += P.LocalJourneyDurationDistrib[i - 1];
}
for (i = j = 0; i <= 1024; i++)
{
s = ((double)i) / 1024;
while (P.JourneyDurationDistrib[j] < s)j++;
P.InvJourneyDurationDistrib[i] = j;
}
for (i = j = 0; i <= 1024; i++)
{
s = ((double)i) / 1024;
while (P.LocalJourneyDurationDistrib[j] < s)j++;
P.InvLocalJourneyDurationDistrib[i] = j;
}
}
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Mean size of place types", "%lf", (void*)P.PlaceTypeMeanSize, P.PlaceTypeNum, 1, 0);
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Param 1 of place group size distribution", "%lf", (void*)P.PlaceTypeGroupSizeParam1, P.PlaceTypeNum, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Power of place size distribution", "%lf", (void*)P.PlaceTypeSizePower, P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeSizePower[i] = 0;
//added to enable lognormal distribution - ggilani 09/02/17
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Standard deviation of place size distribution", "%lf", (void*)P.PlaceTypeSizeSD, P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeSizeSD[i] = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Offset of place size distribution", "%lf", (void*)P.PlaceTypeSizeOffset, P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeSizeOffset[i] = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum of place size distribution", "%lf", (void*)P.PlaceTypeSizeMax, P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeSizeMax[i] = 1e20;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel type for place types", "%i", (void*)P.PlaceTypeKernelType, P.PlaceTypeNum, 1, 0))
for (i = 0; i < NUM_PLACE_TYPES; i++)
P.PlaceTypeKernelType[i] = P.MoveKernelType;
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Place overlap matrix", "%lf", (void*)P.PlaceExclusivityMatrix, P.PlaceTypeNum * P.PlaceTypeNum, 1, 0); //changed from P.PlaceTypeNum,P.PlaceTypeNum,0);
/* Note P.PlaceExclusivityMatrix not used at present - places assumed exclusive (each person belongs to 0 or 1 place)
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion of between group place links", "%lf", (void*)P.PlaceTypePropBetweenGroupLinks, P.PlaceTypeNum, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Relative transmission rates for place types", "%lf", (void*)P.PlaceTypeTrans, P.PlaceTypeNum, 1, 0);
for (i = 0; i < P.PlaceTypeNum; i++) P.PlaceTypeTrans[i] *= AgeSuscScale;
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Daily seasonality coefficients", "%lf", (void*)P.Seasonality, DAYS_PER_YEAR, 1, 0))
{
P.DoSeasonality = 0;
for (i = 0; i < DAYS_PER_YEAR; i++)
P.Seasonality[i] = 1;
}
else
{
P.DoSeasonality = 1;
s = 0;
for (i = 0; i < DAYS_PER_YEAR; i++)
s += P.Seasonality[i];
s += 1e-20;
s /= DAYS_PER_YEAR;
for (i = 0; i < DAYS_PER_YEAR; i++)
P.Seasonality[i] /= s;
}
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of seed locations", "%i", (void*) & (P.NumSeedLocations), 1, 1, 0)) P.NumSeedLocations = 1;
if (P.NumSeedLocations > MAX_NUM_SEED_LOCATIONS)
{
fprintf(stderr, "Too many seed locations\n");
P.NumSeedLocations = MAX_NUM_SEED_LOCATIONS;
}
GetInputParameter(PreParamFile_dat, AdminFile_dat, "Initial number of infecteds", "%i", (void*)P.NumInitialInfections, P.NumSeedLocations, 1, 0);
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Location of initial infecteds", "%lf", (void*)&(P.LocationInitialInfection[0][0]), P.NumSeedLocations * 2, 1, 0)) P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][1] = 0.0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Minimum population in microcell of initial infection", "%i", (void*) & (P.MinPopDensForInitialInfection), 1, 1, 0)) P.MinPopDensForInitialInfection = 0;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum population in microcell of initial infection", "%i", (void*)&(P.MaxPopDensForInitialInfection), 1, 1, 0)) P.MaxPopDensForInitialInfection = 10000000;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Randomise initial infection location", "%i", (void*) & (P.DoRandomInitialInfectionLoc), 1, 1, 0)) P.DoRandomInitialInfectionLoc=1;
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "All initial infections located in same microcell", "%i", (void*) & (P.DoAllInitialInfectioninSameLoc), 1, 1, 0)) P.DoAllInitialInfectioninSameLoc=0;
if (P.DoAdUnits)
{
if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Administrative unit to seed initial infection into", "%s", (P.NumSeedLocations > 1) ? ((void*)AdunitListNames) : ((void*)AdunitListNames[0]), P.NumSeedLocations, 1, 0))
for (i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnit[i] = 0;
else
for (i = 0; i < P.NumSeedLocations; i++)
{
f = 0;
if (P.NumAdunits > 0)
{
for (j = 0; (j < P.NumAdunits) && (!f); j++) f = (!strcmp(AdUnits[j].ad_name, AdunitListNames[i]));
if (f) k = AdUnits[j-1].id;
}
if (!f) k = atoi(AdunitListNames[i]);
P.InitialInfectionsAdminUnit[i] = k;
P.InitialInfectionsAdminUnitId[i]=P.AdunitLevel1Lookup[(k % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor];
}
if(!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Administrative unit seeding weights", "%lf", (void*) & (P.InitialInfectionsAdminUnitWeight[0]), P.NumSeedLocations, 1, 0))
for(i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnitWeight[i] = 1.0;
s=0;
for(i = 0; i < P.NumSeedLocations; i++) s+=P.InitialInfectionsAdminUnitWeight[i];
for(i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnitWeight[i]/=s;
// for (i = 0; i < P.NumSeedLocations; i++) fprintf(stderr, "## %i %s %i %i %lf\n",i, AdUnits[P.InitialInfectionsAdminUnitId[i]].ad_name, P.InitialInfectionsAdminUnitId[i], P.InitialInfectionsAdminUnit[i], P.InitialInfectionsAdminUnitWeight[i]);
}
else