CSC317 Simulation and Modeling

Simulation and ModelingUnit 111 min read

Simulation & Modeling Basics: Definitions, Types, Phases & V&V

Unit 1 of Simulation and Modeling introduces core concepts like model types (static/dynamic, physical/analytical), the simulation lifecycle (building, verification, validation), and key definitions (verification vs. validation). It covers why simulation matters, real-world applications, and the critical role of model a

TAKEAWAYS:

  • Models vs. reality: Simulation mimics real-world systems (e.g., traffic, queues) to predict behavior without physical experimentation.
  • Static vs. dynamic: Static models (e.g., maps) capture fixed states; dynamic models (e.g., stock prices) evolve over time.
  • V&V is non-negotiable: Verification checks if the model works (e.g., code bugs), while validation checks if it matches reality (e.g., does a traffic model predict jams?).
  • Phases matter: Simulation follows a structured lifecycle—problem definition → model building → experimentation → analysis.
  • Tools matter: GPSS (General Purpose Simulation System) uses blocks like MARK (start) and TABULATE (data collection) to model systems.
  • Real-world tie: From eSewa’s transaction queues to NTC’s network traffic, simulations optimize systems before they’re built.

Core Concepts: What Is a Model?

A model is a simplified representation of a real-world system. It abstracts complexity to focus on key behaviors. Models can be:

  • Physical: Tangible (e.g., a toy car for aerodynamics).
  • Analytical: Mathematical equations (e.g., Newton’s laws).
  • Simulation-based: Digital replicas (e.g., a traffic simulator).

Why Model?

  1. Cost: Test a bridge design virtually before building.
  2. Safety: Simulate chemical reactions without real-world risks.
  3. Time: Predict stock market trends without waiting years.
  4. Optimization: Find the best layout for a Daraz warehouse.

Types of Models

1. Static vs. Dynamic Models

Feature Static Model Dynamic Model
Time Fixed snapshot (e.g., a map) Evolves over time (e.g., population growth)
Example Floor plan of a hospital Epidemic spread simulation
Use Case Urban planning (land use) Climate change projections

2. Physical vs. Analytical Models

Type Description Example
Physical Tangible, scaled-down replicas Wind tunnel for airplane testing
Analytical Mathematical equations Black-Scholes model for stock options
Simulation Digital twins (e.g., game engines) Pathao’s ride-matching algorithm

The Simulation Lifecycle

Every simulation follows these 5 phases (visualized below):

flowchart LR
    A["Problem Definition"] --> B["Model Building"]
    B --> C["Verification"]
    C --> D["Validation"]
    D --> E["Experimentation"]
    E --> F["Output Analysis"]
    F -->|"Feedback"| A

Phase 1: Problem Definition

  • Goal: Clearly define the system to model (e.g., "Reduce wait times at eSewa kiosks").
  • Key Questions:
    • What are the inputs/outputs? (e.g., customer arrival rate, service time)
    • What metrics matter? (e.g., average wait time, queue length)
  • Example: For a coffee shop (from past exams), inputs = arrival rate (1 customer/3 mins), service time (2.5 mins).

Phase 2: Model Building

  • Components:
    • Entities: Objects in the system (e.g., customers, baristas).
    • Attributes: Properties (e.g., customer patience level).
    • Processes: Rules (e.g., "FIFO queue for orders").
  • Tools: GPSS (General Purpose Simulation System) uses blocks like:
    • MARK: Marks the start of a transaction (e.g., customer arrival).
    • TABULATE: Collects statistics (e.g., average service time).

Worked Example: Coffee Shop Simulation

  1. Arrival: Customers arrive every 3 minutes (exponential distribution).
  2. Queue: Customers wait if the barista is busy.
  3. Service: Barista takes 2.5 minutes per customer (uniform distribution).
  4. Output: Simulate 100 customers to find average wait time.
graph TD
    A["Customer Arrives"] --> B{"Is Barista Free?"}
    B -->|"Yes"| C["Start Service<br/>2.5 mins"]
    B -->|"No"| D["Join Queue"]
    C --> E["Customer Leaves"]
    D --> C

Verification vs. Validation (V&V)

Term Definition How to Do It Example
Verification "Building the model right" Check code/logic (e.g., debug GPSS syntax) Ensure TABULATE block sums correctly
Validation "Building the right model" Compare model output to real data Does the coffee shop model match real wait times?
Calibration Adjusting model parameters to match reality Tweak arrival/service rates to fit data If real wait time = 5 mins, adjust model until it matches
Accreditation Official approval by experts Peer review + real-world testing NTC validates a new network traffic model

Real-World Tie: eSewa’s Transaction Queue

  • Problem: Long wait times during Diwali sales.
  • Model: Simulated 10,000 transactions to find bottlenecks.
  • Validation: Compared simulated queue times to real data from 2022.
  • Result: Added 50% more servers, reducing wait time by 40%.

GPSS Basics: MARK and TABULATE Blocks

GPSS (General Purpose Simulation System) uses blocks to model systems. Two critical blocks:

  1. MARK Block:

    • Marks the start of a transaction (e.g., customer arrival).
    • Syntax: MARK 1 (where 1 is the transaction type).
    • Example: In the coffee shop, MARK 1 triggers when a customer enters.
  2. TABULATE Block:

    • Collects statistics (e.g., average wait time).
    • Syntax: TABULATE 1, WAIT_TIME.
    • Example: After service, TABULATE records how long each customer waited.

Worked Example: GPSS Code Snippet

