How do I model inspecting a sample from a finite lot?¶
An inspector draws a small sample from a lot with a known number of defectives and does not put the parts back. The defectives found follow a Hypergeometric count. The script charges a minute of paperwork per defective found.
from nagasim import build as nb
# A lot of 50 parts holds 5 defectives. The inspector draws 10 parts without putting any back, and
# each defective found costs one minute of paperwork. Hypergeometric(N, K, n) is the defective count
# of that sample; its mean is n * K / N = 1. Binomial would draw with replacement and overstate the spread.
m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Inspector")
lots = m.create(distribution=nb.Exponential(rate=1 / 4))
found = nb.Hypergeometric(N=50, K=5, n=10)
lots >> m.process(resource_name="Inspector", distribution=found) >> m.dispose()
results = m.run(replications=10, seed=1)
print(f"inspector busy {results.kpi('resource/Inspector/Usage % (snapshot)'):.0f}% (1 minute in 4 is 25%)")
Save it as recipe-lot-sample.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
inspector busy 25% (1 minute in 4 is 25%)
How it works¶
Hypergeometric(N, K, n)is the defectives in a sample ofnfrom a lot ofNthat holdsKof them.- Its mean is
n * K / N, here 1 defective a lot, so the inspector is busy 25% of the time. - A Binomial would draw with replacement and overstate the spread when the sample is a large part of the lot.
Elements used¶
- Distributions: Hypergeometric, Binomial, Exponential.
- Blocks: CREATE, PROCESS, DISPOSE.
- Python:
Model.
Back to all recipes.