-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
124 lines (97 loc) · 3.45 KB
/
main.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
/*
* main.cpp
*
* Created on: 13 Oct 2011
* Author: nathan
*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include "basesimulation.h"
#include "state.h"
#include "stateage.h"
#include "tb_states.h"
#include "statetransitiontable.h"
using namespace std;
using namespace microsimulator;
int main(int argc, char *argv[]) {
cout << "Loading transition table" << endl;
ifstream jsonfile("testinput.json");
stringstream jsonstream;
if (jsonfile.is_open()) {
while ( jsonfile.good() ) {
string line;
getline (jsonfile, line);
jsonstream << line << endl;
}
jsonfile.close();
} else {
cout << "Unable to open json file" << endl;
return 1;
}
StateTransitionTable stateTable;
stateTable.loadStateTransitionTable(jsonstream.str(), JSON);
cout << "Finished loading transition table" << endl;
StateActiveTb activeTb;
StateAlive alive;
StateAge age;
State numberActiveTb;
BaseSimulation s1;
if (argc < 3) {
cout << argv[0] << "<number of individuals> <number of iterations> "
<< "<iteration period in days>" << endl;
return 1;
}
int nIndividuals = atoi(argv[1]);
int nIterations = atoi(argv[2]);
double timePeriod = atof(argv[3]);
cout << "Individuals: " << nIndividuals << endl;
cout << "Iterations: " << nIterations << endl;
cout << "Time Period: " << timePeriod << endl;
s1.addState("alive", &alive);
s1.addState("active tb", &activeTb);
s1.addState("number active tb", &numberActiveTb);
s1.addState("age", &age);
alive.registerRequiredState("active tb", activeTb.getId());
alive.registerRequiredState("age", age.getId());
alive.registerRequiredState("alive", alive.getId());
activeTb.registerRequiredState("alive", alive.getId());
activeTb.registerRequiredState("number active tb", numberActiveTb.getId());
age.registerRequiredState("alive", alive.getId());
s1.setTimePeriod(timePeriod);
s1.setIndividuals(nIndividuals);
s1.setIterations(nIterations);
cout << "Preparing tb simulation" << endl;
s1.prepare();
cout << "Simulating tb" << endl;
s1.simulate();
cout << "Simulation tb finished" << endl;
AnalysisOutput s1Output;
s1.addAnalysisDescriptor("Number of people alive with tb",
activeTb.getId(), count, {On(alive.getId()), On(activeTb.getId())});
s1.addAnalysisDescriptor("Number of people who died with tb",
activeTb.getId(), count, {Off(alive.getId())});
s1.addAnalysisDescriptor("Mean age of the living",
age.getId(), mean, {On(alive.getId())});
s1.addAnalysisDescriptor("Mean age of the dead",
age.getId(), mean, {Off(alive.getId())});
s1.addAnalysisDescriptor("Median age of the living",
age.getId(), median, {On(alive.getId())});
s1.addAnalysisDescriptor("Median age of the dead",
age.getId(), median, {Off(alive.getId())});
s1.addAnalysisDescriptor("Number of people alive", alive.getId(), count);
s1.addAnalysisDescriptor("Number of living people who've had active TB",
numberActiveTb.getId(), count, {On(alive.getId())});
s1.addAnalysisDescriptor("Number of people who've had active TB",
numberActiveTb.getId(), count);
s1.addAnalysisDescriptor("Mean number of times people with active TB infected",
numberActiveTb.getId(), mean, {On(numberActiveTb.getId())});
s1Output = s1.analyze();
cout << "DESCRIPTIONS" << endl;
for (auto it : s1Output) {
cout << it.description << " " << it.value << endl;
}
cout << "END" << endl;
return 0;
}