Simulation & Modelling

Complete Exam Study Guide โ€” KCA University ยท BIT 2201 / BBIT 308

Dec 2023 Dec 2024 Apr 2025 Aug 2025 Dec 2025

๐Ÿ”Š Voice Settings

Tip: Look for voices containing "Kenya", "en-KE", or "Swahili" for the closest Kenyan sound. Edge browser has the best voice selection.

Ready
1.0ร—
1 What is Simulation?

Simulation is the process of designing a model of a real system and conducting experiments with that model to understand the behaviour of the system or evaluate strategies for its operation.

It imitates the operations of real-world processes or systems over time, using a computer to generate artificial history.

Think of simulation as a "digital rehearsal" โ€” you run the show on a model before committing to the real thing.
2 When to Use Simulation (and When NOT to)

โœ… Use Simulation When:

  • The real system does not yet exist (designing a new hospital, airport)
  • Experimenting with the real system would be too dangerous, costly, or disruptive
  • The system is too complex for analytical (mathematical) solutions
  • You want to compress or expand time (test 10 years of operation in minutes)
  • You need to observe system behaviour under different what-if scenarios

โŒ Do NOT Use Simulation When:

  • A simple analytical or mathematical solution already exists
  • Common sense or direct experimentation is cheaper and faster
  • The problem is straightforward and well-understood
  • Resources (time, money, expertise) are insufficient to build a valid model
3 Benefits & Limitations vs Mathematical Formulae Q1a โ€” Every Paper

Benefits (pick 2)

  1. Handles complexity โ€” Simulation can model systems too complex for closed-form mathematical solutions (e.g., queues with non-Poisson arrivals)
  2. Risk-free experimentation โ€” Test policies and scenarios without disrupting the real system or incurring real costs
  3. Time flexibility โ€” Can slow down or speed up time; observe rare events that formulae can't easily represent
  4. Visual & intuitive โ€” Results are easier for non-mathematicians to understand and communicate

Limitations (pick 1)

  1. Not exact โ€” Results are estimates with statistical error; requires many runs for accuracy
  2. Time and cost โ€” Building and validating a good simulation model is expensive and time-consuming
  3. Garbage in, garbage out โ€” A poorly built model produces misleading results
  4. Requires expertise โ€” Need statistical knowledge to design and interpret simulation experiments correctly
4 Real-World Applications Q1b โ€” Every Paper
Problem AreaExampleSolution Method
Banking / QueuingCustomer wait times at bank tellersQueuing simulation (single/multi-server)
ManufacturingProduction line throughput, bottleneck analysisDiscrete-event simulation
Inventory / Supply ChainOptimizing stock levels, lead timesMonte Carlo simulation
TransportationTraffic flow, bus scheduling, route optimizationAgent-based / DES models
HealthcareHospital capacity planning, emergency room flowDiscrete-event simulation
Finance / InvestmentPortfolio risk analysis, project NPVMonte Carlo simulation
Military / EmergencyEvacuation planning, disaster responseAgent-based simulation
5 Steps in a Simulation Exercise Q1c โ€” Every Paper
  1. Problem Formulation โ€” Define the problem clearly; set objectives and scope of the study
  2. Data Collection & Analysis โ€” Gather real-world data; identify probability distributions that fit the data
  3. Model Building โ€” Construct the simulation model representing the real system
  4. Verification โ€” Check that the model works as intended (does the code do what you designed?)
  5. Validation โ€” Check that the model accurately represents the real system (does the model match reality?)
  6. Experimental Design โ€” Define what scenarios to run, number of replications, run length
  7. Run Simulation & Collect Results โ€” Execute the model and gather output statistics
  8. Analysis & Interpretation โ€” Analyse results using statistical methods; draw conclusions
  9. Documentation & Implementation โ€” Report findings; implement recommendations in the real system
Verification asks: "Did I build the model right?" Validation asks: "Did I build the right model?"
1. Problem Formulation 2. Data Collection 3. Model Building 4. Verification Built it right? 5. Validation Right model? Valid? No โ†’ revise Yes 6. Experimental Design 7. Run & Collect 8. Analysis 9. Documentation & Implement
1 Discrete vs Continuous Systems Dec 2024 Q1a

Discrete Systems

State variables change at specific, countable points in time (events).

Examples:

  • Bank queue: changes when customer arrives or leaves
  • Traffic light: changes state at specific times
  • Manufacturing: machine breaks down at a specific moment

Continuous Systems

State variables change continuously over time.

Examples:

  • Water tank: water level changes continuously
  • Chemical reaction: concentration changes over time
  • Population growth: changes continuously
2 Deterministic vs Stochastic Models Dec 2023 Q1b

Deterministic

No randomness โ€” given the same inputs, you always get the same output.

Example: A machine that always takes exactly 5 minutes to produce one unit.

Used when variability is negligible or unimportant.

Stochastic

Includes randomness โ€” outputs vary even with the same inputs.

Example: Customer service time follows an exponential distribution โ€” each customer takes a different random time.

More realistic for most real-world systems.

3 Static vs Dynamic Models Dec 2023 Q1b

Static

Represents a system at a single point in time; time does not play a role.

Example: Monte Carlo simulation to estimate the value of ฯ€.

Dynamic

Represents a system as it evolves over time.

Example: Queuing simulation tracking customers arriving, waiting, and departing over hours.

4 State Variables in a Single-Server Model Dec 2024 Q1b

State variables describe the current condition of the system at any point in time:

  • Number of customers in the queue โ€” how many are waiting
  • Server status โ€” busy (1) or idle (0)
  • Number of customers in the system โ€” queue + those being served
  • Time of last event โ€” when the last arrival or departure occurred

Events in a Single-Server Model

  • Arrival event โ€” a new customer joins the system
  • Departure/Service completion event โ€” server finishes with a customer; next customer (if any) begins service
  • End-of-simulation event โ€” the stopping condition is reached
5 Verification vs Validation

Verification

Ensuring the simulation model correctly implements the conceptual model.

"Did we build the model right?"

Methods: Code review, trace through the model step-by-step, check with known simple cases.

Validation

Ensuring the simulation model is an accurate representation of the real system.

"Did we build the right model?"

Methods: Compare output to historical data, statistical hypothesis tests, expert review.

6 Challenges of Optimisation Through Simulation Dec 2023 Q1e
  • Large solution space โ€” there may be millions of possible combinations of input variables to explore
  • Noisy responses โ€” simulation output is stochastic; the same input can give different outputs in different runs
  • Computational cost โ€” each simulation run takes time; evaluating all options is infeasible
  • Local vs global optima โ€” algorithms may get stuck in a local optimum and miss the global best
  • Warm-up period โ€” initial transient effects bias results if not handled correctly
1 Queuing Simulation Concepts

A queuing simulation tracks customers arriving, waiting, being served, and leaving. The key metrics to compute are:

