How do I draw order sizes from my own data?¶
Order sizes are whole numbers, and you may know either their range or their measured shares. DiscreteUniform covers the first, EmpiricalDiscrete the second. The script charges a minute per item.
from nagasim import build as nb
def busy_with(sizes):
"""A packer needs one minute per item in the order."""
m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Packer")
orders = m.create(distribution=nb.Exponential(rate=1 / 4))
orders >> m.process(resource_name="Packer", distribution=sizes) >> m.dispose()
return m.run(replications=10, seed=1).kpi("resource/Packer/Usage % (snapshot)")
# Any whole number from 1 to 6, each equally likely: mean 3.5, so 3.5 in 4 is 88% busy.
print(f"DiscreteUniform(1, 6): {busy_with(nb.DiscreteUniform(low=1, high=6)):.0f}% busy")
# Your own counts: half the orders have 1 item, 30% have 2, 20% have 5. Mean 2.1, so 53% busy.
own = nb.EmpiricalDiscrete(values=[1, 2, 5], probs=[0.5, 0.3, 0.2])
print(f"EmpiricalDiscrete 1/2/5: {busy_with(own):.0f}% busy")
Save it as recipe-order-sizes.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
DiscreteUniform(1, 6): 87% busy
EmpiricalDiscrete 1/2/5: 52% busy
How it works¶
DiscreteUniform(low, high)makes each whole number fromlowtohighequally likely; 1 to 6 has a mean of 3.5.EmpiricalDiscrete(values, probs)returns each value with the share you measured, here 1, 2 and 5 with 50%, 30% and 20%.- Their means, 3.5 and 2.1, give loads of about 87% and 52% at one order every 4 minutes.
Elements used¶
- Distributions: DiscreteUniform, EmpiricalDiscrete, Exponential.
- Blocks: CREATE, PROCESS, DISPOSE.
- Python:
Model.
Back to all recipes.