I'm currently working on a problem where I need to use simpy stores to model a changing quantity of resource. This resource is used throughout the simulation via store.get() requests.
I've been following this article to help me but I don't think the requests I'm making from the store are being prioritised as expected.
I'd like the requests to first be prioritised on an FIFO basis, and when the request is made at the same time, for it to be based on another priority number passed as a part of the get request (i.e. get(priority=1) where the lower the number, the higher the priority).
I've dropped the code I'm using below. I think the issue is with the implementation of get_queue.
Any advice is welcome! Looking for some simpy expertise on this please :) Thanks!
class PriorityGet(simpy.resources.base.Get):
def __init__(self, resource, priority: int, preempt=True):
self.priority = priority
"""The priority of this request. A smaller number means higher
priority."""
self.resource = resource
self.preempt = preempt
self.time = resource._env.now
self.usage_since = None
"""The time at which the request succeeded."""
self.key = (self.time, self.priority, not self.preempt)
"""Key for sorting events. Consists of the priority (lower value is
more important), the time at which the request was made (earlier
requests are more important)"""
super().__init__(resource)
class PriorityBaseStore(simpy.resources.store.Store):
get_queue = simpy.resources.resource.SortedQueue
get = BoundClass(PriorityGet)