MetricFormula
Average Waiting TimeTotal waiting time รท Total customers
Probability of Waiting (P_wait)Customers who waited > 0 รท Total customers
Probability of Idle Server (P_idle)Total idle time รท Total simulation time
Average Time in SystemTotal time in system รท Total customers
2 How to Fill a Simulation Table

Given: inter-arrival times and service times for each customer.

  1. Arrival Time = Previous arrival time + Inter-arrival time (Customer 1 arrives at time 0)
  2. Time Service Begins = MAX(Arrival Time, Previous Service End Time)
  3. Wait in Queue = Time Service Begins โˆ’ Arrival Time
  4. Time Service Ends = Time Service Begins + Service Time
  5. Time in System = Time Service Ends โˆ’ Arrival Time
  6. Idle Time of Server = MAX(0, Arrival Time โˆ’ Previous Service End Time) [only if server was free when customer arrived]
Server Idle Time is only recorded when a customer arrives and finds the server free โ€” it's the gap between the previous service ending and the new customer starting service.
SERVER Idle QUEUE EXIT โ†’
Speed: t = 0
๐Ÿงฎ Interactive Simulation Table Builder

Enter IAT & Service Time, then fill in each cell. Click Check for instant feedback.

3 Worked Example โ€” Bank Simulation Q1d โ€” Dec 2025 & Aug 2025

From the 20-customer simulation table given in the exam paper, here's how to compute the three required metrics:

Step 1: Extract the totals from the table

ColumnTotal (Sum)
Time Customer Waits in Queue0+0+0+3+0+0+0+4+6+8+8+10+10+8+6+3+6+7+6+1 = 86 minutes
Idle Time of Server0+4+0+0+0+0+4+0+0+0+0+0+0+0+0+0+0+0+0+0 = 8 minutes
Customers who waited (>0 minutes)Customers 4,8,9,10,11,12,13,14,15,16,17,18,19,20 = 14 customers

Step 2: Calculate the metrics

Average Waiting Time = Total Wait / Number of Customers = 86 / 20 = 4.3 minutes
Probability of Waiting = Customers who waited / Total customers = 14 / 20 = 0.70 (70%)
Probability of Idle Server = Total Idle Time / Total Simulation Time = 8 / 86 โ‰ˆ 0.093 (9.3%)
Total simulation time = last service end time = 86 minutes (from the table, customer 20 service ends at 86).
4 M/M/1 Queuing Formulae (Analytical) Dec 2024 Q1e

When arrival rate ฮป and service rate ฮผ are given (not a simulation table), use these formulae:

Let ฯ = ฮป/ฮผ (traffic intensity / server utilisation)

MetricFormula
Prob. server is idle (Pโ‚€)Pโ‚€ = 1 โˆ’ ฯ = 1 โˆ’ ฮป/ฮผ
Prob. customer receives immediate service= Pโ‚€ = 1 โˆ’ ฯ
Avg number in system (L)L = ฯ / (1 โˆ’ ฯ)
Avg time in system (W)W = 1 / (ฮผ โˆ’ ฮป)
Avg number in queue (Lq)Lq = ฯยฒ / (1 โˆ’ ฯ)
Avg wait in queue (Wq)Wq = ฮป / [ฮผ(ฮผ โˆ’ ฮป)]
โœ๏ธ Charles the Barber Example Dec 2024 Q1e

ฮป = 3 customers/hour, ฮผ = 4 customers/hour, ฯ = 3/4 = 0.75

  • Proportion idle: Pโ‚€ = 1 โˆ’ 0.75 = 0.25 (25%)
  • Prob. immediate service: = 0.25 (same as above)
  • Avg customers in system: L = 0.75/(1โˆ’0.75) = 0.75/0.25 = 3 customers
  • Avg time in system: W = 1/(4โˆ’3) = 1/1 = 1 hour
๐Ÿ“ M/M/1 Queue Calculator
5 Grocery Store / Simple Queue Simulation Apr 2025 Q2

Given IAT and ST sequences, build the simulation table the same way as the bank example:

IAT: 0 1 1 6 3 7 5 2 4 1 โ†’ Customer 1 arrives at t=0, Customer 2 at t=0+1=1, etc.

Once the table is built, compute:

  • Average waiting time = Sum of all queue wait times / 8 customers
  • Idle time of server = Sum of all server idle time entries
  • Average service time = Sum of all service times / 8 customers
1 Monte Carlo Simulation โ€” Core Idea

Monte Carlo simulation uses random numbers to sample from probability distributions and simulate the behaviour of a system many times, then averages the results.

Steps:

  1. Identify the uncertain variables and their probability distributions
  2. Assign random number ranges to each outcome (cumulative distribution)
  3. Use random numbers to look up simulated values
  4. Calculate the outcome for each trial
  5. Average the results across all trials

Advantages

  • Can handle complex, interdependent variables
  • Provides a range of possible outcomes (risk profile)
  • Easy to understand and explain
  • Flexible โ€” works with any distribution

Disadvantages

  • Only as good as the input distributions (GIGO)
  • Requires many trials for accurate results
  • Computationally intensive
  • Results are approximate, not exact
2 Assigning Random Number Ranges

Convert a probability table into cumulative probabilities, then map ranges of random numbers to each value:

ValueProbCumulative ProbRN Range
450.030.0300โ€“02
460.050.0803โ€“07
470.070.1508โ€“14
480.100.2515โ€“24
490.150.4025โ€“39
500.200.6040โ€“59
510.150.7560โ€“74
520.100.8575โ€“84
530.070.9285โ€“91
540.050.9792โ€“96
550.031.0097โ€“99
Rule: RN range starts right after the previous range ends. RN 00 maps to the first value if its cum prob covers it. Use 2-digit RNs (00โ€“99) for 2-digit random numbers.
3 Truck Production Simulation Q2 โ€” Dec 2025 & Aug 2025

Train capacity = 51 trucks. Shortfall = max(0, 51 โˆ’ production). Excess = max(0, production โˆ’ 51).

Random numbers: 05, 34, 78, 56, 45, 90, 04, 58, 92, 39

DayRNProductionShortfallExcess
10546 (RN 03โ€“07)50
23449 (RN 25โ€“39)20
37852 (RN 75โ€“84)01
45650 (RN 40โ€“59)10
54550 (RN 40โ€“59)10
69053 (RN 85โ€“91)02
70446 (RN 03โ€“07)50
85850 (RN 40โ€“59)10
99254 (RN 92โ€“96)03
103949 (RN 25โ€“39)20
Total176

Avg shortfall: 17/10 = 1.7 trucks/day  |  Avg excess: 6/10 = 0.6 trucks/day

The last random number given is often a decoy or for an 11th simulation day. Only use what the question asks for (10 days here).
4 Jambo Ltd โ€” Profit Simulation Dec 2023 Q2b

Formula: Profit = (Selling Price โˆ’ Variable Cost) ร— Demand โˆ’ Investment

Each trial: use random numbers to look up a selling price, a variable cost, and a demand. Calculate profit for that trial. Average across all 10 trials.

