我正在使用Simpy软件包来构建医院模拟。我有一个优先级资源,我将需要监视该资源,以便分别记录每个请求的优先级(队列中使用资源的每个优先级有多少个请求)。
在您只想监视较低优先级的情况下,您可以执行以下操作(这样做是为了使较高优先级的请求只是阻止更改资源中可用容量的阻止程序):< / p>
class DynamicMonitoredResource(simpy.PriorityResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.data = []
self.patients = 0
self.blockers = 0
self.patients_queue = 0
self.patients_count = 0
def request(self, *args, **kwargs):
self.patients += 1
self.patients_queue = max(0, self.patients - (self.capacity - self.blockers))
self.patients_count = self.patients - self.patients_queue
self.data.append((env.now, self.patients_queue, self.patients_count))
return super().request(*args, **kwargs)
def release(self, *args, **kwargs):
self.patients -= 1
self.patients_queue = max(0, self.patients - (self.capacity - self.blockers))
self.patients_count = self.patients - self.patients_queue
self.data.append((env.now, self.patients_queue, self.patients_count))
return super().release(*args, **kwargs)
def request_blocker(self, *args, **kwargs):
self.blockers += 1
return super().request(*args, **kwargs)
def release_blocker(self, *args, **kwargs):
self.blockers -= 1
return super().release(*args, **kwargs)
这有效,但不能解决更普遍的问题。有没有人建议如何做?