我正在开展一个项目,用Simpy 2.6描述急诊科的患者流量。
假设进气区有三名医生。我的过程是,在看到一位特定医生(比如医生X)后,患者将(有80%的机会)去实验室。在实验室测试之后,患者将通过重新加入队列返回到原始医生X.
但是我如何在患者-docotr之间建立联系?现在我的代码中的患者是无记忆的" - 他们只是在实验室测试后看到一名随机医生。入口区共有20张床。
请帮帮我!提前谢谢!!
class Intake(Process):
Queue = [] #patient queue
Idle = [] #idle PAs list
Busy = [] #busy PAs list
Waits=[] #list of wait times, the D2D time
#Wholetime=[] #list of whole time spent in ED
IQ = [] #amount in queue when a customer leaves
NDone = 0 #total number of customers that have been services
i = 0 #new; counter of bed occupation
def __init__(self):
Process.__init__(self)
Intake.Idle.append(self) #initially idle
def Run(self):
while Intake.i <= 20: # new new new bed
yield passivate,self #remain idle until customer is ready
Intake.Idle.remove(self)
Intake.Busy.append(self)
while Intake.Queue != []: #perform while customers in queue
P = Intake.Queue.pop(0) # get customer
Intake.i += 1 #new new new bed
Intake.ServiceRate1 = 0.1 / (P.Severity)
Intake.Waits.append(now() - P.ArrivalTime)
Intake.IQ.append(len(Intake.Queue))
ServiceTime = G.Rnd.expovariate(Intake.ServiceRate1)
yield hold,self,ServiceTime #perform job
Intake.NDone += 1
if rand() <= 0.8:
Lab.Queue.append(P)
if Lab.Idle != []:
reactivate(Lab.Idle[0])
else:
Treatment.Queue.append(P)
Intake.i -= 1
if Treatment.Idle != []:
reactivate(Treatment.Idle[0])
Intake.Busy.remove(self)
Intake.Idle.append(self)
""" Lab Process (with P=0.8 patients come here)"""
class Lab(Process):
Queue = [] #patient queue
Idle = [] #idle PAs list
Busy = [] #busy PAs list
Wholetime=[] #list of whole time spent in ED
#Waits=[] #list of wait times, the D2D time
#hQ = [] #amount in queue when a customer leaves
NDone = 0 #total number of customers that have been services
def __init__(self):
Process.__init__(self)
Lab.Idle.append(self) #initially idle
def Run(self):
while True:
yield passivate,self #remain idle until customer is ready
Lab.Idle.remove(self)
Lab.Busy.append(self)
while Lab.Queue != []: #perform while customers in queue
P = Lab.Queue.pop(0) # get customer
#Lab.hQ.append(len(Lab.Queue))
ServiceRate2 = 1.0/(P.Severity) #service rate is recipricol of mean service time #### for Lab
ServiceTime = G.Rnd.expovariate(ServiceRate2)
Lab.Wholetime.append(now() - P.ArrivalTime + ServiceTime)
yield hold,self,ServiceTime #perform job
#Lab.Wholetime.append(now() - P.Arriv)
Lab.NDone += 1
Intake.i -= 1 ## new new new bed
Lab.Busy.remove(self)
Lab.Idle.append(self)