Simulation Modeling

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.

When to simulate

Use simulation when:

- Analytical solution doesn't exist or is intractable

- System has many interacting components

- Stochastic / random elements matter

- Want to test policies or designs cheaply

- Real experiments would be expensive or impossible

Don't simulate when:

- Closed-form solution exists (it's faster and exact)

- Required precision exceeds what simulation can give

- Inputs are too uncertain to provide signal

Major simulation types

Discrete-event simulation

System changes state at discrete events. Time jumps from event to event.

Used for: queueing systems, factories, networks, hospitals.

Tools: SimPy, AnyLogic, Arena, Simio.

Agent-based simulation

Individual agents with rules. System behavior emerges from interactions.

Used for: epidemiology, economics, social systems, traffic.

Tools: NetLogo, Mesa, Repast.

System dynamics

Continuous flows and stocks. Differential equations.

Used for: business strategy, ecology, public policy.

Tools: Stella, Vensim, AnyLogic.

Monte Carlo simulation

Random sampling to estimate quantities.

Used for: financial risk, physics, integration of high-dim functions.

Continuous simulation

Differential equations integrated over time.

Used for: physical systems, control systems, climate.

Tools: MATLAB/Simulink, Modelica.

Discrete-event simulation in detail

The standard pattern:

1. Initialize state and event list

2. Get next event from list

3. Advance simulation time

4. Process event; possibly schedule new events

5. Repeat

Components

- **Entities**: things being modeled (customers, packets, parts)

- **Resources**: servers, queues

- **Events**: arrivals, completions

- **Statistics**: collected throughout

Example: M/M/1 queue

- Arrivals follow Poisson process

- Service times exponential

- Single server

Simulate: track customer arrivals and departures; collect wait times.

In SimPy:

```python

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

```

Monte Carlo simulation

For estimating expectations:

1. Sample inputs from distribution

2. Compute output

3. Average over many trials

Convergence

Estimator standard error: σ/√n. Halving error needs 4x samples.

For high precision, use variance reduction:

- Antithetic variables

- Control variates

- Importance sampling

- Quasi-random sequences

Use cases

- Pricing financial derivatives

- Risk assessment (VaR, ES)

- Bayesian inference (MCMC)

- Numerical integration

- Physics (particle simulations)

Building good simulations

Validation

Does the simulation match reality?

- Compare to historical data

- Compare to known cases (when analytical exists)

- Subject-matter expert review

- Sensitivity analysis

Verification

Is the simulation correctly implemented?

- Code review

- Tests with known answers

- Conservation checks

- Boundary cases

Replication

Run many independent runs (different random seeds). Don't trust a single run.

Confidence intervals

Report not just point estimates but confidence ranges.

Warm-up period

Ignore initial transient. Discrete-event simulations especially need this.

Independent observations

Within one run, observations may be correlated. Use techniques like batch means or independent runs for valid statistics.

Random number generators

Quality matters.

- Don't use linear congruential (period too short)

- Mersenne Twister: standard, period 2^19937

- PCG: modern, statistical quality

Always seed deterministically for reproducibility.

Sensitivity analysis

How does output depend on inputs?

- Vary one input at a time

- Tornado charts

- Sobol indices for variance decomposition

Reveals which inputs need precise estimation; which don't matter.

Specific applications

Queueing analysis

Hospital patient flow, call centers, network traffic.

Estimate: average wait, server utilization, queue length distribution.

Manufacturing

Factory throughput, bottleneck analysis, scheduling policies.

Logistics

Routing, inventory, supply chain.

Finance

Option pricing, portfolio risk, default modeling.

Healthcare

Disease progression, treatment decisions, resource planning.

Public policy

Tax policy effects, transportation, urban planning.

Engineering design

Reliability analysis, performance prediction, what-if scenarios.

Calibration

Adjust simulation parameters to match observed data.

Approaches:

- Maximum likelihood

- Bayesian inference

- Approximate Bayesian Computation (ABC)

- Manual tuning (when others fail)

Calibrated model can predict; uncalibrated model is exploratory.

Common failure patterns

Insufficient runs

Single runs are noise. Need many.

Initial transient pollution

Including warm-up data biases results.

Hidden state

Tests pass but simulation has correlated runs.

Validation gap

Model not validated; predictions trusted.

Over-fitting

Too many parameters; matches history but doesn't predict.

Sensitivity surprise

Output more sensitive to inputs than expected. Without analysis, you don't know.

Treating point estimates as truth

Simulations are estimates. Always report uncertainty.

Verification gap

Bug in simulation. Results meaningless.

Tools

Python

- SimPy: discrete-event

- Mesa: agent-based

- NumPy/SciPy: Monte Carlo

- Pyro/PyMC: Bayesian

Specialized

- AnyLogic: multi-paradigm commercial

- Arena, Simio, FlexSim: industrial DES

- NetLogo: agent-based, education

General

- MATLAB/Simulink: continuous + DES

- R: statistical simulation

- Julia: high-performance scientific

Output analysis

Plotting matters:

- Time series of key variables

- Distributions (histograms, ECDFs)

- Correlation plots

- Confidence intervals

Don't trust averages alone.

Practical workflow

1. Define purpose: what question are you answering?

2. Build minimum viable model

3. Validate against known cases / data

4. Run sensitivity analysis

5. Iterate on model fidelity

6. Run for production decisions

7. Quantify uncertainty

Simulations grow naturally — keep scope tight to start.

Limitations

Simulations are not:

- Reality (just models of it)

- Predictions in chaotic systems beyond short horizon

- Substitutes for understanding

A simulation gives confidence in a model's behavior, not in reality's.

Further Reading

- [Operations Research Hub](OperationsResearchHub) — Cluster index