PadhaikoAll subjects

Introduction to Simulation

Simulation and Modeling (ENCT 353)

Open in the Padhaiko app

1.1 System and system environment concepts

Definition

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:

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:

Core Components of a System
ComponentDefinitionBank Teller ExampleProduction Line Example
EntityAn object of interest in the systemCustomer, TellerJob/Part, Lathe Machine
AttributeA property of an entityAccount balance, transaction typePart weight, processing time
ActivityA time period of specified lengthMaking a deposit ()Machining a shaft ()
EventAn instantaneous occurrence that changes the system stateCustomer arrival, service completionJob arrival, machine breakdown
State VariableA variable needed to describe the system at any instantNumber 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.

AspectContinuous SystemDiscrete System
State EvolutionState variables change continuously with respect to timeState variables change instantaneously at discrete points in time
Mathematical DescriptionDifferential or difference equations (e.g., )Event-transition rules, probability distributions, queues
Time ProgressionSmooth flow of state trajectoriesJumps from one event timestamp to the next
ExamplesWater level behind a dam, aircraft flight dynamics, chemical reactor temperatureNumber 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:

Definition

Classification of Models

  1. 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.
  2. 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.
  3. 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.
  4. Discrete vs. Continuous Models:
    • Discrete Model: State changes occur only at countable event instants.
    • Continuous Model: State changes continuously over time.
  5. 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:

Phases of the Model Development Life Cycle
PhasePrimary ObjectiveKey Output
1. Problem DefinitionClarify system boundaries, performance metrics, and constraintsProblem statement and objectives
2. Conceptual ModelingAbstract real entities, assumptions, and interactions into logicFlowchart, event graph, or mathematical specification
3. Input Data Collection & AnalysisGather empirical observations and fit theoretical distributionsFitted probability distributions (e.g., Poisson, Exponential)
4. Model TranslationEncode the conceptual model into a simulation language or codeExecutable computer program
5. VerificationConfirm the program faithfully implements the conceptual modelDebugged, bug-free simulation code
6. ValidationConfirm the model accurately represents the real systemCalibrated, statistically validated model
7. Experimentation & AnalysisDesign runs, compute confidence intervals, compare alternativesPerformance comparison report
8. Documentation & DeploymentRecord assumptions, usage instructions, and implement decisionsUser manual and operational recommendations

1.5 Simulation and steps in simulation study

Definition

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:

  1. Problem Formulation: State the problem clearly so both the client and analyst agree on the scope.
  2. Setting of Objectives and Overall Project Plan: Specify the questions to be answered, candidate system alternatives, required resources, and schedule.
  3. Model Conceptualization: Abstract the essential features of the system into a conceptual model (starting simple and adding complexity incrementally).
  4. Data Collection: Gather historical and observational data on system inputs (inter-arrival times, service times, failure rates) in parallel with model conceptualization.
  5. 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).
  6. Verified?: Check whether the computer program performs properly ("Did we build the model right?"). If not, return to Model Translation.
  7. Validated?: Compare model outputs against the real system ("Did we build the right model?"). If discrepancies remain, refine Model Conceptualization or Data Collection.
  8. Experimental Design: Decide the alternatives to simulate, simulation run length, warm-up period, and number of independent replications.
  9. Production Runs and Analysis: Execute the planned runs and estimate performance measures (means, confidence intervals).
  10. More Runs?: Determine whether additional replications or new scenarios are needed based on precision requirements.
  11. Documentation and Reporting: Prepare both program documentation (how the code works) and progress/final reports (results and recommendations).
  12. 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 SimulationDisadvantages 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

Definition

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

Definition

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:

  1. System State: Collection of state variables describing the system at time (e.g., server status , queue length ).
  2. Simulation Clock: Variable giving the current value of simulated time.
  3. 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).
  4. Statistical Counters: Variables accumulating performance statistics (total waiting time, total busy time, number served).
  5. Initialization Routine: Sets , initializes state variables and statistical counters, and schedules the initial events into the FEL.
  6. 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.
  7. Event Routines: Subprograms that update system state, statistical counters, and schedule new future events whenever a specific event type occurs.
  8. Report Generator: Computes final summary metrics (average delay, server utilization, average queue length) when the stopping condition is met.

Time-Advance Mechanisms

AspectNext-Event Time AdvanceFixed-Increment Time Advance
Clock UpdateJumps directly from current time to the timestamp of the next imminent event in the FELAdvances in fixed steps :
EfficiencyHigh—skips idle intervals where nothing happensCan waste CPU cycles if is small and events are sparse
PrecisionExact event ordering down to floating-point precisionEvents within the same interval are treated as simultaneous
Primary UseStandard discrete-event systems (queues, networks, manufacturing)Time-stepped continuous approximations or real-time training simulators

Worked Out Examples

Example 1

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 :

Monte-Carlo Trials for Estimating Pi
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 :

Answer:

With out of sample points inside the quarter-circle, the Monte-Carlo estimate is .

Example 2

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 and Service Schedule
CustomerArrival Time ()Service Time ()

Trace the Future Event List (FEL) and state transitions until the th customer departs, and calculate:

  1. Average waiting time in the queue.
  2. Average time spent in the system.
  3. 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:

Discrete-Event Simulation Trace
Clock ()Event TypeAction 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:

Per-Customer Time Summary
CustomerArrival ()Service StartService EndWait in Queue ()Time in System ()
Answer:
  1. Average waiting time in queue:
  2. Average time in system:
  3. Server utilization: (with idle from to ).
Example 3

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.
Answer:

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

Question 1

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).
Answer:

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.

Question 2

List and briefly explain the 12 steps in a simulation study, highlighting the distinction between verification and validation.

Twelve Steps in a Simulation Study:

  1. 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?").
Answer:

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.

Question 3

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.
Answer:

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.

Question 4

A bakery models daily demand for a special cake using Monte-Carlo simulation. Historical demand probabilities are:

Daily Cake Demand Distribution
Demand (cakes)ProbabilityCumulative ProbabilityRandom-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:

Answer:

The simulated daily demands are , giving a simulated average daily demand of .

Question 5

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:

Answer:

Average waiting time in the queue is , and server utilization over is ().

Physical and Mathematical Models →