2

I have a FilterStore and during my simulation there is a queue for the FilterStore.Get event at some times. Now I have two questions:

  1. Is there a way to see the actual elements in the queue, not just the object number? With FilterStore.get_queue I get this output: [FilterStoreGet() object at 0x221a47c6080, FilterStoreGet() object at 0x221a47c6eb8]. But I would like a list with the actual names, for example [1,2,3].

  2. Is there a way to manipulate the queue? I know the elements in the queue are beeing processed with FIFO, but I would like to do LIFO or SIRO.

Ana
  • 51
  • 5

3 Answers3

1

I got an answer to my question on another forum. I will post it here too, because I'm sure someone else will eventually have the same problem.

So it is not possible to manipulate the FilterStore.get_queue directly, but by writing a subclass of the Store, you get a queue that behaves differently (LIFO for example).

class PrependList(list):
def append(self, item):
    self.insert(0, item)

class LCFSStore(Store):
    put = BoundClass(StorePut)
    get = BoundClass(FilterStoreGet) 
    GetQueue = PrependList
Ana
  • 51
  • 5
0
  1. When you get a queue element (with yield), the FilterStore returns the element. Also, you can use a dict to name the elements.

Let´s create 3 barbers:

barberNames = ['Baber A', 'Baber B', 'Baber C']
barberList = [simpy.Resource(env, capacity=1) for i in range(3)]
barberDict = dict(zip(barberNames , barberList))

Now, create a FilterStore to the BarberShop:

barberStore = simpy.FilterStore(env, capacity=3)
barberStore.items = barberNames

If one client of our BarberShop doesn´t want a specific Barber, we just can pick a barber from the created Store:

clientBarber = yield barbeariaStore.get()

If you print clientBarber, you will see his name (as in barberNames)

  1. In this case, our client wants a specific Barber.

Assume that he wants the 'Barber A':

preferBarber = yield barbeariaStore.get(lambda barber : barber == 'Barber A')

Now, preferBarber stores 'Barber A'.

  • Hi Afonso, thank you for your answer, but that was not really what I asked. Maybe it's not really clear what I meant. So if I take your example with the barberstore: imagine a lot of clients requesting a barber with barberstore.get. If there is no item available, a queue will build up. That is the barberstore.get_queue. As soon as an item is available again, the first client in the queue will be the first to get a barber. But I want to change that, so that the last client gets the barber first. – Ana Oct 30 '18 at 07:37
  • I read the simpy documentation, and this is how the get_queue is defined: Queue/list of events waiting to get something out of the resource. And then the definition of the GetQueue: The type to be used for the get_queue. This can either be a plain list (default) or a subclass of it. So I guess I could write a subclass of the FilterStore, and in the case that there is a queue of events, I could define through that subclass which event get triggered first. I just don't know how such a subclass would look like. – Ana Nov 06 '18 at 13:15
0

I got the override working using LIFO like this.

class LIFOStore(Store):
    def _do_get(self, event: StoreGet) -> Optional[bool]:
        if self.items:
            event.succeed(self.items.pop())
        return None