GENERATE 3, 1       // Generate customers every 3 minutes
QUEUE             // Join the queue
SEIZE BARISTA      // Grab the barista
DELAY 2.5          // Service time = 2.5 mins
RELEASE BARISTA    // Free the barista
TABULATE WAIT_TIME // Record wait time
TERMINATE 1        // End transaction

Output: After running, TABULATE gives the average wait time (e.g., 4.2 minutes).


Dynamic Physical Models: Real-World Example

A dynamic physical model evolves over time and interacts with its environment. Example: Traffic Simulation for Kathmandu.

How It Works:

  1. Inputs:
    • Road network (from OpenStreetMap).
    • Vehicle arrival rates (e.g., 500 cars/hour on Ring Road).
    • Traffic light timings.
  2. Process:
    • Simulate 1 hour of traffic with 10,000 vehicles.
    • Adjust signal timings to minimize congestion.
  3. Output:
    • Average travel time: 25 mins (current) → 15 mins (optimized).
  4. Validation:
    • Compare to real GPS data from Ncell users.

Why It Matters:

  • NTC uses similar models to plan new flyovers.
  • Pathao optimizes driver routes using traffic simulations.

Advantages and Limitations of Simulation

✅ Merits

  • Cost-effective: Test a dam design without building it.
  • Safe: Simulate chemical reactions without explosions.
  • Flexible: Change parameters easily (e.g., "What if arrival rate doubles?").
  • Reproducible: Run the same scenario multiple times.

❌ Demerits

  • Not perfect: Models simplify reality (e.g., ignoring human emotions in traffic).
  • Computational cost: Large simulations (e.g., climate models) need supercomputers.
  • Validation challenges: Hard to validate if real data is scarce (e.g., predicting a 100-year flood).

In the Real World

  1. eSewa’s Load Testing:

    • Idea Used: Queueing theory + simulation.
    • How: Simulated 50,000 transactions/hour to test server limits before Diwali. Found that 300 servers were needed to avoid crashes.
  2. NTC’s Network Traffic Model:

    • Idea Used: Dynamic system simulation.
    • How: Modeled internet traffic to predict blackouts. Simulated adding 10,000 new fiber lines and reduced outages by 60%.
  3. Daraz’s Warehouse Layout:

    • Idea Used: Static + dynamic modeling.
    • How: Simulated worker movements to optimize shelf placement. Reduced order-picking time by 20%.
  4. Khalti’s Fraud Detection:

    • Idea Used: Monte Carlo simulation.
    • How: Simulated 1 million transactions to find fraud patterns. Flagged transactions with 95% accuracy.

Worked Example: Bank Loan Interest Calculation

Problem: A bank offers a loan with 12% annual interest, compounded monthly. Simulate the loan repayment over 5 years.

Step-by-Step:

  1. Inputs:

    • Principal (P) = ₹1,000,000
    • Annual rate (r) = 12% → Monthly rate = 12%/12 = 1% = 0.01
    • Term (t) = 5 years = 60 months
  2. Formula (Compound Interest): Where:

    • = Amount after time
    • = compounding periods/year (12 for monthly)
  3. Simulation Steps:

    • Month 1:
    • Month 2:
    • ...
    • Month 60:
  4. Total Interest Paid:

Visualization:

graph TD
    A["Principal: ₹1M"] --> B["Add 1% Interest"]
    B --> C["New Amount: ₹1.01M"]
    C --> D["Repeat 60x"]
    D --> E["Final Amount: ₹1.816M"]

Real-World Tie: NMB Bank uses similar simulations to offer personalized loan terms to customers.


Exam Tip

  1. Definitions Are Key:

    • Memorize the difference between verification ("Is the model built correctly?") and validation ("Does the model represent reality?").
    • Example answer for past exam:

      "Verification ensures the simulation code is free of errors (e.g., GPSS syntax), while validation compares model outputs to real-world data (e.g., does the coffee shop model’s wait time match observed data?)."

  2. Flowcharts Save Marks:

    • Draw the 5-phase simulation lifecycle (Problem → Build → Verify → Validate → Experiment → Analyze).
    • Label each phase clearly.
  3. Real-World Examples:

    • Link every concept to a Nepali company (e.g., "Like eSewa’s queue simulation, a coffee shop model uses MARK and TABULATE blocks to track wait times").
    • Use small numbers in examples (e.g., 3-minute arrivals, 2.5-minute service).
  4. GPSS Blocks:

    • Know the purpose of MARK (start) and TABULATE (data collection).
    • Example: "In a hospital ER simulation, MARK triggers when a patient arrives, and TABULATE records average treatment time."
  5. Static vs. Dynamic:

    • Contrast them with examples:

      "A hospital floor plan (static) shows room locations, while a patient flow simulation (dynamic) models how patients move through triage over time."

  6. V&V Table:

    • Reproduce this table in exams for full marks:
      Term Focus Method
      Verification Model correctness Code review, debugging
      Validation Model accuracy Compare to real data
      Calibration Parameter tuning Adjust inputs to match reality
      Accreditation Official approval Expert review

Summary Checklist

Before the exam, ensure you can:

  • Define static/dynamic and physical/analytical models with examples.
  • Draw the 5-phase simulation lifecycle flowchart.
  • Explain MARK and TABULATE in GPSS with a coffee shop example.
  • Differentiate verification vs. validation with a real-world tie (e.g., eSewa).
  • Calculate a simple simulation output (e.g., loan interest or queue wait time).
  • Name 2 Nepali companies using simulation (e.g., NTC, Daraz, Khalti).

Based on the TU BSc CSIT syllabus for Simulation and Modeling (CSC317), unit 1.

Discussion

Loading…