Introduction to Simulation
Open in the Padhaiko app1.1 System and system environment concepts
System and System Environment
A system is a collection of interacting entities (such as people, machines, or packets) that act together toward accomplishing a logical end. Every study begins by drawing a system boundary:
- Everything inside the boundary constitutes the system.
- Everything outside the boundary that affects the system (or is affected by it) constitutes the system environment.
Activities occurring wholly within the boundary are endogenous (e.g., a machine processing a part), whereas external inputs crossing the boundary from the environment are exogenous (e.g., customer arrivals or raw material supply).
To model any real-world system cleanly, we describe it using five fundamental building blocks:
| Component | Definition | Bank Teller Example | Production Line Example |
|---|---|---|---|
| Entity | An object of interest in the system | Customer, Teller | Job/Part, Lathe Machine |
| Attribute | A property of an entity | Account balance, transaction type | Part weight, processing time |
| Activity | A time period of specified length | Making a deposit () | Machining a shaft () |
| Event | An instantaneous occurrence that changes the system state | Customer arrival, service completion | Job arrival, machine breakdown |
| State Variable | A variable needed to describe the system at any instant | Number of customers waiting, teller status (busy/idle) | Queue length, machine status |
1.2 Continuous and discrete systems
Systems are classified according to how their state variables evolve over time.
| Aspect | Continuous System | Discrete System |
|---|---|---|
| State Evolution | State variables change continuously with respect to time | State variables change instantaneously at discrete points in time |
| Mathematical Description | Differential or difference equations (e.g., ) | Event-transition rules, probability distributions, queues |
| Time Progression | Smooth flow of state trajectories | Jumps from one event timestamp to the next |
| Examples | Water level behind a dam, aircraft flight dynamics, chemical reactor temperature | Number of customers in a bank queue, packets in a router buffer |
In practice, many real systems are hybrid (combined continuous–discrete): for instance, a steel furnace whose temperature rises continuously while ingots arrive and depart at discrete instants.
1.3 Types of models
A model is a simplified representation of a system constructed to study its behavior without disturbing or building the actual system. Models are categorized along several orthogonal dimensions:
Classification of Models
- Physical vs. Mathematical Models:
- Physical (Iconic or Analog) Models: Tangible scale replicas (e.g., wind-tunnel aircraft model) or electrical analogs of mechanical systems.
- Mathematical (Symbolic) Models: Represent relationships among system quantities using equations, logic, and inequalities.
- Static vs. Dynamic Models:
- Static Model: Represents a system at a particular point in time (time plays no explicit role), such as Monte-Carlo integration.
- Dynamic Model: Represents a system as it evolves over time, such as a queuing network or orbital trajectory.
- Deterministic vs. Stochastic Models:
- Deterministic Model: Contains no random variables; identical inputs always yield identical outputs (e.g., ).
- Stochastic (Probabilistic) Model: Contains one or more random variables as inputs (e.g., random inter-arrival times), producing random outputs that must be analyzed statistically.
- Discrete vs. Continuous Models:
- Discrete Model: State changes occur only at countable event instants.
- Continuous Model: State changes continuously over time.
- Analytical vs. Simulation Models:
- Analytical Model: Solved exactly in closed form via calculus, algebra, or queuing formulas (e.g., steady-state formulas).
- Simulation Model: Evaluated numerically by executing the model over time (or over random trials) on a computer when exact analytical solutions are intractable.
1.4 Model development life cycle
Building a credible simulation model follows an iterative engineering workflow rather than a single linear pass:
| Phase | Primary Objective | Key Output |
|---|---|---|
| 1. Problem Definition | Clarify system boundaries, performance metrics, and constraints | Problem statement and objectives |
| 2. Conceptual Modeling | Abstract real entities, assumptions, and interactions into logic | Flowchart, event graph, or mathematical specification |
| 3. Input Data Collection & Analysis | Gather empirical observations and fit theoretical distributions | Fitted probability distributions (e.g., Poisson, Exponential) |
| 4. Model Translation | Encode the conceptual model into a simulation language or code | Executable computer program |
| 5. Verification | Confirm the program faithfully implements the conceptual model | Debugged, bug-free simulation code |
| 6. Validation | Confirm the model accurately represents the real system | Calibrated, statistically validated model |
| 7. Experimentation & Analysis | Design runs, compute confidence intervals, compare alternatives | Performance comparison report |
| 8. Documentation & Deployment | Record assumptions, usage instructions, and implement decisions | User manual and operational recommendations |
1.5 Simulation and steps in simulation study
Simulation
Simulation is the imitation of the operation of a real-world process or system over time. Whether done by hand or on a computer, simulation involves generating an artificial history of the system and observing that history to draw inferences concerning the operating characteristics of the real system.
Following Banks, Carson, and Nelson, a complete simulation study consists of 12 structured steps:
- Problem Formulation: State the problem clearly so both the client and analyst agree on the scope.
- Setting of Objectives and Overall Project Plan: Specify the questions to be answered, candidate system alternatives, required resources, and schedule.
- Model Conceptualization: Abstract the essential features of the system into a conceptual model (starting simple and adding complexity incrementally).
- Data Collection: Gather historical and observational data on system inputs (inter-arrival times, service times, failure rates) in parallel with model conceptualization.
- Model Translation: Translate the conceptual model into a computer-recognizable format using a general-purpose language (Python, Java, C++) or simulation software (GPSS, Arena, SimPy).
- Verified?: Check whether the computer program performs properly ("Did we build the model right?"). If not, return to Model Translation.
- Validated?: Compare model outputs against the real system ("Did we build the right model?"). If discrepancies remain, refine Model Conceptualization or Data Collection.
- Experimental Design: Decide the alternatives to simulate, simulation run length, warm-up period, and number of independent replications.
- Production Runs and Analysis: Execute the planned runs and estimate performance measures (means, confidence intervals).
- More Runs?: Determine whether additional replications or new scenarios are needed based on precision requirements.
- Documentation and Reporting: Prepare both program documentation (how the code works) and progress/final reports (results and recommendations).
- Implementation: Put the recommended system changes into practice; the credibility earned during validation determines stakeholder adoption.
1.6 Advantages and disadvantages of simulation
Simulation is widely used for complex stochastic systems, but it is not always the best first tool.
| Advantages of Simulation | Disadvantages of Simulation |
|---|---|
| Tests without disruption: New policies, layouts, or hardware can be tested before committing capital or halting operations. | Expensive and time-consuming: Model building, data gathering, and validation require significant time and specialist skill. |
| Time compression or expansion: Months of factory operation can be simulated in seconds, or nanosecond events slowed for inspection. | Statistical uncertainty: Outputs from stochastic simulations are random estimates, not exact closed-form numbers. |
| Handles complexity: Models non-stationary arrivals, complex routing, and non-exponential distributions where analytical queuing formulas fail. | No automatic optimization: Simulation evaluates a given scenario ("what-if"); it does not directly output an optimal solution without extra search. |
| "What-if" sensitivity analysis: Easy to explore bottleneck causes and compare multiple competing designs under identical random seeds. | Garbage-in, garbage-out: Poor input data or skipped validation produces misleading results that can appear deceptively precise. |
1.7 Monte-Carlo simulation
Monte-Carlo Simulation
Monte-Carlo simulation is a static, stochastic simulation technique that uses repeated random sampling to obtain numerical results for deterministic or probabilistic problems—such as evaluating definite integrals, estimating , or computing expected profit under uncertain demand.
Unlike discrete-event simulation, time does not play an essential role in a pure Monte-Carlo experiment; each random draw represents an independent trial.
General Monte-Carlo Integration Principle: To estimate , draw independent uniform random samples :
By the Law of Large Numbers, the estimator converges to as with standard error proportional to .
1.8 Discrete-event system simulation
Discrete-Event System Simulation (DES)
Discrete-event system simulation (DES) models systems in which state variables change only at a discrete set of points in time at which events occur. Between consecutive events, all state variables remain constant.
Core Components of a Discrete-Event Simulator
Every discrete-event simulation program is organized around eight standard components:
- System State: Collection of state variables describing the system at time (e.g., server status , queue length ).
- Simulation Clock: Variable giving the current value of simulated time.
- Event List (Future Event List — FEL): A chronological list storing the timestamps and types of all scheduled future events (e.g., next arrival, next departure).
- Statistical Counters: Variables accumulating performance statistics (total waiting time, total busy time, number served).
- Initialization Routine: Sets , initializes state variables and statistical counters, and schedules the initial events into the FEL.
- Timing Routine: Inspects the FEL, selects the most imminent event (smallest timestamp), advances the simulation clock to that time, and transfers control to the corresponding event routine.
- Event Routines: Subprograms that update system state, statistical counters, and schedule new future events whenever a specific event type occurs.
- Report Generator: Computes final summary metrics (average delay, server utilization, average queue length) when the stopping condition is met.
Time-Advance Mechanisms
| Aspect | Next-Event Time Advance | Fixed-Increment Time Advance |
|---|---|---|
| Clock Update | Jumps directly from current time to the timestamp of the next imminent event in the FEL | Advances in fixed steps : |
| Efficiency | High—skips idle intervals where nothing happens | Can waste CPU cycles if is small and events are sparse |
| Precision | Exact event ordering down to floating-point precision | Events within the same interval are treated as simultaneous |
| Primary Use | Standard discrete-event systems (queues, networks, manufacturing) | Time-stepped continuous approximations or real-time training simulators |
Worked Out Examples
1
Estimate the value of using Monte-Carlo simulation with the following pairs of uniform random numbers on :
Geometry of the quarter-circle hit-or-miss method: The unit square has area . Inside it, the first-quadrant quarter of the unit circle has area:
Testing each random coordinate pair against :
| Trial | Inside Quarter-Circle ()? | |||
|---|---|---|---|---|
| Yes | ||||
| No | ||||
| Yes | ||||
| No | ||||
| Yes | ||||
| Yes | ||||
| Yes | ||||
| Yes | ||||
| Yes | ||||
| Yes |
Counting the "Yes" rows gives points inside the quarter-circle out of trials.
Computing the estimate :
With out of sample points inside the quarter-circle, the Monte-Carlo estimate is .
2
Perform a manual discrete-event simulation for a single-server ticket counter serving customers under FCFS discipline. The arrival times and service times (in minutes) are:
| Customer | Arrival Time () | Service Time () |
|---|---|---|
Trace the Future Event List (FEL) and state transitions until the th customer departs, and calculate:
- Average waiting time in the queue.
- Average time spent in the system.
- Server utilization over .
Tracing the event-by-event execution: Let be the number of customers waiting in the queue and be the server status (, ). Using next-event time advance:
| Clock () | Event Type | Action and FEL Update | ||
|---|---|---|---|---|
| Arrival | Server idle; begins service. Schedule Dep at , Arr at . | |||
| Arrival | Server busy; joins queue. Schedule Arr at . | |||
| Departure | departs; starts service (wait ). Schedule Dep at . | |||
| Arrival | Server busy; joins queue. Schedule Arr at . | |||
| Departure | departs; starts service (wait ). Schedule Dep at . | |||
| Departure | departs; queue empty, server becomes idle. Next event: Arr at . | |||
| Arrival | Server idle; begins service. Schedule Dep at , Arr at . | |||
| Arrival | Server busy; joins queue. | |||
| Departure | departs; starts service (wait ). Schedule Dep at . | |||
| Departure | departs; queue empty, simulation ends at . |
Summarizing per-customer delays and performance metrics:
| Customer | Arrival () | Service Start | Service End | Wait in Queue () | Time in System () |
|---|---|---|---|---|---|
- Average waiting time in queue:
- Average time in system:
- Server utilization: (with idle from to ).
3
Exam-Style Modeling Question: Identify the entities, attributes, activities, events, and state variables for a highway tollbooth system, and classify the resulting simulation model across the standard model taxonomies.
Extracting system components:
- System Boundary & Environment: The tollbooth lanes, queues, and booths form the system; arriving highway traffic and external weather/holidays belong to the environment.
- Entities: Vehicles (cars, trucks) and tollbooths/attendants.
- Attributes: Vehicle type (car vs. heavy truck), payment mode (cash vs. RFID tag), toll amount.
- Activities: Paying toll / scanning RFID tag (duration depends on vehicle type and payment mode).
- Events: Vehicle arrival at the toll plaza (exogenous), service completion / vehicle departure (endogenous).
- State Variables: Number of vehicles queued in each lane and status of each tollbooth .
Classifying the model:
- Mathematical / Simulation: Cannot be represented physically at full scale; uses discrete-event logic.
- Dynamic: System queue lengths evolve over time .
- Stochastic: Vehicle inter-arrival times and cash-payment durations are random variables.
- Discrete: State variables and change only at discrete arrival and departure instants.
The highway tollbooth is modeled as a dynamic, stochastic, discrete-event simulation model with vehicles and booths as entities, vehicle type/payment mode as attributes, toll transaction as the activity, arrivals/departures as events, and lane queue lengths plus booth busy flags as state variables.
Exercises
Practice Exercises — Introduction to Simulation
Define system, system environment, entity, attribute, activity, event, and state variable. Explain the difference between endogenous and exogenous activities with a suitable example.
Definitions of System Concepts:
- System: A group of objects joined in regular interaction or interdependence to accomplish a purpose.
- System Environment: All external factors outside the system boundary that influence or are influenced by the system.
- Entity: Any object of interest inside the system (e.g., a packet in a network).
- Attribute: A characteristic property belonging to an entity (e.g., packet size or priority).
- Activity: A process or operation taking a finite, positive duration (e.g., transmitting a packet).
- Event: An instantaneous occurrence that may change the state of the system (e.g., packet arrival).
- State Variable: A minimal set of variables needed to characterize the system at any instant (e.g., buffer occupancy).
Endogenous vs. Exogenous Activities:
- Endogenous: Activities and events occurring inside the system boundary (e.g., packet service inside a router).
- Exogenous: Activities and events originating outside the boundary in the environment (e.g., external packet arrivals from host computers).
A system consists of entities with attributes performing activities triggered by events that update state variables inside a boundary separated from the environment. Internal occurrences are endogenous, whereas external inputs from the environment are exogenous.
List and briefly explain the 12 steps in a simulation study, highlighting the distinction between verification and validation.
Twelve Steps in a Simulation Study:
- Problem formulation; 2. Setting objectives and overall project plan; 3. Model conceptualization; 4. Data collection; 5. Model translation; 6. Verification; 7. Validation; 8. Experimental design; 9. Production runs and analysis; 10. Checking whether more runs are needed; 11. Documentation and reporting; 12. Implementation.
Verification vs. Validation:
- Verification checks the internal translation from conceptual model to computer code ("Did we build the model right?").
- Validation checks external fidelity against the real system ("Did we build the right model?").
A simulation study progresses iteratively through problem formulation, objectives, conceptualization, data collection, translation, verification, validation, experimental design, production runs, additional run checks, documentation, and implementation. Verification ensures the code matches the conceptual model, while validation ensures the model matches reality.
Compare continuous and discrete systems, and explain four situations where simulation is preferred over analytical modeling as well as three major disadvantages of simulation.
Continuous vs. Discrete Systems:
- In a continuous system, state variables change smoothly and continuously with time (modeled by differential equations, such as fluid flow or thermal cooling).
- In a discrete system, state variables change only at isolated event instants (modeled by event lists and state transitions, such as a queue).
When Simulation Is Preferred and Its Drawbacks:
- Preferred when: (1) internal interactions of a complex system are too intricate for closed-form equations; (2) time compression/expansion is needed; (3) "what-if" alternatives must be tested without disrupting live operations; (4) input distributions are non-standard or time-varying.
- Disadvantages: (1) Requires specialized expertise and development time; (2) stochastic runs give statistical estimates rather than exact answers; (3) does not automatically find an optimal configuration on its own.
Continuous systems have smoothly varying states while discrete systems jump at event times. Simulation excels when complex dynamics, time scaling, or non-disruptive testing prevent analytical solutions, at the cost of development effort, statistical noise, and lack of direct optimization.
A bakery models daily demand for a special cake using Monte-Carlo simulation. Historical demand probabilities are:
| Demand (cakes) | Probability | Cumulative Probability | Random-Digit Interval () |
|---|---|---|---|
Simulate days of demand using the -digit random numbers: , and compute the simulated average daily demand.
Mapping each random number to its demand interval:
- Day 1 (): Demand
- Day 2 (): Demand
- Day 3 (): Demand
- Day 4 (): Demand
- Day 5 (): Demand
- Day 6 (): Demand
- Day 7 (): Demand
- Day 8 (): Demand
Computing the simulated average daily demand:
The simulated daily demands are , giving a simulated average daily demand of .
Using next-event time advance, simulate a single-server repair shop for arriving jobs with arrival times and service times minutes. Find the average waiting time in the queue and the server utilization until all jobs depart.
Tracing arrival and departure events:
- : Job 1 arrives; server idle starts service at , departs at . Wait .
- : Job 2 arrives; server busy waits in queue.
- : Job 3 arrives; server busy waits in queue.
- : Job 1 departs; Job 2 starts service (wait ) and departs at .
- : Job 2 departs; Job 3 starts service (wait ) and departs at .
- : Job 4 arrives; server busy waits in queue.
- : Job 3 departs; Job 4 starts service (wait ) and departs at .
- : Job 4 departs; simulation ends.
Calculating performance measures:
Average waiting time in the queue is , and server utilization over is ().