Table of Contents Chapter 15 Computer Simulation Basic
Table of Contents Chapter 15 (Computer Simulation: Basic Concepts) The Essence of Computer Simulation (Section 15. 1) Example 1: A Coin-Flipping Game (Section 15. 1) Example 2: Heavy Duty Company (Section 15. 1) Generating Observations from a Probability Distribution (Section 15. 1) A Case Study: Herr Cutter’s Barber Shop (Section 15. 2) Analysis of the Case Study (Section 15. 3) Some Common Types of Applications (Section 15. 4) Outline of a Major Computer Simulation Study (Section 15. 5) 15. 2 15. 3– 15. 7 15. 8– 15. 14 15. 15– 15. 22 15. 23– 15. 29 15. 30– 15. 37 15. 38– 15. 39 15. 40– 15. 42 Introduction to Simulation (UW Lecture) 15. 43– 15. 58 These slides are based upon a lecture from the MBA core course in Management Science at the University of Washington (as taught by one of the authors). Mc. Graw-Hill/Irwin 1 © The Mc. Graw-Hill Companies, Inc. , 2003
The Essence of Computer Simulation • A stochastic system is a system that evolves over time according to one or more probability distributions. • Computer simulation imitates the operation of such a system by using the corresponding probability distributions to randomly generate the various events that occur in the system. • Rather than literally operating a physical system, the computer just records the occurrences of the simulated events and the resulting performance of the system. • Computer simulation is typically used when the stochastic system ivolved is too complex to be analyzed satisfactorily by analytical models. Mc. Graw-Hill/Irwin 2 © The Mc. Graw-Hill Companies, Inc. , 2003
Example 1: A Coin-Flipping Game • Rules of the game: 1. Each play of the game involves repeatedly flipping an unbiased coin until the difference between the number of heads and tails tossed is three. 2. To play the game, you are required to pay $1 for each flip of the coin. You are not allowed to quit during the play of a game. 3. You receive $8 at the end of each play of the game. • Examples: HHH 3 flips You win $5 THTTT 5 flips You win $3 THHTHTHTTTT 11 flips You lose $3 Mc. Graw-Hill/Irwin 3 © The Mc. Graw-Hill Companies, Inc. , 2003
Computer Simulation of Coin-Flipping Game • A computer cannot flip coins. Instead it generates a sequence of random numbers. • A number is a random number between 0 and 1 if it has been generated in such a way that every possible number within the interval has an equal chance of occurring. • An easy way to generate random numbers is to use the RAND() function in Excel. • To simulate the flip of a coin, let half the possible random numbers correspond to heads and the other half to tails. – 0. 0000 to 0. 4999 correspond to heads. – 0. 5000 to 0. 9999 correspond to tails. Mc. Graw-Hill/Irwin 4 © The Mc. Graw-Hill Companies, Inc. , 2003
Computer Simulation of Coin-Flipping Game Mc. Graw-Hill/Irwin 5 © The Mc. Graw-Hill Companies, Inc. , 2003
Data Table for 14 Replications of Coin-Flipping Game Mc. Graw-Hill/Irwin 6 © The Mc. Graw-Hill Companies, Inc. , 2003
Data Table for 1000 Replications of Coin-Flipping Game Mc. Graw-Hill/Irwin 7 © The Mc. Graw-Hill Companies, Inc. , 2003
Corrective Maintenance versus Preventive Maintenance • The Heavy Duty Company has just purchased a large machine for a new production process. • The machine is powered by a motor that occasionally breaks down and requires a major overhaul. Therefore, a second standby motor is kept, and the two motors are rotated in use. • The breakdowns always occur on the fourth, fifth, or sixth day that the motor is in use. Fortunately, it takes fewer than three days to overhaul a motor, so a replacement is always ready. Cost of a Replacement Cycle that Begins with a Breakdown Replace a Motor $2, 000 Lost production during replacement 5, 000 Overhaul a motor 4, 000 Total $11, 000 Mc. Graw-Hill/Irwin 8 © The Mc. Graw-Hill Companies, Inc. , 2003
Probability Distribution of Breakdowns Day 1, 2, 3 Probability of a Breakdown Corresponding Random Numbers 0 4 0. 25 0. 0000 to 0. 2499 5 0. 2500 to 0. 7499 6 0. 25 0. 7500 to 0. 9999 7 or more Mc. Graw-Hill/Irwin 9 © The Mc. Graw-Hill Companies, Inc. , 2003
Computer Simulation of Corrective Maintenance Mc. Graw-Hill/Irwin 10 © The Mc. Graw-Hill Companies, Inc. , 2003
Preventive Maintenance Options • Preventive maintenance would involve scheduling the motor to be removed (and replaced) for an overhaul at a certain time, even if a breakdown has not occurred. • The goal is to provide maintenance early enough to prevent a breakdown. • Scheduling the overhaul enables removing and replacing the motor at a convenient time when the machine is not in use, so no production is lost. Cost of a Replacement Cycle that Begins without a Breakdown Replace a motor on overtime $3, 000 Lost production during replacement 0 Overhaul a motor before a breakdown 3, 000 Total $6, 000 Mc. Graw-Hill/Irwin 11 © The Mc. Graw-Hill Companies, Inc. , 2003
Replace Motor After 3 Days • Cost of a replacement cycle is $6, 000. (Replacement always occurs without a breakdown). • Replacement cycle occurs every three days. • E(Cost per day) = ($6, 000) / (3 days) = $2, 000 per day. Mc. Graw-Hill/Irwin 12 © The Mc. Graw-Hill Companies, Inc. , 2003
Replace Motor After 4 Days Mc. Graw-Hill/Irwin 13 © The Mc. Graw-Hill Companies, Inc. , 2003
Replace Motor After 5 Days Mc. Graw-Hill/Irwin 14 © The Mc. Graw-Hill Companies, Inc. , 2003
Generating Random Observations from a Probability Distribution • The method for generating random observations from a continuous distribution is called the inverse transformation method. • Notation – r is the random number – F(x) is the cumulative distribution function (CDF) of the distribution from which we wish to generate a random observation. Thus, for each possible value of x, F(x) is the probability of being less than or equal to x. • The Inverse Transformation Method 1. Generate a random number r. 2. Find the value of x such that F(x) = r. This value of x is the desired random observation from the probability distribution. Mc. Graw-Hill/Irwin 15 © The Mc. Graw-Hill Companies, Inc. , 2003
Illustration of Inverse Transformation Method Mc. Graw-Hill/Irwin 16 © The Mc. Graw-Hill Companies, Inc. , 2003
Inverse Transformation Method for a Discrete Distribution Mc. Graw-Hill/Irwin 17 © The Mc. Graw-Hill Companies, Inc. , 2003
Herr Cutter’s Barber Shop • Herr Cutter is a German barber who runs a one-man barber shop. He opens his shop at 8: 00 AM each weekday morning. His customers arrive randomly at an average rate of two customers per hour. He requires an average of 20 minutes for each haircut. • As his business has increased, his customers now often wait awhile (sometimes over half-an-hour). His loyal customers are willing to wait, but new customers are much less likely to return if they have to wait. • An article in The Barber’s Journal states – In a well-run barber shop, loyal customers will tolerate an average wait of 20 minutes, while new customers will tolerate only a 10 minute average wait. (With longer waits, they typically take their business elsewhere in the future. ) Question: Should Herr Cutter hire a new associate to share the workload? Mc. Graw-Hill/Irwin 18 © The Mc. Graw-Hill Companies, Inc. , 2003
Probability Distributions • The time required to give a haircut varies between 15 and 25 minutes. His best estimate is that the times between 15 and 25 minutes are equally likely. – Estimated distribution of service times: The Uniform distribution over the interval from 15 to 25 minutes. – The CDF for this distribution is P(service time ≤ x) = F(x) = • 0 for x ≤ 15 • (x – 15)/10 for 15 ≤ x ≤ 25 • 1 for x ≥ 25 • The barber shop has random arrivals of customers, averaging two per hour. – Estimated distribution of interarrival times: An exponential distribution with a mean of 30 minutes. – The CDF for this distribution is P(interarrival time ≤ x) = F(x) = • 1–e–x/30 for x ≥ 0. Mc. Graw-Hill/Irwin 19 © The Mc. Graw-Hill Companies, Inc. , 2003
CDF of Service-Time Distribution (Uniform) Mc. Graw-Hill/Irwin 20 © The Mc. Graw-Hill Companies, Inc. , 2003
CDF of Interarrival-Time Distribution (Exponential) Mc. Graw-Hill/Irwin 21 © The Mc. Graw-Hill Companies, Inc. , 2003
Applying the Inverse Transformation Method for the Service Time (Uniform Distribution) F(x) = (x– 15)/10 = 0. 7270 when x = 22. 27 Mc. Graw-Hill/Irwin 22 © The Mc. Graw-Hill Companies, Inc. , 2003
Applying the Inverse Transformation Method for the Interarrival Time (Exponential Distribution) F(x) = 1–e–x/30 = 0. 8130 when e-x/30 = 0. 187 or –x/30 = ln 0. 187 = – 1. 6767 or x = 50. 30 Mc. Graw-Hill/Irwin 23 © The Mc. Graw-Hill Companies, Inc. , 2003
Building Blocks of a Simulation Model 1. A description of the components of the system, including how they are assumed to operate and interrelate. 2. A simulation clock. 3. A definition of the state of the system. 4. A method for randomly generating the (simulated) events that occur over time. 5. A method for changing the state of the system when an event occurs. 6. A procedure for advancing the time on the simulation clock. Mc. Graw-Hill/Irwin 24 © The Mc. Graw-Hill Companies, Inc. , 2003
Building Blocks for Herr Cutter’s Simulation Model 1. A description of the components of the system, including how they are assumed to operate and interrelate. • The components are the customers, the queue, and Herr Cutter as the server. 2. A simulation clock. • t = Amount of simulated time that has elapsed so far 3. A definition of the state of the system. • N(t) = Number of customers in the barber shop at time t. 4. A method for randomly generating the (simulated) events that occur over time. • The interarrival and service times are generated using the inverse transformation method. Mc. Graw-Hill/Irwin 25 © The Mc. Graw-Hill Companies, Inc. , 2003
Building Blocks for Herr Cutter’s Simulation Model 5. A method for changing the state of the system when an event occurs. • • Reset N(t) = N(t) + 1 if an arrival occurs at time t Reset N(t) = N(t) – 1 if a service completion occurs at time t 6. A procedure for advancing the time on the simulation clock. • The Next-Event Time-Advance Procedure a) Observe the current time t and randomly generated times of the next occurrence of each event type that can occur (service or arrival in Herr Cutter’s problem). Determine which event will occur next. b) Advance the time on the simulation clock to the time of this next event. c) Updated the system by determining its new state as a result of this event and by randomly generating the time until the next occurrence of any event type that can occur from this new state (if not previously generated). Also record desired information about the performance of the system. Then return to the first step. Mc. Graw-Hill/Irwin 26 © The Mc. Graw-Hill Companies, Inc. , 2003
A Computer Simulation of Herr Cutter’s Barber Shop Mc. Graw-Hill/Irwin 27 © The Mc. Graw-Hill Companies, Inc. , 2003
Evolution of Number of Customers Over First 100 Minutes Mc. Graw-Hill/Irwin 28 © The Mc. Graw-Hill Companies, Inc. , 2003
Simulating the Barber Shop with an Associate • The only difference occurs when the next-event time-advance procedure is determining which event occurs next. • Instead of just two possibilities, there are now three: 1. A departure because Herr Cutter completes a haircut. 2. A departure because the associate completes a haircut. 3. An arrival. Mc. Graw-Hill/Irwin 29 © The Mc. Graw-Hill Companies, Inc. , 2003
Analysis of the Case Study: Financial Factors • Revenue = $15 per haircut • Average tip = $2 per haircut • Cost of maintaining the shop = $50 per working day • Salary of an associate = $120 per working day • Commission for an associate = $5 per haircut given by the associate. • In addition to his salary and commission, the associate would keep his own tips. Otherwise, the revenue would go to Herr Cutter. • The shop is open from 8: 00 AM to 5: 00 PM, so it admits customers for nine hours. Mc. Graw-Hill/Irwin 30 © The Mc. Graw-Hill Companies, Inc. , 2003
Analysis of Continuing without an Associate • The current distribution of interarrival times has a mean of 30 minutes. Therefore, he averages 18 customers per working day. • After subtracting the cost of maintaining the shop, his average net income per working day is Net daily income = ($15 + $2) (18 customers) – $50 = $306 – $50 = $256 Mc. Graw-Hill/Irwin 31 © The Mc. Graw-Hill Companies, Inc. , 2003
Features of the Queueing Simulator 1. Can run computer simulations of various kinds of basic queueing systems. 2. Can have any number of servers up to a maximum of 25. 3. Can use any of the following probability distributions for either interarrival times or service times: a) Constant time (also called the degenerate distribution). b) Exponential distribution. c) Translated exponential distribution (the sum of a constant time and a time from an exponential distribution). d) Uniform distribution. e) Erlang distribution. 4. Provides estimates of various key measures of performance: L Lq W Wq Pn = Expected number of customers in the system, including those being served. = Expected number of customers in the queue. = Expected waiting time in the system (includes service time) for a customer. = Expected waiting time in the queue (excluding service time) for a customer. = Probability of exactly n customers in the system (for n = 1, 2, … , 10). Mc. Graw-Hill/Irwin 32 © The Mc. Graw-Hill Companies, Inc. , 2003
Queueing Simulator for Herr Cutter (Without Associate) Mc. Graw-Hill/Irwin 33 © The Mc. Graw-Hill Companies, Inc. , 2003
Testing the Validity of the Simulation Model Mc. Graw-Hill/Irwin 34 © The Mc. Graw-Hill Companies, Inc. , 2003
Analysis of the Option of Adding an Associate • Adding an associate would – reduce the average waiting time before a haircut begins to less than 10 minutes. – gradually attract new business until this average waiting time reaches 10 minutes. Queueing Simulator Results: Mean of Interarrival Times Point Estimate of Wq 95 Percent Confidence Interval for Wq 20 minutes 3. 33 minutes 3. 05 to 3. 61 minutes 15 minutes 8. 10 minutes 6. 98 to 9. 22 minutes 14 minutes 10. 80 minutes 9. 51 to 12. 08 minutes 14. 2 minutes 9. 83 minutes 8. 83 to 10. 84 minutes 14. 3 minutes 9. 91 minutes 8. 76 to 11. 05 minutes Mc. Graw-Hill/Irwin 35 © The Mc. Graw-Hill Companies, Inc. , 2003
Queueing Simulator for Herr Cutter (With an Associate) Mc. Graw-Hill/Irwin 36 © The Mc. Graw-Hill Companies, Inc. , 2003
Analysis of the Option of Adding an Associate • Herr Cutter believes 14. 3 minutes provides an adequate and conservative estimate of the mean interarrival rate with an associate. • This corresponds to a mean arrival rate of 37. 8 customers per day. • Net daily income = 37. 8 ($15) (shop revenue) + 18. 9 ($2) (his tips) – $50 (shop maintenance) – $120 (associate’s salary) – $18. 9 ($5) (associate’s commission) Total $340. 30 • This compares to Herr Cutter’s current net daily income of $256. Mc. Graw-Hill/Irwin 37 © The Mc. Graw-Hill Companies, Inc. , 2003
Some Common Types of Applications • Design and Operation of Queueing Systems – New York City’s arrest-to arraignment system (1993) – AT&T’s system to design call centers (1993) – Taco Bell (1998) • Managing Inventory Systems – IBM simulating various redesigns of their supply chain (1996) • Estimating the Probability of Completing a Project by the Deadline – PERT/CPM (Chapter 8) provides only a rough estimate. – Computer simulation is becoming an increasingly common approach to better estimate this probability. • Design and Operation of Manufacturing Systems – How many machines of each type should be provided? – How many materials-handling units of each time should be provided? – Considering their due dates, what rule should be used to choose the order in which jobs are processed? – What are realistic due dates for jobs? – What will be the bottleneck operation in a new production process? – What will be throughput of a new production process? Mc. Graw-Hill/Irwin 38 © The Mc. Graw-Hill Companies, Inc. , 2003
Some Common Types of Applications • Design and Operation of Distribution Systems – Uncertainties: How long will shipments take? What will customers’ demands be? – Example: Reynolds Metals Company (1991) • Financial Risk Analysis – Uncertain future cash flows of proposed capital investments are simulated to provide a probability distribution for the return on the investment. • Health Care Applications – – – – • Use of hospital resources when treating patients with heart disease. Health expenditures under alternative insurance plans. Cost and effectiveness of screening for the early detection of disease. Use of complex surgical services at a medical center. Timing and location of calls for ambulance services. Matching of donated kidneys with transplant recipients. Operation of an emergency room. Applications to Other Service Industries – US Postal Service (1992) All references available for download at www. mhhe. com/hillier 2 e/articles Mc. Graw-Hill/Irwin 39 © The Mc. Graw-Hill Companies, Inc. , 2003
Outline of a Major Computer Simulation Study • Step 1: Formulate the Problem and Plan the Study – – – • What is the problem that management wants studied? What are the overall objectives for the study? What specific issues should be addressed? What kinds of alternative system configurations should be considered? What measures of performance of the system are of interest to management? What are the time constraints for performing the study? Step 2: Collect the Data and Formulate the Simulation Model – The probability distributions of the relevant quantities are needed. – Generally it will only be possible to estimate these distributions. – A simulation model often is formulated in terms of a flow diagram. • Step 3: Check the Accuracy of the Simulation Model – Walk through the conceptual model before an audience of all the key people. Mc. Graw-Hill/Irwin 40 © The Mc. Graw-Hill Companies, Inc. , 2003
Outline of a Major Computer Simulation Study • Step 4: Select the Software and Construct a Computer Program – Classes of software • Spreadsheet software (e. g. , Excel, Crystal Ball) • A general purpose programming language (e. g. , C, FORTRAN, Pascal, etc. ) • A general purpose simulation language (e. g. , GPSS, SIMSCRIPT, SLAM, SIMAN) • Applications-oriented simulators • Step 5: Test the Validity of the Simulation Model – If the real system is currently in operation, performance data should be compared with the corresponding output generated by the simulation model. – Conduct a field test to collect data to compare to the simulation model. – Have knowledgeable personnel check how the simulation results change as the configuration of the simulated system is changed. – Watch animations of simulation runs. Mc. Graw-Hill/Irwin 41 © The Mc. Graw-Hill Companies, Inc. , 2003
Outline of a Major Computer Simulation Study • Step 6: Plan the Simulations to Be Performed – Determine length of simulation runs. – Keep in mind that the simulation runs do no produce exact values. Each simulation run can be viewed as a statistical experiment that is generating statistical observations of the performance of the system. • Step 7: Conduct the Simulation Runs and Analyze the Results – Obtain point estimates and confidence intervals to indicate the range of likely values for the measures. • Step 8: Present Recommendations to Management Mc. Graw-Hill/Irwin 42 © The Mc. Graw-Hill Companies, Inc. , 2003
Analytical Models • Advantages: – Gives the “optimal” solution. • Disadvantages: – Model must fit a solvable form. – Gives results for only one (LP) or a few (Decision Analysis) states of nature. Mc. Graw-Hill/Irwin 43 © The Mc. Graw-Hill Companies, Inc. , 2003
Simulation Models • Advantages: – Can include factors that cause problems in analytical models. – Gives a distribution of results for many possible states of nature. • Disadvantages: – Doesn’t give an “optimal solution”. – Good at evaluating, but not finding, solutions. Mc. Graw-Hill/Irwin 44 © The Mc. Graw-Hill Companies, Inc. , 2003
Two Types of Simulation • System Simulation—Simulate a sequence of events over time, to determine how a system performs. – Examples: • Queueing systems • Manufacturing systems • Inventory management • Monte Carlo Simulation—Sampling experiment for estimating the distribution of an outcome that depends on several probabilistic inputs. – Examples: • Profitability of a business venture • Duration of a project • Retirement planning Mc. Graw-Hill/Irwin 45 © The Mc. Graw-Hill Companies, Inc. , 2003
Generating Random Variables • Methods – Mechanical device – Random number table – Random number generator (e. g. , RAND() in Excel) • Suppose u is a random number between 0 and 1 (e. g. = RAND() ). • How do we generate the following random variables? – – Continuous uniform on [0, 20] Continuous uniform on [15, 25] Roll of a die (i. e. , integer uniform on [1, 6]) Discrete: Value Probability 3 0. 2 4 0. 3 5 0. 4 6 0. 1 Mc. Graw-Hill/Irwin 46 © The Mc. Graw-Hill Companies, Inc. , 2003
The Cumulative Distribution Function Suppose W is a random variable. Then, its CDF is F(x) = Prob(W ≤ x) Mc. Graw-Hill/Irwin 47 © The Mc. Graw-Hill Companies, Inc. , 2003
To Generate Any Continuous Random Variable 1. Generate u ~ Uniform [ 0, 1 ] 2. Find x for which F(x) = u. 3. Then x is the generated random variable. Mc. Graw-Hill/Irwin 48 © The Mc. Graw-Hill Companies, Inc. , 2003
Generating Random Variables in Excel • Uniform[a, b] = a + (b – a) * RAND() • Discrete Uniform[a, b] = INT(a + (b - a + 1)*RAND() ) • Normal(m, s) = NORMINV(RAND(), m, s) • Exponential (with rate = l) =(– 1/l) * LN( RAND() ) Mc. Graw-Hill/Irwin 49 © The Mc. Graw-Hill Companies, Inc. , 2003
Freddie the Newsboy • Freddie runs a newsstand in a prominent downtown location of a major city. • Freddie sells a variety of newspapers and magazines. The most expensive of the newspapers is the Financial Journal. • Cost data for the Financial Journal: – Freddie pays $1. 50 per copy delivered. – Freddie charges $2. 50 per copy. – Freddie’s refund is $0. 50 per unsold copy. • Sales data for the Financial Journal: – Freddie sells anywhere between 40 and 70 copies a day. – The frequency of the numbers between 40 and 70 are roughly equal. Mc. Graw-Hill/Irwin 50 © The Mc. Graw-Hill Companies, Inc. , 2003
Spreadsheet Simulation Model Mc. Graw-Hill/Irwin 51 © The Mc. Graw-Hill Companies, Inc. , 2003
A Queueing Problem • ABC Car Wash is an automated car wash. • Each customer deposits four quarters in a coin slot, drives the car into the autowasher, and waits while the car is automatically washed. • Cars arrive randomly at an average rate of 20 cars per hour. • The service time is exactly 2 minutes. Mc. Graw-Hill/Irwin 52 © The Mc. Graw-Hill Companies, Inc. , 2003
A Queueing Problem (The First Three Arrivals) Mc. Graw-Hill/Irwin 53 © The Mc. Graw-Hill Companies, Inc. , 2003
A Queueing Problem (The First Three Arrivals) Customer Arrival Time Until Next Arrival Time of Arrival Time Service Begins #1 Service Time 2 2 2 #2 1 3 #3 4 7 Mc. Graw-Hill/Irwin Time Service Ends Waiting Time 2 2 + 2 = 4 2 – 2 = 0 Max(3, 4) = 4 2 4 + 2 = 6 4 – 3 = 1 Max(6, 7) = 7 2 7 + 2 = 9 7 – 7 = 0 54 © The Mc. Graw-Hill Companies, Inc. , 2003
Queueing Problem Simulation Model Mc. Graw-Hill/Irwin 55 © The Mc. Graw-Hill Companies, Inc. , 2003
A Game of Craps • A popular game in gambling casinos is the game of craps. • In its most basic form, the game is played as follows: – – A player rolls two dice and calculates the sum. If the sum is 7 or 11, the play wins right away. If the sum is 2, 3, or 12, the player loses right away. If the sum is any other number (4, 5, 6, 8, 9, or 10), the number becomes the player’s “point”. • In this case, the dice are thrown repeatedly until the sum is either: – the “point” (in which case the player wins), or – 7 (in which case the player loses). Mc. Graw-Hill/Irwin 56 © The Mc. Graw-Hill Companies, Inc. , 2003
Spreadsheet Simulation Model Mc. Graw-Hill/Irwin 57 © The Mc. Graw-Hill Companies, Inc. , 2003
Using a Data Table to Perform Many Simulation Trials 1. In the first row of the table (row 12), put equations referring to the output cells of the simulation spreadsheet (=E 4 in M 12, =E 5 in N 12). 2. In the first column of the table, label each simulation trial (1 to 100). 3. Select the entire table (L 12 through N 112). 4. Choose Table from the Data menu. 5. For the Column input cell, select any empty cell (e. g. , K 7). Mc. Graw-Hill/Irwin 58 © The Mc. Graw-Hill Companies, Inc. , 2003
- Slides: 58