Skip to content
Advertisement

How would I code a simulation of 2 machines with a buffer using simpy?

I am new to simulation and am going through the simpy documentation. I kind of get the gist of it but cannot really seem to grasp how to translate the production line that I want to simulate.

I am trying to simulate a production line with m number of machines and m-1 number of buffers.

The machines basically work the same:

  • Processes units at speed s per state
  • random distribution of states and time in said state
  • Is there starvation/blockage from the buffers?

The buffers all work the same:

  • Receives units from previous machine
  • Loses units from next machine
  • capacity(t) = capacity(t-1) + (input previous machine) – (output next machine)
  • Capacity(t) <= Max capacity

Now I get that the first steps of simulation are baby steps so I need to make a simple model first. What I am looking to create then using simpy is a 2 machine and 1 buffer system with fixed processing speeds, failure rate and maintenance speeds:

  1. An unlimited capacity of units is delivered to machine 1.
  2. Machine 1 processes at speed s, fails after f minutes and is repaired after r minutes. If buffer is full then Machine 1 stops.
  3. Buffer gets filled by Machine 1 and emptied by Machine 2. There is a max capacity.
  4. Machine 2 processes at min(speed s, capacity buffer) fails after f minutes and is repaired after r minutes. If buffer is empty then Machine 2 stops.
  5. Unlimited buffer capacity after Machine 2.

EDIT: The answer I received from @Michael works very well, I tried playing around with failures and maintenance. The machine seems to fail and repaired, but keeps failing at multiples of the time to failure (which I need to fix). The code I am using is as follows:

JavaScript

Advertisement

Answer

Got bored of my work, so I made some small changes to fix your code. I think it even works. One final note, more then one machine can use the same buffer. so a pool of machines can process out of the same one buffer. This is what I do instead of using a simpy.resurce for a resource pool

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement