Discrete-event simulation in plain Python
Five lessons, each with exercises and a quiz
A kiosk has one barista. Will there be a line, how long is the wait, and does a second barista help more with one shared line or with two? Build small simulations with only what comes with Python, check each against a known formula, and see that a simulation is a short program with a clock, a list and a loop.
For Students who are comfortable with variables, if, loops, lists, dictionaries and functions, as taught in a first programming course. No probability or queueing theory needed.
The 5 lessons
- StartDiscrete-event simulation in plain Python
- 1One server, customer by customer
M/M/1, random times with
random.expovariate, a queue simulated by one short loop with no clock, and why a line gets long even when the barista can keep up. - 2One server with an event list
A clock, a state and a list of future events: the same queue, the time-weighted length of the line, Little's law, and customers who walk away from a long line.
- 3Several servers, customer by customer
M/M/c with one free time per server, Erlang C to test against, and why one shared line beats separate lines.
- 4Several servers with an event list
The event loop with several servers, utilization from busy time, and a new behavior as a new kind of event.
- 5From Python to Quisim
Replications, confidence intervals and warm-up, what a real study still needs, and how your code maps to Quisim's blocks.