-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
177 lines (146 loc) · 5.21 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
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
#include <iostream>
#include <unistd.h>
using namespace std;
double pop;
double r;
int generation = 0;
double positiveCases;
int percentPositive;
void graphicsStable(int percentPositive_stable){ /// BUG : this function has some bugs with simfrom
/* Make sure the graphics start from the same column */
if(generation < 10.0 && percentPositive_stable < 10.0){
cout << " ";
}
if(generation >= 10.0 && percentPositive_stable < 10.0){
cout << " ";
}
if(generation < 10.0 && percentPositive_stable >= 10.0){
cout << " ";
}
if(generation >= 10.0 && percentPositive_stable >= 10.0){
cout << "";
}
}
void Graphics(int percentPositive_drawing, string graph_char){
for(int o = 0; o < percentPositive_drawing; o++){
cout << graph_char;
}
cout << "" << endl;
}
int main()
{
cout << "" << endl;
cout << "spreadOut" << endl;
cout << "the tool for simulating medical or social disease spreading." << endl;
cout << "Type 'help' for printing help message." << endl;
cout << "" << endl;
string mode;
while(true){
cout << " >> ";
cin >> mode;
if(mode == "help"){
cout << "" << endl;
cout << "sim start a simulation from 1 positive case" << endl;
cout << "simfrom start a simulation from a chosen number of positive cases" << endl;
cout << "simfrom-p start a simulation with a progressing R number" << endl;
cout << "simfrom-p-v start a simulation with a vaccine" << endl;
cout << "quit quit spreadOut" << endl;
cout << "" << endl;
}
if(mode == "quit"){
break;
}
if(mode == "sim"){
generation = 0;
cout << "" << endl;
cout << "R = " ;
cin >> r;
cout << "Population : " ;
cin >> pop;
positiveCases = 1;
cout << "" << endl;
while(positiveCases < pop){
generation += 1;
percentPositive = positiveCases/(pop/100);
positiveCases *= r;
cout << "Generation " << generation << " : " << percentPositive << "% ";
graphicsStable(percentPositive);
Graphics(percentPositive, "|");
}
}
if(mode == "simfrom"){
generation = 0;
cout << "" << endl;
cout << "Confirmed positive cases : ";
cin >> positiveCases;
cout << "Population : ";
cin >> pop;
percentPositive = (100/pop)*positiveCases; // percent of positive
cout << "R = ";
cin >> r;
cout << "" << endl;
while(positiveCases < pop && positiveCases >= 1){
generation += 1;
percentPositive = positiveCases/(pop/100);
positiveCases *= r;
cout << "Generation " << generation << " : " << percentPositive << "% ";
graphicsStable(percentPositive);
Graphics(percentPositive, "|");
}
}
if(mode == "simfrom-p"){
generation = 0;
cout << "" << endl;
cout << "Confirmed positive cases : ";
cin >> positiveCases;
cout << "Population : ";
cin >> pop;
percentPositive = (100/pop)*positiveCases; // percent of positive
cout << "R (at the first generation) = ";
cin >> r;
cout << "R progressing rate = ";
double rprog;
cin >> rprog;
cout << "" << endl;
while(positiveCases < pop && positiveCases >= 1){
generation += 1;
percentPositive = positiveCases/(pop/100);
positiveCases *= r;
r += rprog;
cout << "Generation " << generation << " : " << percentPositive << "% ";
graphicsStable(percentPositive);
Graphics(percentPositive, "|");
}
}
if(mode == "simfrom-p-v"){
generation = 0;
cout << "" << endl;
cout << "Confirmed positive cases : ";
cin >> positiveCases;
cout << "Population : ";
cin >> pop;
percentPositive = (100/pop)*positiveCases; // percent of positive
cout << "R (at the first generation) = ";
cin >> r;
cout << "R progressing rate = ";
double rprog;
cin >> rprog;
cout << "Vaccinated population (in %) : ";
double vax;
cin >> vax;
cout << "" << endl;
while(positiveCases < pop && positiveCases >= 1){
generation += 1;
percentPositive = positiveCases/(pop/100);
positiveCases *= r;
if(positiveCases > (100-vax)) positiveCases /= r;
r += rprog;
cout << "Generation " << generation << " : " << percentPositive << "% ";
graphicsStable(percentPositive);
Graphics(percentPositive, "|");
usleep(1000000);
}
}
}
return 0;
}