Build RN ranges for each variable separately (price, cost, demand). Then use the next RN in the list for each variable in sequence.
๐ŸŽฒ Random Number Generator Playground
1 Properties of Good Pseudo-Random Numbers
  • Uniformly distributed on [0,1]
  • Statistically independent โ€” knowing one number tells you nothing about the next
  • Long period โ€” the sequence should not repeat for a very long time
  • Reproducible โ€” same seed gives same sequence (useful for debugging)
  • Fast to generate computationally
Seed: The starting value for a pseudo-random number generator. Same seed โ†’ same sequence.
Period: The length of the sequence before it repeats.
2 Linear Congruential Generator (LCG) Multiple Papers
X_{n+1} = (a ร— X_n + c) mod m

Where: Xโ‚€ = seed, a = multiplier, c = increment, m = modulus

To get U โˆˆ [0,1]: divide by m: U = X / m

When c = 0, it's the Multiplicative Congruential Generator:

X_{n+1} = (a ร— X_n) mod m
โœ๏ธ Example: Xโ‚€=63, a=19, c=0, m=100 Q3 โ€” Multiple Papers
Xโ‚ = (19 ร— 63) mod 100 = 1197 mod 100 = 97
Xโ‚‚ = (19 ร— 97) mod 100 = 1843 mod 100 = 43
Xโ‚ƒ = (19 ร— 43) mod 100 = 817 mod 100  = 17
Xโ‚„ = (19 ร— 17) mod 100 = 323 mod 100  = 23
Xโ‚… = (19 ร— 23) mod 100 = 437 mod 100  = 37

So Xโ‚… = 37, giving Uโ‚… = 0.37

Skip-Ahead Formula

X_{i+n} = (aโฟ ร— X_i) mod m = ((aโฟ mod m) ร— X_i) mod m

This lets you jump n steps ahead without computing all intermediate values.

3 L'Ecuyer Combined Generator Dec 2023 Q3b & Dec 2024 Q4c

Combines three multiplicative generators for a very long period (~8ร—10ยนยฒ):

Parameters: aโ‚=157, mโ‚=32363  |  aโ‚‚=146, mโ‚‚=31727  |  aโ‚ƒ=142, mโ‚ƒ=31657

X_{1,n} = (157 ร— X_{1,n-1}) mod 32363 X_{2,n} = (146 ร— X_{2,n-1}) mod 31727 X_{3,n} = (142 ร— X_{3,n-1}) mod 31657 Y_n = (X_{1,n} - X_{2,n} + X_{3,n}) mod 32362 U_n = Y_n / 32363
โœ๏ธ First iteration: Xโ‚,โ‚€=100, Xโ‚‚,โ‚€=300, Xโ‚ƒ,โ‚€=500
Xโ‚,โ‚ = (157 ร— 100) mod 32363 = 15700 mod 32363 = 15700
Xโ‚‚,โ‚ = (146 ร— 300) mod 31727 = 43800 mod 31727 = 12073
Xโ‚ƒ,โ‚ = (142 ร— 500) mod 31657 = 71000 mod 31657 = 7686

Yโ‚ = (15700 - 12073 + 7686) mod 32362 = 11313 mod 32362 = 11313
Uโ‚ = 11313 / 32363 โ‰ˆ 0.3496

Repeat for iterations 2โ€“5 using Xโ‚,โ‚, Xโ‚‚,โ‚, Xโ‚ƒ,โ‚ as new seeds.

4 Middle-Square Method Apr 2025 Q3d

Proposed by John von Neumann. To generate n-digit numbers:

  1. Start with an n-digit seed
  2. Square it to get a 2n-digit number
  3. Extract the middle n digits as the next number
  4. Repeat
This method fails spectacularly: it can degenerate to 0 (once you hit 0, squaring always gives 0) or cycle in very short loops. Von Neumann himself acknowledged this. Example: seed = 5765 โ†’ 5765ยฒ = 33234225 โ†’ middle 4 digits = 2342 โ†’ 2342ยฒ = 5484964 โ†’ 4849 โ†’ ... can quickly collapse.
5 Fibonacci & Mitchell-Moore Generators Dec 2025 Q3b,c

Fibonacci Generator

X_n = (X_{n-1} + X_{n-2}) mod m
# R implementation
fibonacci_rng <- function(n, x0) {
  x <- numeric(n + 2)
  x[1] <- x0[1]; x[2] <- x0[2]  # need 2 seeds
  for (i in 3:(n+2)) x[i] <- (x[i-1] + x[i-2]) %% 1
  return(x[3:(n+2)])
}

Mitchell-Moore Generator

X_n = (X_{n-24} + X_{n-55}) mod m [uses 55-element seed vector]
# R implementation
mitchell_moore <- function(n, x0) {  # x0 must be length 55
  x <- c(x0, numeric(n))
  for (i in 56:(55+n)) x[i] <- (x[i-24] + x[i-55]) %% 1
  return(x[56:(55+n)])
}
6 Transforming Uniform Random Numbers to Different Intervals

To transform U ~ Uniform[0,1] to Uniform[a, b]:

X = a + (b - a) ร— U

Examples:

  • Uniform[โˆ’11, 17]: X = โˆ’11 + (17 โˆ’ (โˆ’11)) ร— U = โˆ’11 + 28U
  • Uniform[โˆ’148, 1128]: X = โˆ’148 + 1276U
  • Uniform[โˆ’160, 200]: X = โˆ’160 + 360U
๐Ÿ“Š Random Variate Calculator
Data shape? Symmetric Normal Right-skewed Var โ‰ˆ Meanยฒ? No Gamma Yes Exponential Bounded Has a mode? Yes Triangular No Uniform Discrete? Count data? Yes Poisson Lifetime? Weibull Empirical CDF
1 Inverse CDF Method (Inversion)

The most common technique. If F(x) is the CDF, set F(x) = U (uniform random number) and solve for x:

x = Fโปยน(U)

Works perfectly when Fโปยน has a closed form.

2 Common Distribution Generators

Exponential Distribution (mean = ฮฒ)

X = โˆ’ฮฒ ร— ln(U) [or X = โˆ’(1/ฮป) ร— ln(U) where ฮป = 1/ฮฒ]
โœ๏ธ Lead times ~ Exp(mean=3.7 days) Multiple Papers
Generate 5 values using U: 0.12, 0.45, 0.78, 0.33, 0.91 (example)
X = -3.7 ร— ln(U)
Xโ‚ = -3.7 ร— ln(0.12) = -3.7 ร— (-2.12) = 7.85 days
Xโ‚‚ = -3.7 ร— ln(0.45) = -3.7 ร— (-0.80) = 2.95 days  ...

Uniform Distribution on [a, b]

X = a + (b โˆ’ a) ร— U

Normal Distribution (mean=ฮผ, variance=ฯƒยฒ)

Use Box-Muller or standard normal table. In R: rnorm(n, mean=ฮผ, sd=ฯƒ)

