Skip to content

Examples

Every example is a single file in examples/ with a module-level model and a main(replications=...) function. All data is synthetic. Run one with python examples/<name>.py, or all of them quickly with python scripts/run_examples.py. They also work with the CLI:

simulsi run examples/hospital.py -p doctors=4
simulsi validate examples/manufacturing.py
simulsi visualize examples/bank_queue.py --out plots

Notebooks

Three tutorial notebooks in examples/notebooks/ walk through the main workflow (they are executed in CI):

  1. 01-first-model.ipynb - build a model, run it, read the metrics, trace and plot a run.
  2. 02-experiments-and-decisions.ipynb - replications, comparisons with adjusted p-values, run-until-precision, ranking and selection, an HTML report.
  3. 03-inputs-sensitivity-optimisation.ipynb - fit an input distribution, Morris screening, a Gaussian-process surrogate and cost optimisation.

1. Bank queue - bank_queue.py

Poisson arrivals, log-normal service times (specified by mean and coefficient of variation via LogNormal.from_moments), a pool of tellers, and customers who renege after patience minutes (sim.request(..., patience=...)).

Analyses: waiting time, time-average queue length, teller utilization and the reneging fraction, for baseline / four tellers / lunch rush / both, compared with paired CIs. It ends with replication advice: how many replications are needed for a +-5% estimate of the mean wait.

2. Emergency department - hospital.py

Patients get an acuity level (Categorical), see a triage nurse, wait for a treatment room and then a doctor. Rooms and doctors use the "priority" discipline, so critical patients overtake routine ones. Patients keep their room while waiting for and seeing the doctor - a typical source of hidden capacity loss.

Analyses: door-to-doctor time by acuity, the share of patients seen within their acuity's target (a service level), doctor and room utilization. It compares an extra doctor with extra rooms - which one helps depends on which resource binds.

3. Warehouse - warehouse.py

Orders arrive with a time-varying rate (a non-homogeneous Poisson process generated by thinning), each with a Poisson number of lines. Pickers walk and pick, then hand orders to packers through a Queue buffer.

Analyses: orders shipped, backlog (time-weighted open orders), order cycle time and picker/packer utilization, comparing a seventh picker against faster picking from better slotting.

4. Manufacturing - manufacturing.py

Two machines in series with a finite buffer. A full buffer blocks machine 1 while it still holds the finished job. Each machine fails at random (FailureProcess); repairs need a technician (RecoveryProcess(crew=...)) and interrupt the job in progress, which resumes its remaining work afterwards.

Analyses: throughput, WIP, cycle time, availability, buffer level and a CostModel (revenue per job, WIP holding cost, technician wages, repair costs). Scenarios: preventive maintenance (longer MTBF), a bigger buffer, a second technician.

5. Transportation - transportation.py

Buses circulate around a loop of stops. Passengers queue at each stop with a random destination; a bus alights passengers, boards as many as fit, dwells proportionally to boardings and drives on.

Analyses: passenger waits (mean, p95), passengers left behind by full buses (congestion) and load factor (capacity utilization). It compares a fourth bus with bigger buses that have the same total number of seats - frequency against capacity.

6. Aviation - aviation.py

A synthetic day of arrivals in two banks plus background traffic. Flights land with log-normal delays, wait on the taxiway if no gate is free (a gate conflict), turn around and depart. Long-stay aircraft are towed to a remote stand by a tug and towed back before departure. A weather scenario closes gates for part of the second bank (capacity_reduction).

Analyses: taxiway hold time, share of flights with a gate conflict, departure delay (mean, p95), tows and gate utilization for baseline, weather, no towing and both. This is a demonstration of generality, not an airline planning tool, and it uses no real airline data.

Smaller examples

  • queue.py - M/M/c in 30 lines, compared with the Erlang-C formula.
  • simulsi init - the starter "service desk" project with a YAML experiment and cost model.
  • The getting started and concepts pages contain runnable snippets. They are executed by the test suite, so they stay correct.