Definition · Discrete-event simulationA simulation in which the state changes only at a countable set of event times. The simulator holds the current state, a calendar of events scheduled for future times, and a clock. Each step removes the earliest calendar entry, advances the clock to its time, applies its effect, and schedules any events the new state implies.
The model on this page is the single-server queue the earlier course solved exactly: in each slot an arrival occurs with probability p, and a customer in service completes with probability q, so a service duration is a geometric variate on {1, 2, 3, …}. Both are sampled by inverse transform from the seeded stream, so the run is reproducible and every figure it produces is a fraction.
Definition · Time averageFor a quantity N(t) that is constant between events, the time average over [0, T) is (1/T)∫N(t) dt, which for a step function is the sum of N times the length of each interval, divided by T. It is not the average of the values N took; it is the average weighted by how long it took them.
That distinction costs people real errors. A queue that holds one customer for nine hundred slots and nine customers for one hundred has a time average of 1.8 and an unweighted average over its two distinct states of 5. Only the first is the number anyone wants, and only the first is what the area under the curve gives you.
One run, event by event
Example · The first ten events at p = 2/5, q = 1/2, seed 1Customer 1 arrives at slot 3 and leaves at 4. Customer 2 arrives at 5 with a service of three slots; customers 3 and 4 arrive at 6 and 7 and queue behind it. At clock 8 two events share the instant: customer 2 departs and customer 5 arrives. The departure is taken first, so immediately after it the system holds two, and the arrival then takes it to three. Nothing whatever happens at slots 0, 1, 2, and the clock never visits them.
The tie at clock 8 is not a detail. A simulator that answered “who is in the system at time t?” by testing arrival ≤ t < departure would count the arriving customer as present at the instant the departure is being processed, and its headcount would disagree with its own list of names. The rule — departures before arrivals at the same instant — has to be stated once and then obeyed by every part of the program that asks the question.
The long run, and the exact value it is aiming at
p = 2/5, q = 1/2, single server, first in first out
exact, from the chain: L = 12/5 = 2.4 ρ = p/q = 4/5
one run of 2000 slots, seed 1
customers 776
area under N(t) 4733 slot-customers
time average 4733/2000 = 2.3665
server busy 1593 of 2000 slots = 79.7%
gap to the exact value: 0.0335 below
The gap of 0.0335 is not a defect of the simulation and not a rounding error; there is no rounding anywhere in it. It is one draw of a random quantity whose expectation is near 12/5, and reseeding moves it: the same model at seed 0 gives 1.9660, at seed 2 gives 2.7300, at seed 3 gives 2.5300. A page that printed only the first of those would be reporting a coincidence.
Little's Law, and which horizon you divide by
The area under the occupancy curve is both the integral of the number in system and the sum of the customers' times in it. Divide it by the horizon and you get the time average; divide the sum of times by the number of customers and you get the mean time in system; divide the number of customers by the horizon and you get the arrival rate. The three are then related by L = λW as a matter of arithmetic, with no assumption about the model at all.
It is worth being precise about the horizon, because the panel uses two of them and they differ. Over the trace's own horizon — from slot 0 to the last departure, at slot 2005 — the arrival rate is 776/2005 and the mean time in system is 4733/776, and their product is 4733/2005 ≈ 2.3606. The panel's time average divides the same area by the 2000 slots the run was asked for, giving 4733/2000 ≈ 2.3665. Same area, two denominators, and the identity holds for whichever one you choose consistently.
One thing that is often called a mistake here and is not: this is a slotted model, so stepping one slot at a time is the model, and next-event simulation is the efficient form of the same computation. The two agree slot for slot and differ only in how much work they do. They part company for systems in continuous time, which this path does not sample.