-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
85 lines (58 loc) · 2.51 KB
/
main.py
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
from random import seed
from graph import Sparse_Graph
from Objects import Particle,Box,Population,THE_CURVE
from physics import particle_interaction
import shutil
import os
# Simulation parameters
Nparticles = 200 # number of particles in the box
charge = 0.04 # particle charge
wall_factor = 0.1 # wall repulsion strength
action_radius = 0.15 # radius for interaction (infection & coulomb)
boxsize = 3 # size of (square) box
CT_fraction = 0.8 # fraction of population on contact tracing network
I_time = 1.5 # total infection time
prob_symptom = 0.15 # fraction of population that develops symptoms
PS_time = 0.3 # pre-symptomatic time
prob_infect = 0.25 # probability of infection within action radius at each timestep
dt = 0.05 # timestep
Niter = 300 # Number of iterations
seed(2) # Fixed random seed. Comment out for pure random
Infection_curve_frames = False
if __name__ == "__main__":
# Declare square box
box = Box(boxsize, boxsize)
# Declare infection curve
curve = THE_CURVE()
# Declare maximum Coulomb force
max_force = charge * charge / 0.01 ** 2
# Declare population and infect patient zero
pop = Population(box,Nparticles,charge,CT_fraction,I_time,PS_time,prob_symptom,prob_infect)
pop.particle_list[0].infect()
# Declare CT network
particles_network = [pop.particle_list[i] \
for i in range( Nparticles ) if pop.particle_list[i].CT]
graph = Sparse_Graph([particles_network[i].set_network_id(i) \
for i in range( len(particles_network) ) ])
# Remove previous saved frames
try:
shutil.rmtree('./box/')
except:
print('Could not delete folder box')
os.makedirs('./box/',exist_ok=True)
# Run simulation
for i in range(0, Niter):
print(i)
particle_interaction(pop, box, graph, action_radius, wall_factor, max_force, dt, i)
pop.update_pop(dt, graph)
box.plot_pop(pop, i, graph, dt, show=False)
curve.update(pop, iteration=i)
# Save infection curve (at every iteration or just last one)
if Infection_curve_frames:
try:
shutil.rmtree('./curve/')
except:
print('Could not delete folder curve')
os.makedirs('./curve/',exist_ok=True)
curve.save_frames()
curve.make_curve()