1. Discrete Event Simulation
What a discrete-event simulation consists of — entities, events, the event list, the clock, and statistical counters — walked through on a single-server FCFS queue.
1.1. Stochastic Dynamic Systems
A discrete-event simulation model consists of:
- entities — the objects in the system
- attributes — properties of an entity
- state — variables describing the system at time
- events — instants at which the state changes
- event list — the scheduled future events, in time order
- clock — the current simulated time
- statistical counters — running totals used to compute the outputs
1.2. Single-server queueing system with FCFS service discipline
Here is an example:
flowchart LR
A([arrival]) --> Q[waiting line] --> S((server)) --> D([departure])
Objective. Estimate the average delay of a customer, where
Let be the delay of the -th customer. Then .
Entities: customer, server
Attributes: arrival time of a customer; service time of a customer
State: = number of customers in the system at time ; = status of the server
Events: arrival, departure, end of simulation
Statistical counters: number of customers delayed, total delay , area under , area under
1.2.1 Notation
- : interarrival time; is the arrival time (), so the 2nd customer arrives at .
- : service time.
- : departure time (the figure writes ; it should be ).
- Delay : time spent in the queue, excluding service.
- Waiting time : time spent in the system, including service, so .
Under FCFS, customer begins service when customer departs (or immediately, if the server is idle):
1.2.2. Sample path (from the board, )
| 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| 55 | 32 | 24 | 40 | 12 | |
| 55 | 87 | 111 | 151 | 163 | |
| 43 | 36 | 34 | 16 | – | |
| 98 | 134 | 168 | 184 | – | |
| 0 | 11 | 23 | 17 | 21 |
gantt
title Single-server queue, T = 180
dateFormat X
axisFormat %s
tickInterval 20second
section Customer 1
in service :done, c1s, 55, 98
section Customer 2
in queue :active, c2q, 87, 98
in service :done, c2s, 98, 134
section Customer 3
in queue :active, c3q, 111, 134
in service :done, c3s, 134, 168
section Customer 4
in queue :active, c4q, 151, 168
in service :done, c4s, 168, 184
section Customer 5
in queue :active, c5q, 163, 184
Equivalently, as a step function:
| interval | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 1 | 2 | 1 | 2 | 3 | 2 | |
| 0 | 0 | 1 | 0 | 1 | 0 | 1 | 2 | 1 |
where is the number in the queue.
1.2.3. Time-average quantities (M/M/1 queue)
Average number in system.
Average number in queue.
Server utilization (proportion of time the server is busy).
If and , this is the queue (Markovian, i.e. exponential, interarrival times; exponential service times; one server).
1.2.4. How the simulation is driven
flowchart LR
U["random numbers<br/>U ~ U(0,1)"] --> Tr[transformation]
In[input distributions] --> Tr
Tr --> V["random variates<br/>X_i, Y_i"] --> P[simulation program] --> O["outputs<br/>D_1, D_2, ..., W_1, W_2, ..."]
1.3. Simulation of an Inventory System (single commodity)
Problem
flowchart RL
C([customer]) -->|demand| W["warehouse: inventory<br/>(managed by the inventory manager)"]
W -->|order| SUP([supplier])
SUP -.->|delivery, after the lead time| W
- When to order?
- How much to order?
(Textbook p. 48, §1.5.)
The times between successive demands are i.i.d. with month (on average demands per month).
The sizes of demands are i.i.d. (and independent of the demand times) with
At the beginning of each month, the inventory level is reviewed and a decision is made whether to place an order and how much to order. If an order is placed, the order lead time (delivery time) is uniformly distributed between 0.5 and 1 month, .
Let = the inventory level at the beginning of a month. The following policy is employed. Let be the order amount:
So answers when to order (order as soon as the level at a review is below ), and answers how much (order up to ).
could be negative (demand backlog): a demand larger than the stock on hand is not lost; the excess is backlogged and filled later. When an order arrives, it first clears the backlog, and the rest goes into inventory.
One can show that for inventory models of this kind (a fixed cost per order, plus per-item ordering, holding and backlog costs) the optimal policy takes this form (Scarf, 1960). It is a theorem for this class of models, not for every inventory system. Here the form is taken as given, and simulation is used to compare different values of and .
Cost structure
If an order is placed, the cost is (no order, no cost).
is called the setup cost. is the per-unit ordering cost: the price paid for each item ordered, so this part grows with the order size, whereas is paid once per order however many items are ordered (paperwork, transportation). With the textbook’s values , , ordering items costs . Because of , many small orders are expensive, which pushes toward ordering rarely and in large amounts.
There is a holding cost of per item per month held in inventory (penalizes high inventory levels). Textbook: .
There is a penalty cost of per item in backlog per month (penalizes negative inventory levels). Textbook: (written there).
Simulation
States: inventory level at time , ; and the amount of the outstanding order, if any. (The lead time is at most 1 month and reviews are monthly, so at most one order is outstanding at a time.)
Events: demand arrival, order arrival, inventory evaluation (at the beginning of each month), end of simulation.
Statistical counters: total ordering cost, area under , area under (defined below).
Let : items physically held in inventory at time .
: items in backlog at time (demand already received but not yet filled).
Why separate? , and at any time at most one of the two is non-zero. They are charged at different rates: per item per month on hand, per item per month in backlog. Averaging itself would let the positive and negative parts cancel (10 items in stock for half the time and 10 items short for the other half averages to , which would look free), and two different prices could not be applied.
Average number of items held in inventory per month:
average number of backlogged items per month:
where is the number of months simulated. These are time averages, computed from areas just like the area under in §1.2.3.
where the average ordering cost per month is .
The simulation is run for several candidate pairs , and the pair with the smallest average cost per month is preferred. (Textbook: months, starting from with no outstanding order; nine pairs are compared.)
Generating the inputs (derivations and a worked example: §4.7):
- interdemand time: (exponential with mean );
- demand size: discrete inverse transform with , , , : return if , else if , else if , else ;
- lead time: , i.e. .