-
Notifications
You must be signed in to change notification settings - Fork 0
/
Version_3_Final.py
828 lines (708 loc) · 23.4 KB
/
Version_3_Final.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# Index
# 11 - Importing Libraries
# 19 - Defining Classes
# 32 - Defining Function
# 658 - Initializing the Variables
# 680 - Intermediate Calculations
# 695 - Creating Initial World
# 711 - Starting the Interaction Process
# 754 - Plotting the Results
# Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
import time
# Time Taken for Simulation
Start_Time = time.time()
# Defining Classes
class Agent:
def __init__(self, id, Category, Home, Work, Time_Till_Isolation, Immunity, Time_Till_Recovery, Infection_Status, Vaccination_Status):
self.id = id
self.Category = Category # Categories (MH, SE, CE, ST, HW, SP)
self.Home = Home # (i,j)
self.Work = Work # (i, j)
self.Time_Till_Isolation = Time_Till_Isolation # (default = 3)
self.Immunity = Immunity
self.Time_Till_Recovery = Time_Till_Recovery # (default = 3)
# (default = 0[Non-Infected], 1[Infected], 2[Isolation], 3[Death])
self.Infection_Status = Infection_Status
# (default = 0[Non-Vaccinated], 1[Partially Vaccinated], 2[Completely Vaccinated])
self.Vaccination_Status = Vaccination_Status
# Defining Functions
def Home_Loc(N, Grid):
Home_loc = []
for i in range(N):
loc = np.random.randint(1, Grid + 1, size=2)
loc = np.split(loc, 2)
temp = [loc[0][0], loc[1][0]]
if temp not in Home_loc:
Home_loc.append(temp)
return Home_loc
def Work_Loc(N, Home):
Work_loc = []
count = 0
while count < N:
loc = np.random.randint(1, Grid + 1, size=2)
loc = np.split(loc, 2)
temp = [loc[0][0], loc[1][0]]
if temp not in Home:
if temp not in Work_loc:
Work_loc.append(temp)
count += 1
return Work_loc
def Agent_init(n):
Array = np.array([])
for i in range(n):
Category = np.random.randint(6)
Home = np.random.choice(len(Home_Locations))
Home = Home_Locations[Home]
if Category > 1:
Work = np.random.choice(len(Work_Locations))
Work = Work_Locations[Work]
else:
Work = None
temp = Agent(i, Category, Home, Work,
Time_Till_Isolation=TTI,
Immunity=1,
Time_Till_Recovery=TTR,
Infection_Status=0,
Vaccination_Status=0)
Array = np.append(Array, temp)
return Array
def Neighbour(x):
m1 = [x[0] - 1, x[1] - 1]
m2 = [x[0], x[1] - 1]
m3 = [x[0] + 1, x[1] - 1]
m4 = [x[0] - 1, x[1]]
m5 = [x[0] + 1, x[1]]
m6 = [x[0] - 1, x[1] + 1]
m7 = [x[0], x[1]]
m8 = [x[0] + 1, x[1] + 1]
temp = [m1, m2, m3, m4, m5, m6, m7, m8]
return temp
def Distance(a, b):
dist = np.square(a.Home[0] - b.Home[0]) + np.square(a.Home[1] - b.Home[1])
temp = np.sqrt(dist) # * Grid
return temp
def Probability(x):
temp = np.random.randint(1, 10000)
# print(temp)
if temp < x:
return True
else:
return False
def Uni_Prob_Interaction(a, b):
if a.Home == b.Home:
return p_high
elif a.Home in Neighbour(b.Home):
return p_medium
def Uni_Str_Interaction(A1, A2):
if A1.Home == A2.Home:
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
def Choice(a, b):
if a.Category == "MH" and b.Category == "MH":
return 'AA'
elif a.Category == "MH" and b.Category == "SE":
return 'AB'
elif a.Category == "MH" and b.Category == "CE":
return 'AC'
elif a.Category == "MH" and b.Category == "HW":
return 'AD'
elif a.Category == "MH" and b.Category == "ST":
return 'AE'
elif a.Category == "MH" and b.Category == "SP":
return 'AF'
elif a.Category == "SE" and b.Category == "MH":
return 'AB'
elif a.Category == "SE" and b.Category == "SE":
return 'BB'
elif a.Category == "SE" and b.Category == "CE":
return 'BC'
elif a.Category == "SE" and b.Category == "HW":
return 'BD'
elif a.Category == "SE" and b.Category == "ST":
return 'BE'
elif a.Category == "SE" and b.Category == "SP":
return 'BF'
elif a.Category == "CE" and b.Category == "MH":
return 'AC'
elif a.Category == "CE" and b.Category == "SE":
return 'BC'
elif a.Category == "CE" and b.Category == "CE":
return 'CC'
elif a.Category == "CE" and b.Category == "HW":
return 'CD'
elif a.Category == "CE" and b.Category == "ST":
return 'CE'
elif a.Category == "CE" and b.Category == "SP":
return 'CF'
elif a.Category == "HW" and b.Category == "MH":
return 'AD'
elif a.Category == "HW" and b.Category == "SE":
return 'BD'
elif a.Category == "HW" and b.Category == "CE":
return 'CD'
elif a.Category == "HW" and b.Category == "HW":
return 'DD'
elif a.Category == "HW" and b.Category == "ST":
return 'DE'
elif a.Category == "HW" and b.Category == "SP":
return 'DF'
elif a.Category == "ST" and b.Category == "MH":
return 'AE'
elif a.Category == "ST" and b.Category == "SE":
return 'BE'
elif a.Category == "ST" and b.Category == "CE":
return 'CE'
elif a.Category == "ST" and b.Category == "HW":
return 'DE'
elif a.Category == "ST" and b.Category == "ST":
return 'EE'
elif a.Category == "ST" and b.Category == "SP":
return 'EF'
elif a.Category == "SP" and b.Category == "MH":
return 'AF'
elif a.Category == "SP" and b.Category == "SE":
return 'BF'
elif a.Category == "SP" and b.Category == "CE":
return 'CF'
elif a.Category == "SP" and b.Category == "HW":
return 'DF'
elif a.Category == "SP" and b.Category == "ST":
return 'EF'
elif a.Category == "SP" and b.Category == "SP":
return 'FF'
def Probability_of_Interaction(A1, A2):
choice = Choice(A1, A2)
if choice == 'AA':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'AB':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'AC':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'AD':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'AE':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'AF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'BB':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'BC':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'BD':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'BE':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'BF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'CC':
temp = Uni_Prob_Interaction(A1, A2)
if A1.Work == A2.Work:
return p_high
elif temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'CD':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'CE':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'CF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'DD':
temp = Uni_Prob_Interaction(A1, A2)
if A1.Work == A2.Work:
return p_high
elif temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'DE':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'DF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'EE':
temp = Uni_Prob_Interaction(A1, A2)
if A1.Work == A2.Work:
return p_high
elif temp != None:
return temp
else:
if Distance(A1, A2) < 2:
return p_medium / Distance(A1, A2)
else:
return p_low / Distance(A1, A2)
elif choice == 'EF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
return p_low / Distance(A1, A2)
elif choice == 'FF':
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
elif A1.Work == A2.Work:
return p_medium
else:
return p_low / Distance(A1, A2)
def Strength_of_Interaction(A1, A2):
choice = Choice(A1, A2)
if choice == 'AA':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'AB':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'AC':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'AD':
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif choice == 'AE':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'AF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'BB':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'BC':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'BD':
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif choice == 'BE':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'BF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'CC':
temp = Uni_Str_Interaction(A1, A2)
if A1.Work == A2.Work:
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'CD':
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif choice == 'CE':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'CF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'DD':
temp = Uni_Str_Interaction(A1, A2)
if A1.Work == A2.Work:
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'DE':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'DF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'EE':
temp = Uni_Str_Interaction(A1, A2)
if A1.Work == A2.Work:
if A2.Vaccination_Status == 0:
return s_high * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_high * A2.Immunity * 0.5
else:
return 0
elif temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_medium * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_medium * A2.Immunity * 0.5
else:
return 0
elif choice == 'EF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
elif choice == 'FF':
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp
else:
if A2.Vaccination_Status == 0:
return s_low * A2.Immunity
elif A2.Vaccination_Status == 1:
return s_low * A2.Immunity * 0.5
else:
return 0
def Recovery_Death(A1):
temp = np.random.randint(1, 10000)
if temp < 9900:
A1.Infection_Status = 0
A1.Immunity = A1.Immunity * Recovery_Constant
A1.Time_Till_Isolation = TTI
A1.Time_Till_Recovery = TTR
else:
A1.Infection_Status = 3
def Initial_Infected(N):
select = np.random.choice(Population_Size, size=N)
for i in select:
Population[i].Infection_Status = 1
def POI(A1, A2):
if A1.Work == A2.Work and A1.Work != None:
return p_high
temp = Uni_Prob_Interaction(A1, A2)
if temp != None:
return temp
else:
dist = Distance(A1, A2)
if dist < 5:
return P_Matrix[A1.Category][A2.Category] / dist
else:
return p_low / dist
def SOI(A1, A2):
temp = Uni_Str_Interaction(A1, A2)
if temp != None:
return temp * A2.Immunity
else:
return S_Matrix[A1.Category][A2.Category] * A2.Immunity
# Initailizing Variables
# Categories: 0 = MH, 1 = SE, 2 = CE, 3 = ST, 4 = HW, 5 = SP
Grid = 15
Population_Size = 1000
Initial_Infected_Population = 1
TTI = 3 # Time Till Isolation
TTR = 10 # Time Till Recovery
Strength = 1200 # Co-efficient of Strength of Interaction
Probab = 1500 # Co-efficient of Probability of Interaction
# Degree of Change in Immunity After Recovering from the infection
Recovery_Constant = 0.5
Total_Simulation_Time = 100
Vaccination_StartTime = 50
Daily_Vaccination = 50
# Intermediate Calculations
s_high = Strength
s_medium = Strength * (2/3)
s_low = Strength * (1/3)
p_high = Probab
p_medium = Probab * (2/3)
p_low = Probab * (1/3)
P_Matrix = [[p_low, p_medium, p_low, p_medium, p_low, p_medium],
[p_medium, p_low, p_medium, p_medium, p_medium, p_low],
[p_low, p_medium, p_low, p_medium, p_low, p_low],
[p_medium, p_medium, p_medium, p_low, p_medium, p_low],
[p_low, p_medium, p_low, p_medium, p_medium, p_low],
[p_medium, p_low, p_low, p_low, p_low, p_low]]
S_Matrix = [[s_low, s_low, s_low, s_high, s_medium, s_medium],
[s_low, s_low, s_low, s_high, s_medium, s_low],
[s_low, s_low, s_low, s_high, s_low, s_low],
[s_high, s_high, s_high, s_medium, s_medium, s_medium],
[s_medium, s_medium, s_low, s_medium, s_low, s_low],
[s_medium, s_low, s_low, s_high, s_low, s_low]]
day = 0
Daily_Count = [[day, Initial_Infected_Population]]
# Creating the Initial World
Home_Ratio = int(Grid * Grid * 0.8) # Ratio of Homes in the Given Area
Home_Locations = Home_Loc(Home_Ratio, Grid)
# Ratio of Work Locations in the Given Area
Work_Ratio = int(Grid * Grid * 0.2)
Work_Locations = Work_Loc(Work_Ratio, Home_Locations)
# Initailize the Agents in the Population
Population = Agent_init(Population_Size)
# Number of Infected Agents at the Start of Simulation
Initial_Infected(Initial_Infected_Population)
# Starting the Interaction Process
while day < Total_Simulation_Time:
day += 1
# Introducing Vaccination
if day > Vaccination_StartTime:
vaccinate = np.random.choice(Population, Daily_Vaccination)
for x in vaccinate:
if x.Vaccination_Status == 0:
x.Vaccination_Status = 1
x.Immunity = x.Immunity * 0.5
elif x.Vaccination_Status == 1:
x.Vaccination_Status = 2
x.Immunity = 0
Infected = [] # Temporary list for Infected Population
Non_Infected = [] # Temporary list for Non-Infected Population
for y in Population: # Seggregating the Population into temporary list
if y.Infection_Status == 0:
Non_Infected.append(y)
elif y.Infection_Status == 1:
Infected.append(y)
elif y.Infection_Status == 2:
y.Time_Till_Recovery -= 1 # Recovery Time Calculation
if y.Time_Till_Recovery == 0:
Recovery_Death(y)
for i in Infected: # Actual Interaction
for j in Non_Infected:
if Probability(POI(i, j)) is True:
if Probability(SOI(i, j)) is True:
j.Infection_Status = 1
i.Time_Till_Isolation -= 1 # Isolation Time Calculation
if i.Time_Till_Isolation == 0:
i.Infection_Status = 2
# Daily count of Number of Infected Agents
Daily_Count.append([day, len(Infected)])
# Time Taken for Simulation
End_Time = time.time()
print("Time Taken for Simulation = ", End_Time - Start_Time)
# Plotting the Results
plt.figure(dpi=100)
count = []
infected = []
for i in Daily_Count:
count.append(i[0])
infected.append(i[1])
plt.plot(np.array(count), np.array(infected))
plt.title('Curve of Growth of Infection w.r.t. Time')
plt.xlabel('Number of Days')
plt.ylabel('Total Number of Infected Agents')
plt.show()