How do I model the number of lines on an order?¶
An order has a random number of lines, with a known average. A Poisson count suits that. The script makes the delay equal to the count, at one minute per line.
from nagasim import build as nb
# A picking order has a Poisson number of lines (mean 6). The pick takes one minute a line, so the
# delay is the count itself. The Python keyword `lambda` is the parameter name, hence Distribution().
m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Picker")
orders = m.create(distribution=nb.Exponential(rate=1 / 8))
lines = nb.Distribution("Poisson", {"lambda": 6})
orders >> m.process(resource_name="Picker", distribution=lines) >> m.dispose()
results = m.run(replications=10, seed=1)
print(f"picker busy {results.kpi('resource/Picker/Usage % (snapshot)'):.0f}% of the time (6 of every 8 minutes is 75%)")
print(f"mean wait for the picker {results.kpi('resource/Picker/Time in Queue Avg'):.1f} minutes")
Save it as recipe-poisson-lines.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
picker busy 76% of the time (6 of every 8 minutes is 75%)
mean wait for the picker 10.2 minutes
How it works¶
Poisson(lambda)returns a whole number with meanlambda; the keywordlambdais reserved in Python, so the script usesnb.Distribution.- Here one minute per line means a 6-minute mean job every 8 minutes, so the picker is busy about 75% of the time.
- Counts are not durations, so scale them by a time per unit as the delay does here.
Elements used¶
Back to all recipes.