1

A Simpy-Store is filled with elements {0}...{9}

car_Fleet = simpy.Store(env, capacity=10)
i = 0
for i in range(10):
    car_Fleet.put({i})
    i += 1

When requesting an item from that store

    car_id = yield car_Fleet.get()
    print(car_id)

the print statement returns the "value" of the Simpy-Store item, for example {4}

But when using a simpy condition event

with car_Fleet.get() as req:
    patience = 2
    results = yield req | env.timeout(patience)

    wait = env.now - arrive

    if req in results:
        .....
        print(req)
        .....

    else:
        # We quit
        ...

The print(req) (also print(req.value) ) statement returns "<StoreGet() object at 0x7f8e2681da50>" and not the value of the requested item as in the code above. Also print(results) returns: <ConditionValue {<StoreGet() object at 0x7fe1c37f4b80>: <StoreGet() object at 0x7fe1c37f41f0>}>

How can one access the value instead of the address of the item requested from the store?

Edit: Michaels comment solved the problem. The results variable can be accessed as follows. By using results[req] one can retrieve the name of the requested item. When returning an Item to the store it's also important to pass results[req] with carFleet.put .

MacUserXL
  • 35
  • 5
  • The goal is to have multiple processes requesting a "car" from the "car-fleet". Processes should wait until a car becomes available, or if it takes too long, abort their request. I need the name "{1}" of the car for further logging purposes. To my understanding i need the yield statement in order to allow a process to wait for a car to return as long the patience is not triggered. – MacUserXL Dec 18 '22 at 15:34
  • 1
    your results var is a ordered dictionary. conditional events can return more then one event. Your store.get and timeout can fire at the same time. results will have a entry for every event fired. try iterating over the dict and printing each dict entry. – Michael Dec 18 '22 at 17:04
  • 1
    instead of print(req), try print(results[req]) – Michael Dec 18 '22 at 19:42

0 Answers0