Z = ฮฆโปยน(U) then X = ฮผ + ฯƒZ
โœ๏ธ Maintenance times ~ Normal(ฮผ=33, ฯƒยฒ=4, so ฯƒ=2) Apr 2025 Q4b

Generate 5 values: look up Z from standard normal table using U, then X = 33 + 2Z

Weibull Distribution (shape ฮฑ, scale ฮฒ)

X = ฮฒ ร— [โˆ’ln(U)]^(1/ฮฑ)

For the fluorescent bulb: P(T > t) = e^(โˆ’(t/1000)โต). Set U = e^(โˆ’(T/1000)โต), solve for T:

T = 1000 ร— [โˆ’ln(U)]^(1/5)

Discrete Distribution (Empirical)

Build a CDF table. For each U, find the x value where F(x) first exceeds U.

โœ๏ธ Empirical Distribution Dec 2024 Q2

x: 1, 2, 4, 6, 8, 10 with f(x): 0.10, 0.20, 0.25, 0.20, 0.15, 0.10

xf(x)F(x)RN Range
10.100.100.00โ€“0.10
20.200.300.10โ€“0.30
40.250.550.30โ€“0.55
60.200.750.55โ€“0.75
80.150.900.75โ€“0.90
100.101.000.90โ€“1.00

U=0.05 โ†’ x=1; U=0.45 โ†’ x=4; U=0.62 โ†’ x=6; U=0.90 โ†’ x=10

3 Discrete CDF Generator Q4a โ€” Aug 2025 & Dec 2025

Given: F(x) = x(x+1)(2x+1) / [n(n+1)(2n+1)] for x = 1, 2, โ€ฆ, n. With n=4:

Denominator = 4 ร— 5 ร— 9 = 180
xNumerator x(x+1)(2x+1)F(x)
11ร—2ร—3 = 66/180 = 0.033
22ร—3ร—5 = 3030/180 = 0.167
33ร—4ร—7 = 8484/180 = 0.467
44ร—5ร—9 = 180180/180 = 1.000

Find x such that F(xโˆ’1) < U โ‰ค F(x):

  • Rโ‚ = 0.83 โ†’ F(3)=0.467 < 0.83 โ‰ค F(4)=1.000 โ†’ x = 4
  • Rโ‚‚ = 0.24 โ†’ F(2)=0.167 < 0.24 โ‰ค F(3)=0.467 โ†’ x = 3
  • Rโ‚ƒ = 0.57 โ†’ F(3)=0.467 < 0.57 โ‰ค F(4)=1.000 โ†’ x = 4
4 Triangular Distribution Dec 2023 & Dec 2024 Q3/Q4

Range (a, b), mode at c. True mean = (a + b + c) / 3

For range (1,10), mode at 4: True mean = (1+10+4)/3 = 5

c* = (c โˆ’ a) / (b โˆ’ a) = (4 โˆ’ 1)/(10 โˆ’ 1) = 3/9 = 1/3 โ‰ˆ 0.333 If U โ‰ค c*: X = a + โˆš[U ร— (bโˆ’a) ร— (cโˆ’a)] If U > c*: X = b โˆ’ โˆš[(1โˆ’U) ร— (bโˆ’a) ร— (bโˆ’c)]

Beta Distribution

In R: rbeta(n, shape1=ฮฒโ‚, shape2=ฮฒโ‚‚) generates values on [0,1]. To transform to [L, H]: X = L + (Hโˆ’L) ร— U_beta

5 R Code for Common Distributions
# Exponential (mean = 3.7)
rexp(5, rate = 1/3.7)

# Normal (mean=33, variance=4, so sd=2)
rnorm(5, mean=33, sd=2)

# Gamma (shape=3, scale=1)
rgamma(10000, shape=3, scale=1)

# Beta
rbeta(10, shape1=1.47, shape2=2.16)

# Weibull (shape=5, scale=1000)
rweibull(n, shape=5, scale=1000)

# Chi-squared (k degrees of freedom)
rchisq(n, df=k)  # or: sum of k squared standard normals

# Binomial P(X = 25000) where X ~ Bin(50000, 0.5)
# Method 1:
dbinom(25000, size=50000, prob=0.5)

# Method 2 (using sum, log, exp only):
n <- 50000; k <- 25000; p <- 0.5
log_prob <- sum(log(1:n)) - sum(log(1:k)) - sum(log(1:(n-k))) + k*log(p) + (n-k)*log(1-p)
exp(log_prob)
1 Time Advance Mechanisms Apr 2025 Q2a

Fixed-Time Increment (Fixed-Step)

The simulation clock advances by a fixed small amount (ฮ”t) at each step. Check if any events occurred in that interval.

โœ“ Simple to implement

โœ“ Good for continuous-time systems

โœ— Wasteful if events are rare (many empty time steps)

โœ— May miss events between steps if ฮ”t too large

Next-Event Time Advance

The clock jumps directly to the time of the next event. Maintains a future event list (FEL) sorted by event time.

โœ“ Efficient โ€” no wasted steps

โœ“ Standard for discrete-event simulation

โœ— More complex to implement

โœ— Requires maintaining and sorting the event list

2 Future Event List (FEL) & Simulation Table Dec 2023 Q3a

The simulation table tracks: Clock time, Server status, Queue length, Future events.

Given: IAT = 1, 5, 6, 3, 8 and ST = 3, 5, 4, 1, 5

ClockEventServerQueueNext ArrivalNext Departure
0StartIdle01โˆž
1C1 arrivesBusy064
4C1 departsIdle06โˆž
6C2 arrivesBusy01211
11C2 departsIdle012โˆž
12C3 arrivesBusy01516
15C4 arrivesBusy12316
At each event, update: (1) server status, (2) queue, (3) schedule next events. Stop when clock reaches stopping time (30 in this problem).
3 Port/Barge Simulation Apr 2025 Q1c

Two probability tables: arrivals per day and unloading rate per day. Build RN ranges for each, then simulate day by day tracking:

  • Barges arriving each day
  • Barges unloaded each day (limited by unloading rate and barges available)
  • Barges delayed (queue carrying over to next day)

Metrics: Avg barges delayed = Total delayed / Days; Avg arrivals/day; Avg offloaded/day.

4 Non-Stationary Poisson Process (NSPP) Dec 2024 Q4a

When arrival rates change over time (e.g., rush hours), the arrival rate ฮป(t) is estimated from data:

ฮป(t) = Average arrivals in that time period / Length of period (hours)

Example: 8:00โ€“10:00 has counts 22, 24, 20, 28 across 4 days โ†’ avg = 94/4 = 23.5 arrivals โ†’ ฮป = 23.5/2 = 11.75 arrivals/hour

1 AR(1) and EAR(1) Models for Correlated Data Multiple Papers

When data shows autocorrelation (successive observations are related), use time-series models.

AR(1) โ€” Autoregressive Model

X_n = ฮผ + ฯ†(X_{n-1} โˆ’ ฮผ) + ฮต_n

