Back to trackLesson 1 of 25

Release Schedule 1: Your First Simulation

Uses Only Free-Tier SpiceGrinder

Problem statement

A team has to tell the business when a release will ship. Before we model the whole project, we start with one task: the design phase. Ask the designer how long it will take and you don’t get one number, you get three: at best 5 days, most likely 8, at worst 15.

“About 8 days” is the most likely answer, but it isn’t the typical one, and it says nothing about how often the task runs long. So the questions are: how long does design take, typically, and how often does it run past 10 days?

The model

Three numbers like that are exactly what a Triangular distribution takes: a minimum, a most likely value (the mode) and a maximum. One node is the whole model.

<?xml version="1.0" encoding="UTF-8"?>
<dataset columns="design" seed="101">
	<root node="Design"/>
	<nodes>
		<Triangular name="Design" min="5" mode="8" max="15"/>
	</nodes>
</dataset>

Every row the model produces is one possible way the design phase could go: one trial. Grind it 1,000 times and we have 1,000 trials to ask questions of.

grind --count 1000 first-simulation.xml

The first rows (samples/simulation/first-simulation.xml in your own install, if you want to reproduce this; leave the seed at 101 and you get exactly these values):

12.604509025673156
11.812076882734052
11.415559358701438
8.67586147638826
11.374110107415689
6.475047083420846
7.086306877634829
13.49232169017597

Reading the results

One thousand numbers is not an answer yet; we have to ask them questions. Sort them, take the middle one, and count how many are above 10:

QuestionAnswer from 1,000 trials
Median duration9.09 days
Mean duration9.28 days
Share of trials over 10 days33.6%

Notice that none of these is 8. The mode is the single most likely value, but the triangle is lopsided: the worst case is 7 days past the mode and the best case only 3 days before it, so the typical outcome sits above 8, and about one run in three takes longer than 10 days. A single estimate of “8 days” would have hidden both facts.

A histogram of the 1,000 trials in one-day bins from 5 to 15 days, with the median at 9.09 and the mean at 9.28 marked, the bars above 10 days shaded and labeled 33.6%, and the exact triangle drawn over the bars

Same run, or a new batch

The seed is in the file, so the same command always gives the same 1,000 rows, byte for byte. That is what makes a simulation something you can show to someone else and check. Change the seed (grind --seed 2 ...) and you get a different 1,000 trials: a new batch drawn from the same task.

Do that ten times and look at the share over 10 days each time. You don’t have to pick the seeds: grind --no-seed ... lets SpiceGrinder choose a fresh one every run (it prints the seed it used). Ours were seeds 1 to 10, so you can reproduce them exactly:

seed   1     2     3     4     5     6     7     8     9     10
      39.8% 35.9% 36.1% 35.4% 35.4% 35.9% 33.4% 33.5% 33.9% 36.8%

The ten answers disagree, and that is not a bug. Each batch is a sample, and a sample of 1,000 carries about 1.5 percentage points of noise (the standard error, sqrt(p(1-p)/n), is 0.015). The ten estimates scatter around 35.6% with a spread of 1.9 points. So the honest answer to “how often does design run past 10 days” is “about 36%, give or take 3 points”, not “33.6%”. Lesson 5 comes back to how many trials are enough.

The ten estimates of the share over 10 days as dots, one per seed, scattered around the exact 35.7% inside the band expected from batches of 1,000 trials

The companion page draws both figures from these same runs and lets you switch between the batches.

Check: does the answer match the math?

A triangular distribution can be worked out exactly, and a simulation should agree with it. With a minimum of 5, a mode of 8 and a maximum of 15:

  • the chance of going over 10 days is (15 − 10)² / ((15 − 5) × (15 − 8)) = 25/70 = 35.7%;
  • the mean is (5 + 8 + 15) / 3 = 9.33;
  • the median is 9.08.

Our 1,000 trials gave 33.6%, 9.28 and 9.09. All three are within sampling error of the exact values (the 33.6% is 1.4 standard errors below 35.7%). Checking a simulation against something you can compute by hand is the habit to build first; every lesson in this track ends with one.

What this gives you: an answer as a distribution instead of a single number, “the median is about 9 days and one run in three goes over 10”, plus a run you can replay exactly and a way to tell sampling noise from a real difference.

One task is not a project, and a triangle is only one of the shapes an estimate can take. The next lesson adds the rest of the tasks and chooses a distribution for each on purpose.