Skip to content

How do I keep a skewed time between a minimum and a maximum?

A filling step can take at most 10 minutes and never less than 2, and it is usually closer to the top. JohnsonSB lives on a fixed interval and can be skewed, while JohnsonSU has no bounds and suits heavy tails. The script runs a filler with each.

from nagasim import build as nb
from nagasim.core.distributions import distribution_mean


def busy_with(fill):
    m = nb.Model(time_limit=4000, warmup=0)
    m.add_resource(name="Filler")
    m.create(distribution=nb.Exponential(rate=1 / 12)) >> m.process(
        resource_name="Filler", distribution=fill) >> m.dispose()
    return m.run(replications=10, seed=1).kpi("resource/Filler/Usage % (snapshot)")


# A fill takes between 2 and 10 minutes, mostly towards the long end: JohnsonSB lives on a fixed
# interval. JohnsonSU, set to a similar centre, has no bounds, so its tails can pass 2 and 10.
bounded = nb.JohnsonSB(a1=1, a2=1, min=2, max=10)
unbounded = nb.JohnsonSU(a=0, b=1.5, loc=7, scale=2)
for label, dist in (("JohnsonSB", bounded), ("JohnsonSU", unbounded)):
    mean = distribution_mean(dist.name, dist.params)
    print(f"{label}: mean {mean:.2f} minutes, filler busy {busy_with(dist):.0f}%")

Save it as recipe-bounded-yield.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.

JohnsonSB: mean 7.57 minutes, filler busy 64%
JohnsonSU: mean 7.00 minutes, filler busy 59%

How it works

  1. JohnsonSB(a1, a2, min, max) stays inside [min, max], and the shape parameters set the skew.
  2. JohnsonSU(a, b, loc, scale) is a flexible fit with no bounds, so a draw below zero is cut to zero.
  3. Both are set to a similar centre, around 7 minutes, so the two fillers are close in load.

Elements used

Back to all recipes.