2

I am new to Simpy and I am having troubles figuring out how to model a process scheduler that has complex dependencies.

High-level summary of my problem:

  • I have a warehouse that receives boxes containing items through an entrance. The boxes are put in a queue where they wait to be processed.
  • Each box has a destination room and must be shipped there using a conveyor belt. A conveyor belt services multiple rooms.
  • An operator looks at the boxes in the queue and puts a box on the appropriate conveyor belt only if both the belt and the destination room are available. The operator sends the boxes in order but skips the boxes that cannot be processed.
  • Once the box is opened inside a room, it takes a certain amount of time to store the object. During this time, the room cannot receive other boxes.
  • After the object is stored, the empty box is sent to the exit of the warehouse using the same conveyor belt it came in.
  • The operator has knowledge at all times of which conveyor belts and rooms are free.

My question is how to model this operator. I did not find so far an elegant way to do this in Simpy. I essentially want to have a process that wakes up only when the following three conditions hold: a) a room is free; b) there is a box in the queue addressed for this room, and c) the belt for getting to the room is free.

Any idea, advice or pointer to an existing example are greatly appreciated. Thank you!

Radu
  • 1,098
  • 1
  • 11
  • 22

2 Answers2

0

Here's another StackOverflow question on simpy that might get you closer to a solution: How can I have a process wait for multiple resources?

If I understand that answer correctly, you can treat events like messages in a queue: peek at them, but put back the ones you don't like. This means you can wait for an entire list of events, including .get()'s and your timeout, and when any of them trigger, inspect those. You can act on some of them and discard the rest (leaving them "unprocessed" for another process or iteration). This way, if your timeout even is in the list, you could then check the status of your other three events and act accordingly.

-1

You might want to take a look at

https://simpy.readthedocs.io/en/latest/topical_guides/resources.html#res-type-store

 from collections import namedtuple

 Machine = namedtuple('Machine', 'size, duration')
 m1 = Machine(1, 2)  # Small and slow
 m2 = Machine(2, 1)  # Big and fast

 env = simpy.Environment()
 machine_shop = simpy.FilterStore(env, capacity=2)
 machine_shop.items = [m1, m2]  # Pre-populate the machine shop

 def user(name, env, ms, size):
     machine = yield ms.get(lambda machine: machine.size == size)
     print(name, 'got', machine, 'at', env.now)
     yield env.timeout(machine.duration)
     yield ms.put(machine)
     print(name, 'released', machine, 'at', env.now)


 users = [env.process(user(i, env, machine_shop, (i % 2) + 1))
          for i in range(3)]
 env.run()

Regarding the box and the room, i suggest you use 2 different resource - store(resource class) to model it.

a) a room is free; ( Check whether resource store for the room is empty)
b) there is a box in the queue addressed for this room,( Define the box and room in the namedtuple) , you can use get_queue to check

c) the belt for getting to the room is free.(Similar to point a )

Nic
  • 44
  • 3
  • Thanks for the reply. Unfortunately it does not address my question. Probably I was not clear enough. I know how to use a FilterStore but I dont know how to wake up only when all 3 events are simultaneously true. It seems to me that in Simpy events can be triggered at different times when part of a composite condition. For example, I currently loop over the belts and yield on a condition event `yield (haveBoxEvent & haveRoomEvent & haveBeltEvent) | someTimeOut`. This is not working properly as the timeout is not mutually exclusive with the other AND-ed events in between ( ... ). – Radu Nov 01 '19 at 22:30
  • For example, if the timeout triggers some (but not all) of the other events can also be triggered. For example, the belt can be acquired first, then the box, but then the timeout expires before the room becomes free. This means that when I wake up I cannot do any useful work but I have blocked some resources (e.g., extracted a box from the queue) which messes up the simulation. – Radu Nov 01 '19 at 22:35