When systems are too complex for closed-form analysis, simulation lets you study them numerically. Run a model many times; observe behavior; estimate statistics.
Simulation underpins queueing analysis, financial modeling, scientific research, and engineering design.
Use simulation when:
Don't simulate when:
System changes state at discrete events. Time jumps from event to event.
Used for: queueing systems, factories, networks, hospitals.
Tools: SimPy, AnyLogic, Arena, Simio.
Individual agents with rules. System behavior emerges from interactions.
Used for: epidemiology, economics, social systems, traffic.
Tools: NetLogo, Mesa, Repast.
Continuous flows and stocks. Differential equations.
Used for: business strategy, ecology, public policy.
Tools: Stella, Vensim, AnyLogic.
Random sampling to estimate quantities.
Used for: financial risk, physics, integration of high-dim functions.
Differential equations integrated over time.
Used for: physical systems, control systems, climate.
Tools: MATLAB/Simulink, Modelica.
The standard pattern:
Simulate: track customer arrivals and departures; collect wait times.
In SimPy:
import simpy
import random
def customer(env, server):
arrival = env.now
with server.request() as req:
yield req
wait = env.now - arrival
yield env.timeout(random.expovariate(SERVICE_RATE))
# log wait
env = simpy.Environment()
server = simpy.Resource(env, capacity=1)
# spawn arrivals; run; analyze
For estimating expectations:
Estimator standard error: σ/√n. Halving error needs 4x samples.
For high precision, use variance reduction:
Does the simulation match reality?
Is the simulation correctly implemented?
Run many independent runs (different random seeds). Don't trust a single run.
Report not just point estimates but confidence ranges.
Ignore initial transient. Discrete-event simulations especially need this.
Within one run, observations may be correlated. Use techniques like batch means or independent runs for valid statistics.
Quality matters.
Always seed deterministically for reproducibility.
How does output depend on inputs?
Reveals which inputs need precise estimation; which don't matter.
Hospital patient flow, call centers, network traffic.
Estimate: average wait, server utilization, queue length distribution.
Factory throughput, bottleneck analysis, scheduling policies.
Routing, inventory, supply chain.
Option pricing, portfolio risk, default modeling.
Disease progression, treatment decisions, resource planning.
Tax policy effects, transportation, urban planning.
Reliability analysis, performance prediction, what-if scenarios.
Adjust simulation parameters to match observed data.
Approaches:
Calibrated model can predict; uncalibrated model is exploratory.
Single runs are noise. Need many.
Including warm-up data biases results.
Tests pass but simulation has correlated runs.
Model not validated; predictions trusted.
Too many parameters; matches history but doesn't predict.
Output more sensitive to inputs than expected. Without analysis, you don't know.
Simulations are estimates. Always report uncertainty.
Bug in simulation. Results meaningless.
Plotting matters:
Don't trust averages alone.
Simulations grow naturally — keep scope tight to start.
Simulations are not:
A simulation gives confidence in a model's behavior, not in reality's.