Simulation and ModelingUnit 1013 min read
Practical Applications & Case Studies in Simulation
Unit 10 of Simulation and Modeling explores real-world applications of Markov chains, queueing theory, Monte Carlo methods, and discrete-event simulation in Nepalese and global industries—from eSewa’s transaction queues to Ncell’s network traffic modeling. Learn how to map problems to simulation techniques, analyze cas
TAKEAWAYS:
- Markov chains model state transitions in systems like Ncell’s call-drop rates or Daraz’s order fulfillment (e.g., "pending → shipped → delivered").
- Queueing theory optimizes wait times in eSewa’s payment queues or NTC’s customer service calls (M/M/1 vs. M/M/c models).
- Monte Carlo simulations estimate risks in NEPSE stock prices or Kathmandu traffic congestion by sampling random scenarios.
- Discrete-event simulation (DES) schedules resources in Pathao’s driver dispatch or hospital patient flows (e.g., "arrival → triage → treatment").
- Validation/verification ensures models match real data (e.g., comparing simulated vs. actual Khalti transaction delays).
- Tools like AnyLogic or SimPy automate simulations; choose based on problem scale (e.g., Python for small-scale, Arena for industrial).
1. Markov Chains: State Transitions in Real Systems
Markov chains model systems where future states depend only on the current state (memoryless property). Key applications in Nepal:
- Telecom networks: Ncell’s call-drop probability (states: "active call," "dropped," "reconnected").
- E-commerce: Daraz’s order status (states: "processing," "shipped," "delivered," "cancelled").
- Finance: NEPSE stock price movements (states: "bullish," "bearish," "stable").
How It Works
A Markov chain is defined by:
- States (S): Distinct conditions (e.g.,
S = {waiting, in_service, completed}for a queue). - Transition probabilities (P): Probability of moving from state i to j in one step (e.g.,
P(waiting → in_service) = 0.3). - Transition matrix: Square matrix where
P_ij= probability of i→j.
Worked Example: eSewa Payment Queue
Problem: Model the probability of a user’s payment getting stuck in "processing" before completing. States:
S₀: Payment initiated (user sees "Processing...").S₁: Payment successful (user redirected to merchant).S₂: Payment failed (user returns to wallet).
Transition Matrix (assumed probabilities):
S₀ S₁ S₂
S₀ [0.6 0.3 0.1]
S₁ [0.0 1.0 0.0] ← Absorbing state (no reversal)
S₂ [0.0 0.2 0.8]
Question: What’s the probability a payment fails after 2 steps if it starts in S₀?
Solution:
- After Step 1:
P(S₀→S₀) = 0.6,P(S₀→S₂) = 0.1.
- After Step 2:
- From
S₀:0.6→S₀(thenS₀→S₂ = 0.1) →0.6 * 0.1 = 0.06. - From
S₂:0.1→S₂(thenS₂→S₂ = 0.8) →0.1 * 0.8 = 0.08. - Total:
0.06 + 0.08 = 0.14(14% chance of failure in 2 steps).
- From
graph TD
A["S₀: Processing"] -->|"0.6"| A
A -->|"0.3"| B["S₁: Success"]
A -->|"0.1"| C["S₂: Failed"]
C -->|"0.8"| C
C -->|"0.2"| BApplications Table
| Domain | System | States | Transition Example |
|---|---|---|---|
| Telecom | Ncell call drops | Active, Dropped, Reconnected | P(Dropped→Reconnected) = 0.4 |
| E-commerce | Daraz order status | Pending, Shipped, Delivered | P(Pending→Shipped) = 0.7 |
| Healthcare | Hospital patient flow | Triage, Admitted, Discharged | P(Triage→Admitted) = 0.6 |
| Finance | NEPSE stock trends | Bullish, Bearish, Stable | P(Bullish→Bearish) = 0.2 |
2. Queueing Theory: Managing Wait Times
Queueing theory models systems with arrivals, service, and waiting lines. Critical for:
- eSewa/Khalti: Payment processing queues (customers vs. servers).
- NTC: Customer service call centers (M/M/c model).
- Pathao: Driver dispatch (multiple servers = drivers).
Key Models
| Model | Description | When to Use | Formula |
|---|---|---|---|
| M/M/1 | Single server, Poisson arrivals | Bank tellers, single-counter eSewa | |
| M/M/c | Multiple servers (c > 1) | NTC call center (10 agents) | |
| M/G/1 | Single server, general service times | Daraz order fulfillment (variable times) | Use Pollaczek-Khinchine formula |
Worked Example: NTC Call Center
Problem: NTC has 5 agents (c=5), average call arrival rate λ=12 calls/hour, service rate μ=15 calls/hour/agent. Find:
- Utilization (ρ): Probability an agent is busy.
- Average queue length ().
Solution:
- Utilization: (16% busy).
- Queue length (using M/M/c formula):
- .
- Plugging in: .
- (2 calls waiting on average).
flowchart LR
A["Arrival: λ=12/h"] --> B["Queue"]
B --> C["Server Pool (5 agents)"]
C -->|"μ=15/h"| D["Departure"]Real-World Impact
- eSewa: If
λ > c·μ, payments fail (e.g., during Dashain sales). Solution: Add more servers (increasec). - Pathao: Uses M/M/c to match drivers to rides (dynamic
cbased on demand).
3. Monte Carlo Simulation: Uncertainty Modeling
Monte Carlo uses random sampling to estimate outcomes for systems with uncertainty. Used in:
- NEPSE: Predicting stock price ranges.
- Traffic: Estimating Kathmandu’s congestion delays.
- Healthcare: Simulating vaccine distribution.
How It Works
- Define inputs: Random variables (e.g., stock price change =
N(0, 0.1)). - Run trials: Sample inputs, compute output (e.g., portfolio value after 1 year).
- Aggregate results: Average/percentiles give estimates.
Worked Example: NEPSE Stock Prediction
Problem: Simulate the price of a stock after 1 year, given:
- Current price: ₹1000.
- Daily return:
N(0%, 2%)(mean 0%, std dev 2%). - Trading days: 250.
Steps:
- Generate 250 random daily returns:
returns = [r₁, r₂, ..., r₂₅₀]whererᵢ ~ N(0, 0.02). - Compute final price: .
- Repeat 10,000 times to get a distribution.
Python Code Snippet:
import numpy as np
np.random.seed(42)
returns = np.random.normal(0, 0.02, 250)
final_price = 1000 * np.prod(1 + returns)
print(f"Simulated price: ₹{final_price:.2f}")
Output Distribution:
Mean: ₹1002.50
95% Confidence Interval: [₹950, ₹1055]
graph TD
A["Start: ₹1000"] --> B["Day 1: +r₁"]
B --> C["Day 2: +r₂"]
C --> D["..."]
D --> E["Day 250: +r₂₅₀"]
E --> F["Final Price: ₹X"]Applications in Nepal
| Company/App | Use Case | Random Variables |
|---|---|---|
| NEPSE | Stock price forecasting | Daily returns ~ N(μ, σ) |
| Kathmandu Metro | Passenger load estimation | Arrival times ~ Poisson(λ) |
| Daraz | Delivery time prediction | Traffic delays ~ Exponential(λ) |
4. Discrete-Event Simulation (DES): Scheduling Systems
DES models systems where events (e.g., arrivals, departures) change state at discrete times. Used for:
- Pathao: Ride dispatch (events: "ride requested," "driver assigned").
- Hospitals: Patient flow (events: "arrival," "triage," "surgery start").
Key Components
- Entities: Objects moving through the system (e.g., Pathao riders).
- Events: Changes in state (e.g., "ride accepted").
- Resources: Limited capacity (e.g., 100 drivers in Kathmandu).
- Processes: Logic for handling events (e.g., "assign nearest driver").
Worked Example: Pathao Ride Dispatch
Scenario:
- Arrival rate: 1 ride/minute (Poisson).
- Driver availability: 50 drivers, each takes 10 mins/ride.
- Question: What’s the average wait time for a rider?
Simulation Steps:
- Initialize: Time = 0, Queue = [], Available Drivers = 50.
- Event 1: Ride arrives at
t=0→ add to queue. - Event 2: Driver assigned at
t=0.5(assuming 30 sec to match).- Driver takes 10 mins → returns at
t=10.5.
- Driver takes 10 mins → returns at
- Repeat: Simulate 1000 rides, track wait times.
Output:
- Average wait time: 2.3 minutes (due to driver scarcity).
- Solution: Add more drivers or incentivize faster pickups.
sequenceDiagram
participant Rider
participant Pathao
participant Driver
Rider->>Pathao: Request ride (t=0)
Pathao->>Driver: Assign (t=0.5)
Driver-->>Rider: Pickup (t=1)
Driver->>Pathao: Return (t=11)
Pathao->>Rider: End trip (t=11)5. Model Validation and Verification
Validation: Does the model match real-world behavior? Verification: Does the model implement the theory correctly?
Techniques
| Method | Description | Example |
|---|---|---|
| Face validation | Expert review | NTC engineers check call-center model |
| Historical data | Compare simulated vs. real data | eSewa’s actual vs. simulated failures |
| Sensitivity analysis | Test extreme inputs | What if Daraz’s λ doubles? |
Worked Example: eSewa Failure Rate
Real Data: 5% of payments fail in peak hours. Simulated Data: Markov chain predicts 4.8% failures. Conclusion: Model is valid (error < 5%).
6. Tools for Simulation
| Tool | Type | Best For | Example Use Case |
|---|---|---|---|
| AnyLogic | Commercial (GUI) | Industrial-scale DES | NTC network traffic simulation |
| SimPy | Python library | Custom DES scripts | Pathao ride dispatch |
| R (simmer) | Statistical modeling | Queueing/Monte Carlo | NEPSE stock analysis |
| Excel | Spreadsheet | Small-scale Monte Carlo | Daraz delivery time estimates |
In the Real World
eSewa/Khalti:
- Idea: Queueing theory (M/M/c) models payment processing queues.
- How: During Dashain,
λspikes to 200 payments/minute. eSewa usesc=50 serversto keepL_q < 5(no crashes). - Real Output: [IMAGE: "eSewa payment success screen" | "eSewa’s transaction queue management dashboard"]
Pathao:
- Idea: Discrete-event simulation (DES) schedules drivers.
- How: Events = "ride requested," "driver assigned," "ride completed." Simulates 10,000 rides/day to optimize driver routes.
- Real Output: [IMAGE: "Pathao driver app ride assignment screen" | "Pathao’s DES-based dispatch system"]
Ncell:
- Idea: Markov chains predict call drops.
- How: States = "active call," "dropped," "reconnected." Transition
P(dropped→reconnected) = 0.7guides tower placements. - Real Output: [IMAGE: "Ncell network coverage map" | "Ncell’s Markov-based call-drop heatmap"]
Exam Tip
Case Study Structure:
- Problem: State the real-world scenario (e.g., "NTC call center").
- Model: Name the technique (e.g., "M/M/c queueing").
- Assumptions: List simplifications (e.g., "Poisson arrivals").
- Solution: Show calculations/formulas.
- Validation: Compare to real data (e.g., "Simulated
L_qmatches actual wait times").
Common Pitfalls:
- Forgetting to define states in Markov chains (lose marks!).
- Misapplying Poisson vs. Exponential distributions in queueing.
- Ignoring validation in case studies (always compare to real data).
High-Score Tips:
- Draw diagrams: Always include a state diagram (Markov) or queue flowchart (DES).
- Use real numbers: Even if hypothetical, base on Nepalese data (e.g., "λ=100 calls/hour for NTC").
- Link to tools: Mention which software could implement the model (e.g., "This Markov chain could be coded in Python using
numpy").
Summary Table: When to Use Which Technique
| Problem Type | Technique | Example | Tool |
|---|---|---|---|
| State-dependent systems | Markov chains | Ncell call drops | Python, AnyLogic |
| Wait-time optimization | Queueing theory (M/M/c) | eSewa payment queues | SimPy, Excel |
| Uncertainty/risk analysis | Monte Carlo | NEPSE stock prices | R, Python |
| Scheduling resources | Discrete-event simulation | Pathao driver dispatch | AnyLogic |
| Comparing models to reality | Validation | Daraz delivery time vs. simulation | Historical data |
Based on the TU BSc CSIT syllabus for Simulation and Modeling (CSC317), unit 10.
Discussion
Loading…