How do I model a time that is a fixed part plus a random part?¶
A repair is a fixed diagnosis followed by a random fix, and no single distribution says that. CustomExpression takes any expression. The script uses 2 + EXPO(3) as the bay's repair time.
from nagasim import build as nb
# A repair is a fixed 2-minute diagnosis plus an exponential fix with a mean of 3 minutes. No single
# distribution says that, but an expression does. UNIF, EXPO, NORM, TRIA and DISC are available.
repair = nb.CustomExpression(expression="2 + EXPO(3)")
m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Bay")
cars = m.create(distribution=nb.Exponential(rate=1 / 8))
cars >> m.process(resource_name="Bay", distribution=repair) >> m.dispose()
results = m.run(replications=10, seed=1)
print(f"bay busy {results.kpi('resource/Bay/Usage % (snapshot)'):.0f}% (mean repair 5 minutes in 8 is 62%)")
Save it as recipe-formula-time.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
bay busy 63% (mean repair 5 minutes in 8 is 62%)
How it works¶
CustomExpressionevaluates its text each time a time is needed, soEXPO,UNIF,NORM,TRIAandDISCare all available.- The mean of
2 + EXPO(3)is 5 minutes, so one car every 8 minutes loads the bay to about 62%. - It cannot be fitted from data, so use it for a known structure and a named family for a fitted shape.
Elements used¶
- Distributions: CustomExpression, Exponential.
- Blocks: CREATE, PROCESS, DISPOSE.
- Python:
Model.
Back to all recipes.