Skip to content

How do I use a histogram from a time study as a service time?

A time study gives bins and the share of jobs in each, not a formula. EmpiricalContinuous draws from exactly that histogram. The script gives a bench three bins and checks the load against the mean worked out by hand.

from nagasim import build as nb

# A time-study histogram: 50% of jobs took 0-2 minutes, 30% took 2-5, 20% took 5-10. `values` are the
# bin edges (one more than `probs`); a draw picks a bin by its weight, then a point inside it.
histogram = nb.EmpiricalContinuous(values=[0, 2, 5, 10], probs=[0.5, 0.3, 0.2])
mean = 0.5 * 1 + 0.3 * 3.5 + 0.2 * 7.5      # each bin's midpoint, weighted

m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Bench")
jobs = m.create(distribution=nb.Exponential(rate=1 / 6))
jobs >> m.process(resource_name="Bench", distribution=histogram) >> m.dispose()

results = m.run(replications=10, seed=1)
print(f"mean service by the bin midpoints: {mean:.2f} minutes, so {mean / 6 * 100:.0f}% busy")
print(f"bench busy in the run:             {results.kpi('resource/Bench/Usage % (snapshot)'):.0f}%")

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

mean service by the bin midpoints: 3.05 minutes, so 51% busy
bench busy in the run:             51%

How it works

  1. values are the bin edges, one more than probs, and probs are the share of jobs in each bin.
  2. A draw picks a bin by its weight and then a point inside it, so the result is continuous and not a resample of the points.
  3. The hand mean uses the midpoint of each bin, and the run's load matches it.

Elements used

Back to all recipes.