-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
46 lines (37 loc) · 1.22 KB
/
core.py
File metadata and controls
46 lines (37 loc) · 1.22 KB
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
import numpy as np
from member import member
import cfg
class CORE(object):
def __init__(self, rate):
self.rate = rate
self.__init_method()
def __init_method(self):
self.isBusy = False
self.current_member: member = None
def __change_work_status(self):
self.isBusy = not(self.isBusy)
def isIdle(self,):
return not(self.isBusy)
def start_work(self, member: member):
self.__change_work_status()
self.current_member = member
time_to_work = self.__get_time_to_work()
if cfg.LOG:
print(
f"\t==> time to work [at core] for ID={member._id} : {time_to_work}")
b = self.current_member.begin_work(time_to_work)
if not b:
self.__change_work_status()
self.current_member = None
def __get_time_to_work(self):
time_to_work = np.random.exponential(1/self.rate)
if cfg.TRACE:
# return 1
time_to_work = 1/self.rate
return time_to_work
def end_work(self):
self.__change_work_status()
self.current_member.begin_queue()
self.current_member = None
def is_serving(self):
return self.current_member != None