-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormula.java
163 lines (133 loc) · 4.84 KB
/
Formula.java
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
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
public class Formula {
public static Vector<Double> MakeDayZero(double vInitPop, double vNumInfectious, double vPercentImm){
Vector<Double> initDay = new Vector<>();
double susceptible = vInitPop-vNumInfectious-vInitPop*vPercentImm/100;
double immune = vInitPop*vPercentImm/100;
initDay.add(new Double(0));
initDay.add(new Double(Math.round(susceptible)));
initDay.add(new Double(vNumInfectious));
initDay.add(new Double(Math.round(immune)));
initDay.add(new Double(0));
initDay.add(new Double(vInitPop));
return initDay;
}
public static Vector<Double> MakeNextDay(Vector<Double> before, double vRateTrans, double vInitPop, double vLengthInf, double vPercentDie){
Vector<Double> nextDay = new Vector<>();
double Sb = before.get(1);
double Ib = before.get(2);
double Imb = before.get(3);
double Deb = before.get(4);
nextDay.add(before.get(0) + 1); //day number
double sNext = Sb-(vRateTrans*Sb*Ib/vInitPop);
if (sNext < 0) {
nextDay.add(0.0);
}
else if (sNext > vInitPop) {
nextDay.add(vInitPop);
}
else {
nextDay.add(new Double(Math.round(sNext))); //susceptible
}
double iNext = Ib+(vRateTrans*Sb*Ib/vInitPop - Ib/vLengthInf - Ib*vPercentDie/(100*vLengthInf));
if (iNext < 0) {
nextDay.add(0.0);
}
else if (iNext > vInitPop) {
nextDay.add(vInitPop);
}
else {
nextDay.add(new Double(Math.round(iNext))); //infected
}
double imNext = Imb+(Ib/vLengthInf);
if (imNext < 0) {
nextDay.add(0.0);
}
else if (imNext > vInitPop) {
nextDay.add(vInitPop);
}
else {
nextDay.add(new Double(Math.round(imNext))); //immune
}
double dNext = vPercentDie*Ib/(100*vLengthInf)+Deb;
if (dNext < 0) {
nextDay.add(0.0);
}
else if (dNext > vInitPop) {
nextDay.add(vInitPop);
}
else {
nextDay.add(new Double(Math.round(dNext))); //dead
}
double pop = vInitPop - Math.round(dNext);
if (pop < 0) {
nextDay.add(0.0);
}
else if (pop > vInitPop) {
nextDay.add(vInitPop);
}
else {
nextDay.add(pop); //population
}
// System.out.println("Sb: " + Sb);
// System.out.println("Ib: " + Ib);
// System.out.println("Imb: " + Imb);
// System.out.println("Deb: " + Deb);
// System.out.println("vRateTrans: " + vRateTrans);
// System.out.println("vInitPop: " + vInitPop);
// System.out.println("vLengthInf: " + vLengthInf);
// System.out.println("vPercentDie: " + vPercentDie);
return nextDay;
}
public static Vector<Double> getRowAt(DefaultTableModel model, int num){
Vector<Double> row = new Vector<>();
for(int i = 0; i < model.getColumnCount(); i++) {
row.add((Double) model.getValueAt(num, i));
}
return row;
}
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
}
catch(NumberFormatException e) {
return false;
}
return true;
}
public static boolean isFloat(String s) {
try {
Float.parseFloat(s);
}
catch(NumberFormatException e) {
return false;
}
return true;
}
public static boolean isNum(String s) {
if(Formula.isFloat(s) || Formula.isInteger(s)) {
return true;
}
else {
return false;
}
}
public static void main(String[] args) {
DefaultTableModel model = new DefaultTableModel();
String[] columnNames = {"Day", "# Susceptible", "# Infected",
"# Immune", "# Dead", "Total Population"};
model.setColumnIdentifiers(columnNames);
Vector<Double> row1 = new Vector<>();
row1.add(0.0); row1.add(94995.0); row1.add(5.0); row1.add(5000.0);
row1.add(0.0); row1.add(100000.0);
Vector<Double> row2 = new Vector<>();
row2.add(1.0); row2.add(94996.0); row2.add(6.0); row2.add(6000.0); row2.add(1.0); row2.add(100006.0);
model.addRow(row1);
model.addRow(row2);
//System.out.println(model.getValueAt(1, 1));
System.out.println(getRowAt(model, 1));
//System.out.println(row1);
//System.out.println(MakeNextDay(row1, 5.0, 1000000.0, 5.0, 5.0));
}
}