Where ฯ† is the autocorrelation coefficient and ฮต_n ~ Normal(0, ฯƒยฒ(1โˆ’ฯ†ยฒ)). Works well for continuous, normally distributed data.

EAR(1) โ€” Exponential Autoregressive Model

Better for count data (integers, non-negative). Uses a mixture approach with a Bernoulli random variable.

To choose between them: Look at a histogram of the data. If bell-shaped/symmetric โ†’ AR(1). If skewed/count-like โ†’ EAR(1).

Hotel patrons data (20, 14, 21, 19, 14, 18, 21, 25, 27, 26, 22, 18, 13, 18, 18, 18, 25, 23, 20, 21) appears roughly normal โ†’ AR(1) likely fits better.

# R code for AR(1)
x <- c(20,14,21,19,14,18,21,25,27,26,22,18,13,18,18,18,25,23,20,21)
fit <- arima(x, order=c(1,0,0))
print(fit)
hist(x, main="Hotel Patrons")
2 Validating Simulation Output โ€” t-test Apr 2025 Q4e & Aug 2025 Q4e

Test if simulation output is consistent with real system behaviour.

Data: 7 replications: 18.9, 22.0, 19.4, 22.1, 19.8, 21.9, 20.2. Real-world average: ฮผโ‚€ = 22.5

Hโ‚€: ฮผ = 22.5 (model is valid) vs Hโ‚: ฮผ โ‰  22.5

n = 7
xฬ„ = (18.9+22.0+19.4+22.1+19.8+21.9+20.2)/7 = 144.3/7 = 20.614
sยฒ = ฮฃ(xแตข โˆ’ xฬ„)ยฒ / (nโˆ’1)

Deviations: -1.714, 1.386, -1.214, 1.486, -0.814, 1.286, -0.414
Squared:     2.939,  1.921,  1.474,  2.209,  0.663,  1.654,  0.171
Sum = 11.031  โ†’  sยฒ = 11.031/6 = 1.839  โ†’  s = 1.356

t = (xฬ„ โˆ’ ฮผโ‚€) / (s/โˆšn) = (20.614 โˆ’ 22.5) / (1.356/โˆš7)
  = โˆ’1.886 / 0.5124 = โˆ’3.68

Critical value: tโ‚€.โ‚€โ‚‚โ‚…,โ‚† = 2.447 (two-tailed, ฮฑ=0.05)

|t| = 3.68 > 2.447 โ†’ Reject Hโ‚€: the simulation output is NOT consistent with the real system. The model needs revision.

3 Input Modelling โ€” Fitting a Distribution Multiple Papers

Data: 0.740, 1.28, 1.46, 2.36, 0.354, 0.750, 0.912, 4.44, 0.114, 3.08, 3.24, 1.10, 1.59, 1.47, 1.17, 1.27, 9.12, 11.5, 2.42, 1.77

  1. Compute summary statistics: mean, variance, min, max
  2. Plot histogram to observe shape (skewed right โ†’ try Exponential or Gamma)
  3. Estimate parameters: For Exponential, mean โ‰ˆ 1/ฮป so ฮปฬ‚ = 1/xฬ„
  4. Goodness-of-fit test: Chi-square or K-S test to confirm fit
# R code for input modelling
data <- c(0.740,1.28,1.46,2.36,0.354,0.750,0.912,4.44,0.114,
           3.08,3.24,1.10,1.59,1.47,1.17,1.27,9.12,11.5,2.42,1.77)
mean(data); var(data); sd(data)
hist(data, probability=TRUE)
# If variance โ‰ˆ meanยฒ, try exponential
# If right-skewed, try gamma or lognormal
library(MASS)
fitdistr(data, "exponential")
fitdistr(data, "gamma")
4 Chi-Square Goodness-of-Fit Test Dec 2023 Q4d
ฯ‡ยฒ = ฮฃ [(Oแตข โˆ’ Eแตข)ยฒ / Eแตข]

Where Oแตข = observed frequency, Eแตข = expected frequency under the hypothesised distribution.

Degrees of freedom = k โˆ’ 1 โˆ’ (number of estimated parameters)

  • For Poisson with unknown mean: df = k โˆ’ 2 (estimated ฮป from data)
  • For Poisson with specified mean: df = k โˆ’ 1

Reject Hโ‚€ if ฯ‡ยฒ > ฯ‡ยฒ_{ฮฑ, df} from table.

Merge cells with expected frequency < 5 before computing the test statistic.
1 Full Simulation Table Construction

Given: IAT = 0,1,1,6,3,7,5,2 and ST = 4,2,5,4,1,5,4,1 for 8 customers (Customer 1 at t=0)

CustIATArrivalSvc TimeSvc BeginsWaitSvc EndsIn SystemServer Idle
100400440
211243650
3125641190
46841131570
531111541650
671851802352
752342302740
822512722830

Total wait: 0+3+4+3+4+0+0+2 = 16 | Avg wait: 16/8 = 2.0 min

Total idle: 2 min | Sim ends at: t=28

P(wait): 5/8 = 0.625 | P(idle): 2/28 โ‰ˆ 0.071

Avg svc time: (4+2+5+4+1+5+4+1)/8 = 26/8 = 3.25 min

2 Transforming Uniform RNs to [โˆ’11, 17]

Formula: X = โˆ’11 + 28U

Given U ~ Uniform[0,1], generate X ~ Uniform[โˆ’11, 17]:

  • U = 0.25 โ†’ X = โˆ’11 + 28(0.25) = โˆ’11 + 7 = โˆ’4
  • U = 0.80 โ†’ X = โˆ’11 + 28(0.80) = โˆ’11 + 22.4 = 11.4
3 Generator for F(x) = xโด/16 on [0,2] Dec 2023 Q4c

Set U = F(x) = xโด/16, solve for x:

xโด = 16U โ†’ x = (16U)^(1/4) = 2U^(1/4)

True mean: E[X] = โˆซโ‚€ยฒ x ร— f(x)dx where f(x) = xยณ/4

E[X] = โˆซโ‚€ยฒ x ร— (xยณ/4)dx = โˆซโ‚€ยฒ xโด/4 dx = [xโต/20]โ‚€ยฒ = 32/20 = 1.6

Generate sample values using Uโ‚, Uโ‚‚, ... โ†’ Xแตข = 2Uแตข^(0.25). Sample mean should โ‰ˆ 1.6.

4 R Code โ€” Die Roll Until 6 Q4b โ€” Aug & Dec 2025
simulate_die <- function() {
  rolls <- 0
  while (TRUE) {
    rolls <- rolls + 1
    if (sample(1:6, 1) == 6) return(rolls)
  }
}

# Run it
simulate_die()

# Many runs to get average
mean(replicate(10000, simulate_die()))  # Should be โ‰ˆ 6
5 Chi-Square Test โ€” Coal Mine Injuries Dec 2023 Q4d

Data: injuries per month over 100 months. Test if Poisson distributed.

