Monte Carlo simulation
Monte Carlo simulation: cumulative distributions, random-number allocation, hand simulation of demand and a single-server queue, accuracy and limitations.
Drafted with Aria, reviewed by the AiCanCode.org team. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Many shop-floor systems are too messy for a neat formula: arrivals that are not Poisson, machines that break down, demand and lead time that are both random, several interacting queues. Monte Carlo simulation imitates such a system on paper or a computer with random numbers, so you can test a policy — an extra fitter, a higher reorder point, a second loading bay — before spending money on it. It is the general tool when analytical OR models run out.
Key ideas
What simulation is. A model of the system's logic is run step by step, with each uncertain quantity (demand, inter-arrival time, service time, time to failure) drawn at random from its probability distribution. Averaging the results of many runs estimates the performance measures. Simulation does not optimise by itself; it evaluates the alternatives you feed it.
Monte Carlo procedure.
- Define the problem, the performance measure and the policies to compare.
- Get the probability distribution of each random variable (from past records or a fitted distribution).
- Form the cumulative probability distribution.
- Assign random-number ranges in proportion to the probabilities: with two-digit numbers 00–99, a probability of 0.20 gets 20 numbers. The ranges follow the cumulative probabilities.
- Draw random numbers (from a table or a generator) and read off the simulated values.
- Run the system logic for the required number of trials and record the results.
- Compute averages and compare alternatives; increase the number of trials until the estimates settle.
Accuracy. A simulation result is a statistical estimate. Its standard error falls as 1/√n, so four times as many trials only halves the error. Short runs (like the ten-trial examples done by hand) show the method; real decisions need hundreds or thousands of trials, a warm-up period for queues that start empty, and several independent replications.
Continuous distributions. For a continuous variable, the inverse-transform method sets x = F⁻¹(r) with r uniform on (0, 1). For an exponential distribution with mean 1/λ: x = −(1/λ)·ln(1 − r), equivalently −(1/λ)·ln r.
Advantages and limits. Simulation handles any distribution, interactions and time-varying behaviour; it is easy to explain to managers. But it gives estimates, not exact optima, depends on correct input distributions ("garbage in, garbage out"), and can need many runs. Use an analytical model (e.g. M/M/1) when its assumptions hold — it is exact and instant — and also to validate a simulation.
Formulas
- Cumulative probability:
F(xₖ) = p₁ + p₂ + … + pₖ - Random-number range for value xₖ (two digits): from
100·F(xₖ₋₁)to100·F(xₖ) − 1 - Estimated mean:
x̄ = (1/n) · Σ xᵢ - Expected value for comparison:
E(X) = Σ xₖ · pₖ - Standard error of the estimate:
s / √n - Exponential variate:
x = −(1/λ) · ln(1 − r) - Monte Carlo estimate of π:
π ≈ 4 · (points inside quarter or inscribed circle) / (total points)
Symbols: xₖ = possible value of the random variable (units/day, min); pₖ = its probability; F = cumulative probability; r = uniform random number in (0, 1); n = number of trials; s = sample standard deviation of the simulated results; λ = rate of the exponential distribution (per min).
Worked examples
Example 1 (demand simulation). Daily demand for a spare part is 0, 1, 2, 3 or 4 units with probabilities 0.10, 0.20, 0.40, 0.20, 0.10. Simulate 10 days with random numbers 48, 78, 19, 51, 56, 77, 15, 14, 68, 09.
- Cumulative probabilities: 0.10, 0.30, 0.70, 0.90, 1.00.
- Random-number ranges: 0 → 00–09; 1 → 10–29; 2 → 30–69; 3 → 70–89; 4 → 90–99.
- Simulated demands: 48 → 2, 78 → 3, 19 → 1, 51 → 2, 56 → 2, 77 → 3, 15 → 1, 14 → 1, 68 → 2, 09 → 0.
- Total = 17 units in 10 days, so the simulated mean = 1.7 units/day.
- Theoretical mean = 0(0.10) + 1(0.20) + 2(0.40) + 3(0.20) + 4(0.10) = 2.0 units/day. The gap is sampling error from only 10 trials.
Example 2 (GATE-type single-server queue). Inter-arrival times 1, 2, 3, 4 min have probabilities 0.2, 0.3, 0.3, 0.2 (ranges 00–19, 20–49, 50–79, 80–99). Service times 1, 2, 3 min have probabilities 0.3, 0.5, 0.2 (ranges 00–29, 30–79, 80–99). Random numbers for inter-arrivals of customers 1–6: 64, 18, 37, 92, 05, 51; for services: 82, 45, 27, 71, 93, 10. The clock starts at 0 with the server free. Find the average wait in queue and server idle time.
- Inter-arrival times: 3, 1, 2, 4, 1, 3 min → arrival clock times 3, 4, 6, 10, 11, 14.
- Service times: 3, 2, 1, 2, 3, 1 min.
- C1: arrives 3, starts 3, waits 0, ends 6. C2: arrives 4, starts 6, waits 2, ends 8. C3: arrives 6, starts 8, waits 2, ends 9.
- C4: arrives 10, starts 10, waits 0, ends 12 (server idle 9–10). C5: arrives 11, starts 12, waits 1, ends 15. C6: arrives 14, starts 15, waits 1, ends 16.
- Total wait = 0 + 2 + 2 + 0 + 1 + 1 = 6 min → average wait = 1.0 min per customer.
- Server idle = 3 (0–3) + 1 (9–10) = 4 min out of 16 min, utilisation = 12/16 = 75 %.
Common mistakes
- Making random-number ranges overlap or leave gaps (for example 00–10 and 10–29); each range must have exactly 100·p numbers.
- Using individual probabilities instead of cumulative ones to set the ranges.
- Starting a customer's service at the arrival time even though the server is still busy.
- Drawing conclusions from a handful of trials as if they were exact.
- Reusing the same random-number stream for two different variables, which correlates them.
- Comparing two policies with different random numbers when the aim is a fair comparison (use common random numbers).
For GATE PI
- Assign random-number intervals from a probability table and read simulated values (NAT).
- Short hand simulations of demand, inventory or a single-server queue: average demand, waiting time, idle time.
- Concept MCQs on the purpose, accuracy and limitations of simulation, and the π estimate.
- Practise building the arrival–start–end–wait table neatly; most errors come from the clock column.
Quick check
- Probabilities 0.25, 0.45, 0.30. Write the two-digit random-number ranges.
- 400 random points in a unit square give 316 inside the quarter circle. Estimate π.
- To halve the standard error of a simulation estimate, by what factor must the trials increase?
- Can Monte Carlo simulation find the optimal policy by itself?
Answers: 1. 00–24, 25–69, 70–99. 2. 4 × 316/400 = 3.16. 3. Four times. 4. No — it evaluates the policies you test.
See it move
All Production animationsAdjust the number of random points to see how the estimate of π converges. Observe how more points lead to a more accurate estimation.
Equations used
- E(X) = Σ [x * P(x)] — Expected value of the random variable X
- π ≈ 4 * (Number of points inside circle / Total number of points)
Interview questions
All Operations Research interview questionsTry answering each one aloud before you open it.
1.What is Monte Carlo simulation in the context of operations research?Concept
Monte Carlo simulation is a computational technique used to model the probability of different outcomes in a process that cannot easily be predicted due to the intervention of random variables. It uses random sampling and statistical modeling to estimate mathematical functions and mimic the operations of complex systems.
2.Explain how Monte Carlo simulation can be applied in production and industrial engineering.Concept
In production and industrial engineering, Monte Carlo simulation can be used to model and analyze complex systems such as supply chain logistics, production scheduling, and inventory management. By simulating different scenarios and outcomes, engineers can assess risks, optimize processes, and make informed decisions under uncertainty.
3.What are the key components required to perform a Monte Carlo simulation?Concept
The key components of a Monte Carlo simulation include a model of the system or process being analyzed, a set of input variables with defined probability distributions, a method for generating random samples, and a computational algorithm to simulate the process and analyze the results.
4.Why is random sampling important in Monte Carlo simulations?Application
Random sampling is crucial in Monte Carlo simulations because it allows for the exploration of a wide range of possible outcomes and the estimation of probabilities for different scenarios. This randomness helps in capturing the inherent variability and uncertainty in complex systems, leading to more robust and reliable results.
5.What happens if the number of iterations in a Monte Carlo simulation is too low?Application
If the number of iterations in a Monte Carlo simulation is too low, the results may not accurately represent the true variability and uncertainty of the system being modeled. This can lead to biased estimates and unreliable conclusions, as the simulation may not capture the full range of possible outcomes.
6.How can Monte Carlo simulation be used to optimize inventory management?Application
Monte Carlo simulation can be used in inventory management to model demand variability, lead times, and other uncertainties. By simulating different inventory policies and scenarios, managers can identify optimal reorder points and safety stock levels that minimize costs while maintaining service levels.
7.Describe a scenario where Monte Carlo simulation might be preferred over deterministic models.Application
Monte Carlo simulation is preferred over deterministic models when dealing with systems that have significant uncertainty and variability, such as financial forecasting, risk assessment, or complex manufacturing processes. In these cases, deterministic models may oversimplify the system, while Monte Carlo simulation can provide a more comprehensive analysis by accounting for randomness.
8.A project has three possible outcomes: a profit of ₹1,00,000 with probability 0.3, a profit of ₹50,000 with probability 0.5 and a loss of ₹20,000 with probability 0.2. What is its expected value, and what would a Monte Carlo run of the project give?Numerical
EV = 0.3 × 1,00,000 + 0.5 × 50,000 + 0.2 × (−20,000) = 30,000 + 25,000 − 4000 = ₹51,000. A Monte Carlo run would allot random numbers 00–29, 30–79 and 80–99 to the three outcomes and average the simulated results; with enough trials the average converges to ₹51,000, while the spread of the trials also shows the 20 % chance of a loss.
9.A factory uses Monte Carlo simulation to estimate the probability of machine failure. If the simulation runs 10,000 iterations and observes 500 failures, what is the estimated probability of failure?Numerical
The estimated probability of failure is calculated by dividing the number of observed failures by the total number of iterations: Probability of failure = 500 / 10,000 = 0.05 or 5%.
10.What are some limitations of Monte Carlo simulation?Concept
Some limitations of Monte Carlo simulation include the need for significant computational resources, the potential for inaccurate results if the input distributions are not well-defined, and the challenge of interpreting results in complex systems. Additionally, the quality of the simulation is highly dependent on the accuracy of the model and the assumptions made.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?