How do I model retesting until a part passes?¶
A part is tested again until it passes, and each try costs the same time. The number of tries is Geometric. If you instead count the rejects before a set number of good parts, it is Negative binomial. The script runs both.
from nagasim import build as nb
def busy_with(rework):
"""Percent of time the test bench is busy when each attempt or reject takes one minute."""
m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Bench")
parts = m.create(distribution=nb.Exponential(rate=1 / 4))
parts >> m.process(resource_name="Bench", distribution=rework) >> m.dispose()
return m.run(replications=10, seed=1).kpi("resource/Bench/Usage % (snapshot)")
# Geometric: attempts until the first pass, mean 1 / 0.5 = 2 minutes, so 2 in 4 is 50% busy.
print(f"Geometric(p=0.5): {busy_with(nb.Geometric(p=0.5)):.0f}% busy")
# NegativeBinomial: rejects before 3 good parts, mean 3 * 0.2 / 0.8 = 0.75 minutes, so 19% busy.
print(f"NegativeBinomial(r=3, p=0.8): {busy_with(nb.NegativeBinomial(r=3, p=0.8)):.0f}% busy")
Save it as recipe-retest-attempts.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
Geometric(p=0.5): 50% busy
NegativeBinomial(r=3, p=0.8): 19% busy
How it works¶
Geometric(p)is the number of attempts up to and including the first pass, with mean1 / p.NegativeBinomial(r, p)is the number of failures beforersuccesses, with meanr * (1 - p) / p.- At one minute per try the first loads the bench to 50%, and the second, with its mean of 0.75, to about 19%.
Elements used¶
- Distributions: Geometric, NegativeBinomial, Exponential.
- Blocks: CREATE, PROCESS, DISPOSE.
- Python:
Model.
Back to all recipes.