data <- c(rep(0,35), rep(1,40), rep(2,13), rep(3,6), rep(4,4), rep(5,1), rep(6,1))
lambda_hat <- mean(data)  # = (0ร—35+1ร—40+2ร—13+3ร—6+4ร—4+5ร—1+6ร—1)/100 = 100/100 = 1.0

# Expected frequencies (n=100, Poisson with ฮป=1)
E <- 100 * dpois(0:6, lambda=lambda_hat)
# Observed
O <- c(35, 40, 13, 6, 4, 1, 1)

# Merge last cells if E < 5
# chi-square
chi_sq <- sum((O - E)^2 / E)
df <- length(O) - 1 - 1  # minus 1 for estimated lambda
qchisq(0.95, df)  # critical value
๐Ÿ—‚ Formula Cheat Sheet

Queuing Metrics

MetricFormula
Avg Wait TimeฮฃWait / n
P(wait > 0)Customers who waited / n
P(server idle)Total idle time / Total sim time
Server utilisation ฯฮป/ฮผ
P(server idle) M/M/11 โˆ’ ฯ
L (avg in system)ฯ/(1โˆ’ฯ)
W (avg time in system)1/(ฮผโˆ’ฮป)

Random Number Generation

MethodFormula
LCGX_{n+1} = (aX_n + c) mod m
Multiplicative CGX_{n+1} = aX_n mod m (c=0)
Skip-aheadX_{i+n} = (a^n mod m ร— X_i) mod m
Transform [0,1]โ†’[a,b]X = a + (bโˆ’a)U

Random Variate Generation

DistributionGenerator
Exponential(ฮฒ)X = โˆ’ฮฒ ln(U)
Uniform[a,b]X = a + (bโˆ’a)U
Weibull(ฮฑ,ฮฒ)X = ฮฒ[โˆ’ln(U)]^(1/ฮฑ)
Triangular (Uโ‰คc*)X = a + โˆš[U(bโˆ’a)(cโˆ’a)]
Triangular (U>c*)X = b โˆ’ โˆš[(1โˆ’U)(bโˆ’a)(bโˆ’c)]
NormalX = ฮผ + ฯƒฮฆโปยน(U)

Statistical Tests

TestFormula
t-test (validate sim)t = (xฬ„ โˆ’ ฮผโ‚€)/(s/โˆšn); df=nโˆ’1
Chi-square GOFฯ‡ยฒ = ฮฃ(Oโˆ’E)ยฒ/E; df=kโˆ’1โˆ’p
๐Ÿ“Œ High-Probability Exam Topics
Based on ALL 5 past papers โ€” these appear in almost every exam:
  1. Q1 (Compulsory): 2 benefits + 1 limitation of simulation; 4 real-world applications; steps in simulation; queuing table (compute avg wait, P_wait, P_idle)
  2. Monte Carlo Production Simulation: Build RN ranges from probability table; simulate 10 days; compute shortfalls/excesses
  3. Random Number Generation: LCG computation (Xโ‚€, a, c, m given); L'Ecuyer combined generator; transforming U[0,1] to U[a,b]
  4. Random Variate Generation: CDF inversion; exponential; discrete CDF table
  5. R Code: Simulation of distributions (gamma, chi-square, exponential, die roll)
  6. AR(1)/EAR(1): Fitting to hotel patron data; deciding which fits better from histogram
  7. Validation t-test: job shop replication data vs. ฮผโ‚€ = 22.5
Questions 2, 3, 4 are optional โ€” choose the ones with topics you know best. The truck simulation (Q2) is the most mechanical and safest to attempt if you practice it once.
๐Ÿ“– Key Definitions to Memorise
TermDefinition
SimulationImitation of a real-world system over time using a model
SeedThe initial value Xโ‚€ used to start a pseudo-random number generator
PeriodThe length of a pseudo-random sequence before it begins to repeat
VerificationChecking the model is coded correctly ("built it right")
ValidationChecking the model represents reality ("built the right model")
StochasticA model incorporating randomness
DeterministicA model with no randomness; same inputs โ†’ same outputs always
Discrete systemState changes at countable points in time (events)
Continuous systemState changes continuously over time
FCFSFirst Come First Served โ€” the standard queue discipline
Traffic intensity ฯฯ = ฮป/ฮผ; must be <1 for a stable queue
Monte CarloSimulation technique using random sampling to estimate outcomes
Questions sourced from past papers: Dec 2023 โ€“ Dec 2025
๐Ÿ“˜ Topic 1 โ€” Introduction to Simulation
1State two benefits and one limitation of using simulation as opposed to mathematical formulae to solve problems.3 marks
Benefits:
  1. Handles complexity โ€” Simulation can model systems too complex for closed-form solutions (e.g., queues with non-Poisson arrivals, multiple interacting variables).
  2. Risk-free experimentation โ€” Test policies, designs, and what-if scenarios without disrupting the real system or incurring real costs.
Limitation:
  1. Results are estimates, not exact โ€” Simulation output includes statistical noise; requires many replications and careful analysis to draw valid conclusions, unlike formulae which give exact answers.

2Give four different real-life problems that can be solved through simulation and briefly explain the simulation approach for each.4 marks
  1. Banking queues โ€” Simulate customer arrivals and service times to determine optimal number of tellers and expected wait times.
  2. Manufacturing โ€” Model a production line with machine breakdowns to identify bottlenecks and optimise throughput.
  3. Inventory management โ€” Use Monte Carlo simulation to determine reorder points and quantities under uncertain demand.
  4. Hospital emergency department โ€” Simulate patient arrivals, triage, and treatment to plan staff schedules and bed capacity.

3Describe the major steps involved in a simulation exercise.9 marks
  1. Problem Formulation โ€” Define objectives, scope, and boundaries of the study.
  2. Data Collection & Analysis โ€” Gather real-world data; identify probability distributions.
  3. Model Building โ€” Construct the simulation model (conceptual then computational).
  4. Verification โ€” Ensure the code correctly implements the conceptual model ("Built it right?").
  5. Validation โ€” Ensure the model accurately represents reality ("Built the right model?").
  6. Experimental Design โ€” Define scenarios, number of replications, run length, warm-up period.
  7. Run Simulation โ€” Execute the model and collect output statistics.
  8. Analysis & Interpretation โ€” Use statistical methods (confidence intervals, hypothesis tests) to interpret results.
  9. Documentation & Implementation โ€” Report findings and implement recommendations.
๐Ÿ“— Topic 2 โ€” Model Types & Classification
1Distinguish between discrete and continuous simulation models, giving an example of each.4 marks

Discrete: State variables change at specific, countable points in time (events). Example: a bank queue โ€” the number of customers changes only when someone arrives or departs.

Continuous: State variables change continuously over time. Example: water level in a tank โ€” it rises/falls smoothly as water flows in or out.


2Explain the difference between deterministic and stochastic models.4 marks

Deterministic: No randomness involved. Given the same inputs, you always get exactly the same output. Example: a machine that always takes exactly 5 minutes per unit.

