How do I limit the work waiting between two machines?¶
A buffer between two machines holds a few parts. When it is full the machine before it stops and waits. The script tries a buffer of 1, 5 and 50 parts between a cutter and a welder.
from nagasim import build as nb
def line_with_buffer(capacity):
m = nb.Model(time_limit=2000, warmup=200)
m.add_resource(name="Cutter")
m.add_resource(name="Welder")
cut = m.process(resource_name="Cutter", distribution=nb.Exponential(rate=1.0))
weld = m.process(resource_name="Welder", distribution=nb.Exponential(rate=1.0))
# Parts arrive at 0.8 a minute, each machine averages 1 a minute, and the buffer holds `capacity` parts.
m.create(distribution=nb.Exponential(rate=0.8)) >> cut >> m.buffer(capacity=capacity) >> weld >> m.dispose()
return m.run(replications=5, seed=1)
print("buffer parts finished cutter blocked %")
for capacity in (1, 5, 50):
results = line_with_buffer(capacity)
summary = results["buffer_summary"]
blocked = summary["Blocked %"].dropna().mean()
print(f"{capacity:>6} {results.kpi('system/Total Entities Completed'):14.0f} {blocked:15.1f}")
Save it as recipe-buffer-wip.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
buffer parts finished cutter blocked %
1 1332 24.7
5 1428 8.8
50 1428 0.0
How it works¶
m.buffer(capacity=n)is a finite store between two blocks; the upstream machine is blocked while it is full.- A buffer of 1 blocks the cutter a quarter of the time and loses about 100 finished parts. A buffer of 5 finishes as many as 50.
- So the first few places matter most, and you find the right size by running a few.
Elements used¶
Back to all recipes.