1
1
2
+ from typing import Union as _Union
3
+
2
4
from .._network import Network
5
+ from .._networks import Networks
3
6
from .._population import Population
4
7
from ..utils ._profiler import Profiler
5
8
from .._infections import Infections
@@ -25,7 +28,13 @@ def _load_additional_seeds(filename: str):
25
28
26
29
# yes, this is really the order of the seeds - "t num loc"
27
30
# is in the file as "t loc num"
28
- seeds .append ((int (words [0 ]), int (words [2 ]), int (words [1 ])))
31
+ if len (words ) == 4 :
32
+ seeds .append ((int (words [0 ]), int (words [2 ]),
33
+ int (words [1 ]), words [3 ]))
34
+ else :
35
+ seeds .append ((int (words [0 ]), int (words [2 ]),
36
+ int (words [1 ]), None ))
37
+
29
38
print (seeds [- 1 ])
30
39
line = FILE .readline ()
31
40
@@ -40,7 +49,7 @@ def _load_additional_seeds(filename: str):
40
49
_additional_seeds = None
41
50
42
51
43
- def setup_additional_seeds (network : Network ,
52
+ def setup_additional_seeds (network : _Union [ Network , Networks ] ,
44
53
profiler : Profiler ,
45
54
** kwargs ):
46
55
"""Setup function that reads in the additional seeds held
@@ -51,7 +60,7 @@ def setup_additional_seeds(network: Network,
51
60
52
61
Parameters
53
62
----------
54
- network: Network
63
+ network: Network or Networks
55
64
The network to be seeded
56
65
profiler: Profiler
57
66
Profiler used to profile this function
@@ -70,7 +79,7 @@ def setup_additional_seeds(network: Network,
70
79
p = p .stop ()
71
80
72
81
73
- def advance_additional_serial (network : Network ,
82
+ def advance_additional_serial (network : _Union [ Network , Networks ] ,
74
83
population : Population ,
75
84
infections : Infections ,
76
85
profiler : Profiler ,
@@ -80,7 +89,7 @@ def advance_additional_serial(network: Network,
80
89
81
90
Parameters
82
91
----------
83
- network: Network
92
+ network: Network or Networks
84
93
The network being modelled
85
94
population: Population
86
95
The population experiencing the outbreak - also contains the day
@@ -93,24 +102,44 @@ def advance_additional_serial(network: Network,
93
102
Arguments that aren't used by this advancer
94
103
"""
95
104
96
- wards = network .nodes
97
-
98
- play_infections = infections .play
99
- infections = infections .work
100
-
101
105
# The 'setup_additional_seeds' function should have loaded
102
106
# all additional seeds into this global '_additional_seeds' variable
103
107
global _additional_seeds
104
108
105
109
p = profiler .start ("additional_seeds" )
106
110
for seed in _additional_seeds :
107
111
if seed [0 ] == population .day :
108
- if wards .play_suscept [seed [1 ]] < seed [2 ]:
112
+ ward = seed [1 ]
113
+ num = seed [2 ]
114
+
115
+ if isinstance (network , Networks ):
116
+ demographic = seed [3 ]
117
+
118
+ if demographic is None :
119
+ # have to choose a demographic randomly - choose based
120
+ # on the relative populations of the demographics
121
+ demographic = 0
122
+ else :
123
+ demographic = network .demographics .get_index (demographic )
124
+
125
+ wards = network .subnets [demographic ]
126
+ play_infections = infections .subinfs [demographic ].play
127
+ else :
128
+ demographic = None
129
+ wards = network .wards
130
+ play_infections = infections .play
131
+
132
+ if wards .play_suscept [ward ] < num :
109
133
print (f"Not enough susceptibles in ward for seeding" )
110
134
else :
111
- wards .play_suscept [seed [1 ]] -= seed [2 ]
112
- print (f"seeding play_infections[0][{ seed [1 ]} ] += { seed [2 ]} " )
113
- play_infections [0 ][seed [1 ]] += seed [2 ]
135
+ wards .play_suscept [ward ] -= num
136
+ if demographic is not None :
137
+ print (f"seeding demographic { demographic } "
138
+ f"play_infections[0][{ ward } ] += { num } " )
139
+ else :
140
+ print (f"seeding play_infections[0][{ ward } ] += { num } " )
141
+
142
+ play_infections [0 ][ward ] += num
114
143
p .stop ()
115
144
116
145
0 commit comments