-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_simulation.py
109 lines (97 loc) · 3.16 KB
/
do_simulation.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
import sys, getopt
import unittest
import time
# pylint: disable=import-error
from src.Simulator import Simulator
from src.Parameters.IntervalParameter import IntervalParameter
from src.Parameters.ListParameter import ListParameter
from src.Models.SIR import SIR
# TODO: Needs testing.
def main(argv):
size = 1000
model = 'rSIR_V_T'
steps = 300
network = 'BA'
beta = None
gamma = None
delta = None
theta = None
timescale = None
try:
opts, _ = getopt.getopt( argv, "",[
'size=',
'model=',
'steps=',
'network=',
'beta=',
'gamma=',
'delta=',
'theta=',
'timescale=',
] )
except getopt.GetoptError:
print( 'test.py TODO' )
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print( 'TOOD: help' )
sys.exit()
elif opt == "--size":
size = arg
elif opt == "--model":
model = arg
elif opt == "--steps":
steps = arg
elif opt == "--network":
network = arg
elif opt == "--beta":
beta = arg
elif opt == "--gamma":
gamma = arg
elif opt == "--delta":
delta = arg
elif opt == "--theta":
theta = arg
elif opt == "--timescale":
timescale = arg
#TODO: accept the values for parameters (beta, gamma, etc)
parameters = {
'sizes': [int(size)],
'steps': int(steps),
'save_location': './Data/Example/',
'filename': 'new',
'show_legend': True,
'beta': parse_arg( 'beta', beta ), #IntervalParameter('beta', .0, 0.95, .05),
'gamma': parse_arg( 'gamma', gamma ), #IntervalParameter('gamma', .1, .1, .1),
'delta': parse_arg( 'delta', delta ), #IntervalParameter('delta', .3, .3, .3),
'theta': parse_arg( 'theta', theta ), #IntervalParameter('theta', .1, .1, .1),
'timescale': parse_arg( 'timescale', timescale ), #ListParameter('timescale', [ 0, 0.5 ]),#1, 2, 4, 8 ] ),
'vaccinate': 1,
'infect': 1,
}
start = time.time()
s = Simulator( model, [ network ], { 'vac': [ 'Random' ] }, parameters, 'SaveLast' )
s.simulate()
end = time.time()
print('total:', end - start)
def parse_arg( name, arg ):
if arg.isnumeric():
#TODO: add a type of parameter that only has a single value
return IntervalParameter( name, int(arg), int(arg), 1.0 )
try:
arg = float(arg)
#TODO: add a type of parameter that only has a single value
return IntervalParameter( name, arg, arg, 1.0 )
except ValueError:
pass
split = arg.split(',')
if len(split) > 1:
return ListParameter( name, [float(i) for i in split] )
split = arg.split(':')
if len(split) == 3:
return IntervalParameter( name, float(split[0]), float(split[1]), float(split[2]) )
print( 'Problem with arg ' + name)
sys.exit()
if __name__ == "__main__":
main(sys.argv[1:])