Stochastic: Incorporates random variables. Outputs vary between runs even with the same inputs. Example: customer service times following an exponential distribution โ€” each customer takes a different random time.


3Describe the state variables and events in a single-server queuing model.4 marks

State variables:

  • Server status (busy or idle)
  • Number of customers in the queue
  • Number of customers in the system (queue + being served)
  • Time of the last event

Events:

  • Arrival event โ€” a new customer enters the system
  • Departure event โ€” server completes service; next customer begins or server goes idle
  • End-of-simulation event โ€” stopping condition is reached

4Discuss three challenges of optimisation through simulation.6 marks
  1. Large solution space โ€” Millions of combinations of input parameters may need evaluation, making exhaustive search impractical.
  2. Noisy/stochastic responses โ€” The same inputs produce different outputs across runs due to randomness, making it hard to distinguish true improvements from random variation.
  3. Computational cost โ€” Each simulation run is time-consuming; evaluating enough candidate solutions for reliable optimisation requires substantial compute resources.
๐Ÿ“™ Topic 3 โ€” Queuing Simulation
1Given the following data for a single-server queue with 8 customers: IAT = 0,1,1,6,3,7,5,2 and Service Times = 4,2,5,4,1,5,4,1. Construct the simulation table and compute: (i) average waiting time, (ii) probability that a customer has to wait, (iii) probability of idle server.15 marks
CustIATArrivalSTSvc BeginsWaitSvc EndsIn SystemIdle
100400440
211243650
3125641190
46841131570
531111541650
671851802352
752342302740
822512722830

(i) Avg waiting time = (0+3+4+3+4+0+0+2)/8 = 16/8 = 2.0 minutes

(ii) P(wait) = 5 customers waited / 8 total = 0.625 (62.5%)

(iii) P(idle) = Total idle time / Simulation end = 2/28 = 0.071 (7.1%)


2A barber shop has one barber. Customers arrive at a rate of ฮป = 3 per hour and the barber can serve at ฮผ = 4 per hour. Using M/M/1 formulae, calculate: (i) the proportion of time the barber is idle, (ii) probability a customer gets immediate service, (iii) average number of customers in the system, (iv) average time a customer spends in the system.8 marks

ฯ = ฮป/ฮผ = 3/4 = 0.75

(i) Proportion idle = Pโ‚€ = 1 โˆ’ ฯ = 1 โˆ’ 0.75 = 0.25 (25%)

(ii) P(immediate service) = Pโ‚€ = 0.25 (same as proportion idle)

(iii) Avg in system (L) = ฯ/(1โˆ’ฯ) = 0.75/0.25 = 3 customers

(iv) Avg time in system (W) = 1/(ฮผโˆ’ฮป) = 1/(4โˆ’3) = 1 hour

๐Ÿ“• Topic 4 โ€” Monte Carlo Simulation
1A train has a capacity of 51 trucks. Daily production follows a known distribution. Given the probability table and random numbers 05, 34, 78, 56, 45, 90, 04, 58, 92, 39 โ€” simulate 10 days and compute: (i) average daily shortfall, (ii) average daily excess.15 marks

Step 1: Build RN ranges from the cumulative probability table (see Tab 4, Card 2).

DayRNProductionShortfallExcess
1054650
2344920
3785201
4565010
5455010
6905302
7044650
8585010
9925403
10394920

(i) Avg shortfall = 17/10 = 1.7 trucks/day

(ii) Avg excess = 6/10 = 0.6 trucks/day


2Explain the Monte Carlo simulation technique and state two advantages and two disadvantages.6 marks

Monte Carlo simulation uses random numbers to sample from probability distributions repeatedly, then aggregates results to estimate system behaviour. Each trial draws random values for uncertain inputs, computes the outcome, and the average across many trials gives the estimated result.

Advantages: (1) Can handle complex, interdependent variables that have no analytical solution. (2) Provides a full range of possible outcomes (risk profile), not just a single point estimate.

Disadvantages: (1) Results are only as good as the input distributions โ€” garbage in, garbage out. (2) Requires many trials for accurate results, making it computationally intensive.

๐ŸŽฒ Topic 5 โ€” Random Number Generation
1Using the multiplicative congruential generator with Xโ‚€ = 63, a = 19, m = 100, generate the first 5 random numbers and their uniform equivalents.5 marks
X_{n+1} = (19 ร— X_n) mod 100
Xโ‚ = (19 ร— 63) mod 100 = 1197 mod 100 = 97   โ†’ Uโ‚ = 0.97
Xโ‚‚ = (19 ร— 97) mod 100 = 1843 mod 100 = 43   โ†’ Uโ‚‚ = 0.43
Xโ‚ƒ = (19 ร— 43) mod 100 = 817 mod 100  = 17   โ†’ Uโ‚ƒ = 0.17
Xโ‚„ = (19 ร— 17) mod 100 = 323 mod 100  = 23   โ†’ Uโ‚„ = 0.23
Xโ‚… = (19 ร— 23) mod 100 = 437 mod 100  = 37   โ†’ Uโ‚… = 0.37

2Using L'Ecuyer's combined generator with seeds Xโ‚,โ‚€=100, Xโ‚‚,โ‚€=300, Xโ‚ƒ,โ‚€=500, compute Uโ‚ (the first random number).5 marks
Xโ‚,โ‚ = (157 ร— 100) mod 32363 = 15700
Xโ‚‚,โ‚ = (146 ร— 300) mod 31727 = 12073
Xโ‚ƒ,โ‚ = (142 ร— 500) mod 31657 = 7686

Yโ‚ = (15700 โˆ’ 12073 + 7686) mod 32362 = 11313
Uโ‚ = 11313 / 32363 โ‰ˆ 0.3496

3State five desirable properties of a good pseudo-random number generator.5 marks
  1. Uniformly distributed on [0, 1] โ€” each value equally likely.
  2. Statistically independent โ€” knowing one number tells you nothing about the next.
  3. Long period โ€” the sequence should not repeat for a very long time.
  4. Reproducible โ€” same seed produces the same sequence (essential for debugging).
  5. Fast to generate โ€” computationally efficient for large-scale simulations.

4Transform U ~ Uniform[0,1] to generate values from Uniform[โˆ’11, 17]. Give the formula and compute X for U = 0.25 and U = 0.80.3 marks
X = a + (b โˆ’ a) ร— U = โˆ’11 + 28U

U = 0.25 โ†’ X = โˆ’11 + 28(0.25) = โˆ’11 + 7 = โˆ’4

U = 0.80 โ†’ X = โˆ’11 + 28(0.80) = โˆ’11 + 22.4 = 11.4

๐Ÿ“Š Topic 6 โ€” Random Variate Generation
1Lead times follow an Exponential distribution with mean ฮฒ = 3.7 days. Using the inverse CDF method, generate 3 lead times for U = 0.12, 0.45, 0.78.6 marks
X = โˆ’ฮฒ ร— ln(U) = โˆ’3.7 ร— ln(U)

