requesting multiple resources at the same time, but running for different duration

92 views
Skip to first unread message

Fanwang Meng

unread,
Mar 20, 2023, 8:45:09 PM3/20/23
to python-simpy
Hi, friends of simpy community.

I was trying to simulate a factory manufacturing different products with different machines with `simpy`. For each product, we will need to allocate different machines for the production. For example, the first product will ask for machine 1, 2, 5 sequentially and the second product requires machine 2, 3, and 5. For my case, I will given a list of products we are going to manufacture and the corresponding information to make the products. One example is shown below.

tmp.png


My situation was unlike most `simpy` simulations. I want to simulate the process of the given list of procedures (with information on the machine and running time). Please note that the given list of processes comes with unfixed lengths, which is saying the program does not know how many events and which resources to allocate beforehand.

My problem is how to deal with the event dependencies and how to deal with requesting resources for the cases shown in the figure. A simplified example is to use `ExitStack` as a generalized way of the context manager to request resources to run for the same duration, e.g. [Requesting multiple resources simultaneously](https://groups.google.com/g/python-simpy/c/MO-U4ub_o64). But for my case, the dependent events (e.g. A2 and A3 in the first workflow) may run for a different duration. One may think that I can request the maximum running time out of A2 and A3. But this leads to undesired resource waste.

Any comments and code snippets would be appreciated. I am quite new to simpy, but find it useful and interesting. Thank you very much!

Sean Reed

unread,
Jul 29, 2023, 1:22:51 PM7/29/23
to python-simpy
Can't you just request a machine resource for each task once it's predecessors (in the machine sequence graph for a product) are complete? In other words, once a task is complete, release that machine resource, then check if all predecessor tasks of each successor task have been completed, and if so, request the machine resource for that task successor task. 
Reply all
Reply to author
Forward
0 new messages