Why there is no PriorityContainer?
Hi simpy maintainers,
Though simpy offers priority-based implementation for Resource and Store resource types, there is not priority-based implementation for Container type. For my use-case, I required my ContainerGet requests to have associated priority so that high priority requests are fulfilled before low priority ones and not follow the FIFO ordering. I was able to achieve my desired result by a simple implementation of a PriorityContainer resource type.
class PriorityContainerGet(ContainerGet):
def __init__(
self,
container: Container,
amount: ContainerAmount,
priority: int = 0,
):
self.priority = priority
self.time = container._env.now
self.key = (self.priority, self.time)
super().__init__(container, amount)
class PriorityContainer(Container):
PutQueue = list
GetQueue = SortedQueue
def __init__(
self,
env: Environment,
capacity: ContainerAmount = float('inf'),
init: ContainerAmount = 0,
):
super().__init__(env, capacity, init)
if TYPE_CHECKING:
def put( # type: ignore[override]
self, amount: ContainerAmount
) -> ContainerPut:
return ContainerPut(self, amount)
def get( # type: ignore[override]
self, amount: ContainerAmount, priority: int = 0
) -> PriorityContainerGet:
return PriorityContainerGet(self, amount, priority)
else:
put = BoundClass(ContainerPut)
get = BoundClass(PriorityContainerGet)