-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.go
158 lines (131 loc) · 5.95 KB
/
simulation.go
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
package main
import (
"log"
"math/rand"
"runtime"
)
// nationalHealthcareSystem SSN
type nationalHealthcareSystem struct {
intensiveCare int
subIntensiveCare int
intensiveCareHospitalization []uint32
subIntensiveCareHospitalization []uint32
}
// spreadingDesease runs a simulation over n epochs on a bigNet ([]person)
func spreadingDesease(networkPointer *bigNet, epochs int, epochsResultsPointer *[simulationEpochs][5]int, muskPointer *muskMeasure, socialDistancePointer *socialDistancingMeasure, ssnPointer *nationalHealthcareSystem, trialsResultsPointer *[][3]int, ssnEpochResults *[simulationEpochs][2]int, trial int) error {
for epoch := 0; epoch < epochs; epoch++ {
if epoch == 0 {
// pick a random infect over the graph
case0 := rand.Intn(nNodes)
(*networkPointer)[case0].Infective = true
log.Println("CASE 0:", case0)
infectiveDaysLen := len((*networkPointer)[case0].InfectiveDays)
for day := 0; day < infectiveDaysLen; day++ {
if (*networkPointer)[case0].InfectiveDays[day] == 0 {
isInfected, infected := middlewareContainmentMeasure(&(*networkPointer)[case0], muskPointer, socialDistancePointer, epoch)
if isInfected {
if (*networkPointer)[infected].InfectiveEpochs > 0 {
// Check if Healthcare is neeeded
requireHealthcare, typeHealthcare := bernoulliHealthcare(pIntensiveCare, pSubIntensiveCare)
if requireHealthcare {
// if Healthcare needed, check if there are bed available
addedToSSN := addToSSN(ssnPointer, uint32(infected), typeHealthcare)
if addedToSSN {
// if added to SSN can still infect others
(*networkPointer)[infected].Infective = true
(*networkPointer)[infected].InfectiveEpochs += hospitalDays
} else {
// if not possible to add to SSN the patient is dead
//log.Println("NO BED AVAILABLE")
(*networkPointer)[infected].InfectiveEpochs = 0
(*networkPointer)[infected].Dead = true
}
} else {
(*networkPointer)[infected].Infective = true
}
}
}
// I set to -1 in order to not consider it anymore
(*networkPointer)[case0].InfectiveDays[day] = -1
} else if (*networkPointer)[case0].InfectiveDays[day] > 0 {
(*networkPointer)[case0].InfectiveDays[day]--
}
}
// make time pass and reduce the remaining infective days
_ = reduceInfectiveEpochs(&(*networkPointer)[case0], ssnPointer, uint32(case0))
} else {
infected := getInfected(networkPointer)
for _, infectedID := range infected {
infectiveDaysLen := len((*networkPointer)[infectedID].InfectiveDays)
for day := 0; day < infectiveDaysLen; day++ {
if (*networkPointer)[infectedID].InfectiveDays[day] == 0 {
isInfected, infected := middlewareContainmentMeasure(&(*networkPointer)[infectedID], muskPointer, socialDistancePointer, epoch)
if isInfected {
if (*networkPointer)[infected].Infective == false &&
(*networkPointer)[infected].Dead == false &&
(*networkPointer)[infected].Survived == false &&
(*networkPointer)[infected].InfectiveEpochs > 0 {
// Check if Healthcare is neeeded
requireHealthcare, typeHealthcare := bernoulliHealthcare(pIntensiveCare, pSubIntensiveCare)
if requireHealthcare {
// if Healthcare needed, check if there are bed available
addedToSSN := addToSSN(ssnPointer, uint32(infected), typeHealthcare)
if addedToSSN {
// if added to SSN can still infect others
(*networkPointer)[infected].Infective = true
(*networkPointer)[infected].InfectiveEpochs += hospitalDays
} else {
//log.Println("NO BED AVAILABLE")
// if not possible to add to SSN the patient is dead
(*networkPointer)[infected].InfectiveEpochs = 0
(*networkPointer)[infected].Dead = true
}
} else {
(*networkPointer)[infected].Infective = true
}
}
}
// I set to -1 in order to not consider it anymore
(*networkPointer)[infectedID].InfectiveDays[day] = -1
} else if (*networkPointer)[infectedID].InfectiveDays[day] > 0 {
(*networkPointer)[infectedID].InfectiveDays[day]--
}
}
// make time pass and reduce the remaining infective days
_ = reduceInfectiveEpochs(&(*networkPointer)[infectedID], ssnPointer, uint32(infectedID))
}
}
infectNumber := countInfected(networkPointer, true, false, false)
log.Println("EPOCH\t", epoch,
"\tACTIVE:\t", infectNumber,
"\t\tINT.CARE:\t", len((*ssnPointer).intensiveCareHospitalization),
"\tSUB.INT.CARE:", len((*ssnPointer).subIntensiveCareHospitalization))
// number of infected today
(*epochsResultsPointer)[epoch][0] = infectNumber
// new number of infected today regards yesterday
if epoch != 0 {
lastInfected := (*epochsResultsPointer)[epoch-1][0]
(*epochsResultsPointer)[epoch][1] = infectNumber - int(lastInfected)
} else {
(*epochsResultsPointer)[epoch][1] = infectNumber
}
// number of total infected
(*epochsResultsPointer)[epoch][2] = countTotalInfected(networkPointer)
// number of total recovered
(*epochsResultsPointer)[epoch][3] = countInfected(networkPointer, false, true, false)
// number of total deaths
(*epochsResultsPointer)[epoch][4] = countInfected(networkPointer, false, false, true)
// number of intensive care
(*ssnEpochResults)[epoch][0] = len((*ssnPointer).intensiveCareHospitalization)
// number of sub intensive care
(*ssnEpochResults)[epoch][1] = len((*ssnPointer).subIntensiveCareHospitalization)
runtime.GC()
}
// assign number of total infected to col 0 of trial
(*trialsResultsPointer)[trial][0] = countTotalInfected(networkPointer)
// assign number of total recovered to col 1 of trial
(*trialsResultsPointer)[trial][1] = countInfected(networkPointer, false, true, false)
// assign number of total deaths to col 2 of trial
(*trialsResultsPointer)[trial][2] = countInfected(networkPointer, false, false, true)
return nil
}