-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
60 lines (47 loc) · 1.81 KB
/
agent.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
# library imports
import random
# project imports
from epidemiological_state import EpidemiologicalState
class Agent:
"""
An agent in the population - implemented as timed finite state machine
"""
def __init__(self,
epidimiological_state: EpidemiologicalState,
location: int,
timer: int,
mask: bool = False):
self.e_state = epidimiological_state
self.location = location
self.timer = timer
self.mask = mask
@staticmethod
def create_random(graph_size: int):
return Agent(epidimiological_state=random.choice([EpidemiologicalState.S,
EpidemiologicalState.E,
EpidemiologicalState.I,
EpidemiologicalState.R,
EpidemiologicalState.D]),
location=random.randint(0, graph_size-1),
timer=0,
mask=False)
def tic(self):
self.timer += 1
def set_e_state(self,
new_e_state: EpidemiologicalState):
self.e_state = new_e_state
self.timer = 0
def put_mask(self):
self.mask = True
def copy(self):
return Agent(epidimiological_state=self.e_state,
location=self.location,
timer=self.timer,
mask=self.mask)
def __hash__(self):
return (self.e_state, self.location).__hash__()
def __repr__(self):
return self.__str__()
def __str__(self):
return "<Agent: State={}, Location={}>".format(self.e_state,
self.location)