U = 0.12 โ†’ X = โˆ’3.7 ร— ln(0.12) = โˆ’3.7 ร— (โˆ’2.120) = 7.85 days

U = 0.45 โ†’ X = โˆ’3.7 ร— ln(0.45) = โˆ’3.7 ร— (โˆ’0.799) = 2.95 days

U = 0.78 โ†’ X = โˆ’3.7 ร— ln(0.78) = โˆ’3.7 ร— (โˆ’0.248) = 0.92 days


2Given F(x) = xโด/16 on [0, 2], derive the random variate generator. What is the true mean E[X]?5 marks

Set U = F(x) = xโด/16, solve for x:

xโด = 16U โ†’ x = (16U)^(1/4) = 2U^(1/4)

True mean: f(x) = F'(x) = 4xยณ/16 = xยณ/4

E[X] = โˆซโ‚€ยฒ x ร— (xยณ/4) dx = โˆซโ‚€ยฒ xโด/4 dx = [xโต/20]โ‚€ยฒ = 32/20 = 1.6

3A Triangular distribution has range (1, 10) and mode at 4. Compute c* and generate X for U = 0.20 and U = 0.60.6 marks
c* = (c โˆ’ a)/(b โˆ’ a) = (4 โˆ’ 1)/(10 โˆ’ 1) = 3/9 = 0.333

U = 0.20 โ‰ค c* = 0.333:

X = 1 + โˆš(0.20 ร— 9 ร— 3) = 1 + โˆš5.4 = 1 + 2.324 = 3.324

U = 0.60 > c* = 0.333:

X = 10 โˆ’ โˆš((1โˆ’0.60) ร— 9 ร— 6) = 10 โˆ’ โˆš21.6 = 10 โˆ’ 4.648 = 5.352
โฑ๏ธ Topic 7 โ€” Discrete-Event Simulation
1Compare fixed-time increment and next-event time advance mechanisms. State one advantage and one disadvantage of each.4 marks

Fixed-Time Increment: Clock advances by a fixed ฮ”t each step. โœ“ Simple to implement; good for continuous systems. โœ— Wasteful if events are rare (many empty steps).

Next-Event Time Advance: Clock jumps directly to the next scheduled event. โœ“ Efficient โ€” no wasted time steps. โœ— More complex; requires maintaining and sorting a future event list (FEL).


2Construct a simulation table using next-event time advance for 5 customers with IAT = 1,5,6,3,8 and ST = 3,5,4,1,5. Show: Clock, Event, Server Status, Queue Length, Next Arrival, Next Departure.10 marks
ClockEventServerQueueNext ArrNext Dep
0StartIdle01โˆž
1C1 arrivesBusy064
4C1 departsIdle06โˆž
6C2 arrivesBusy01211
11C2 departsIdle012โˆž
12C3 arrivesBusy01516
15C4 arrivesBusy12316
16C3 departs, C4 startsBusy02317
17C4 departsIdle023โˆž
23C5 arrivesBusy0โˆž28
28C5 departsIdle0โˆžโˆž
๐Ÿ“ˆ Topic 8 โ€” Output Analysis & Validation
1A simulation of a job shop was replicated 7 times. The average job completion times were: 18.9, 22.0, 19.4, 22.1, 19.8, 21.9, 20.2. The real system average is ฮผโ‚€ = 22.5. Use a t-test at ฮฑ = 0.05 to determine whether the model is valid.10 marks

Hโ‚€: ฮผ = 22.5 (model is valid) vs Hโ‚: ฮผ โ‰  22.5 (two-tailed)

n = 7
xฬ„ = 144.3/7 = 20.614

Deviationsยฒ: 2.939, 1.921, 1.474, 2.209, 0.663, 1.654, 0.171
ฮฃ = 11.031 โ†’ sยฒ = 11.031/6 = 1.839 โ†’ s = 1.356

t = (20.614 โˆ’ 22.5) / (1.356/โˆš7) = โˆ’1.886 / 0.5124 = โˆ’3.68

Critical value: tโ‚€.โ‚€โ‚‚โ‚…,โ‚† = 2.447

|t| = 3.68 > 2.447 โ†’ Reject Hโ‚€. The simulation output is NOT consistent with the real system. The model needs revision.


2Explain the difference between AR(1) and EAR(1) models. How do you decide which to use?4 marks

AR(1) (Autoregressive): X_n = ฮผ + ฯ†(X_{n-1} โˆ’ ฮผ) + ฮต_n. Best for continuous, normally distributed data.

EAR(1) (Exponential Autoregressive): Uses a Bernoulli mixture. Best for count data, skewed, non-negative data.

Decision: Plot a histogram. If bell-shaped/symmetric โ†’ AR(1). If skewed right/count-like โ†’ EAR(1).


3Describe the Chi-Square goodness-of-fit test and state the formula. How are degrees of freedom determined?5 marks

The Chi-Square test compares observed frequencies (O) with expected frequencies (E) under a hypothesised distribution.

ฯ‡ยฒ = ฮฃ [(Oแตข โˆ’ Eแตข)ยฒ / Eแตข]

Degrees of freedom = k โˆ’ 1 โˆ’ p, where k = number of categories (after merging cells with E < 5) and p = number of parameters estimated from data.

Reject Hโ‚€ if ฯ‡ยฒ > ฯ‡ยฒ_{ฮฑ, df} from the chi-square table.

๐Ÿ’ป Topic: R Programming Questions
1Write an R function that simulates rolling a die until a 6 appears and returns the number of rolls. Run it 10,000 times and compute the average.5 marks
simulate_die <- function() {
  rolls <- 0
  while (TRUE) {
    rolls <- rolls + 1
    if (sample(1:6, 1) == 6) return(rolls)
  }
}

# Run and average
mean(replicate(10000, simulate_die()))  # Should be โ‰ˆ 6

The expected value is 6 (geometric distribution with p = 1/6 has mean 1/p = 6).


2Write R code to generate 10,000 values from a Gamma(shape=3, scale=1) distribution. Plot a histogram and compute the sample mean and variance.5 marks
x <- rgamma(10000, shape=3, scale=1)
hist(x, breaks=50, probability=TRUE, main="Gamma(3,1)")
mean(x)  # Should be โ‰ˆ 3 (shape ร— scale)
var(x)   # Should be โ‰ˆ 3 (shape ร— scaleยฒ)

3Write R code to compute P(X = 25000) where X ~ Binomial(n=50000, p=0.5) using: (a) the direct method and (b) the logarithmic method.4 marks
# Method (a): Direct
dbinom(25000, size=50000, prob=0.5)

# Method (b): Logarithmic (avoids overflow)
n <- 50000; k <- 25000; p <- 0.5
log_prob <- sum(log(1:n)) - sum(log(1:k)) -
            sum(log(1:(n-k))) + k*log(p) + (n-k)*log(1-p)
exp(log_prob)