Computer Simulation Blackboard

advertisement
Simulation
Chapter 16 of Quantitative
Methods for Business, by
Anderson, Sweeney and
Williams Read sections
16.1, 16.2, 16.3, 16.4, and
Appendix 16.1
COMPUTER SIMULATION
• What is it?
• Creating a computer model of a system
• Subjecting the model to various scenarios
• Statistically analyzing the results in order to
predict how the real system will behave
EXAMPLE #1--coin tossing
• A gambling game where a coin is tossed
repeatedly until the number of heads and
number of tails differ by 3.
• You pay $100 for each toss. You collect
$800 at the end of each game.
• Do you want to play?
EXAMPLE #1
• By hand simulation of the game:
• Heads
Tails
Payoff
EXAMPLE #1
• Suppose we simulate 10 games and find
the number of tosses to be:
5,13,7,5,9,5,3,11,5, and 7.
• Avg. # of tosses / game = 7
• Do you want to play?
EXAMPLE #1
• To simulate this game on Excel, we need to get
Excel to generate “heads” and “tails” randomly.
• The RAND() function
=RAND()
• causes Excel to generate a (uniformly distributed)
random value between 0 and 1 in that cell.
EXAMPLE #1
• How could we randomly generate “Heads” or
“Tails”?
• The IF() function
=IF(logical condition,value if true,value if false)
• Using these tools, create a model which
will simulate the gambling game.
Homework Status
• At this point you should be able to complete the
following homework problems in Chapter 16:
– #1
Generating random values
• What about generating the weather on a given day if the
probability of “rainy” is .5, the probability of “cloudy” is .3,
and the probability of “clear” is .2?
• How could we use Excel to generate outcome from the
throw of a single die?
• How could we use Excel to generate the outcome from
the throw of a single die, if the die had “A”, “B”, “C”, “D”,
“E”, “F” on its faces?
Generating random values
• To generate a new random value, just
press F9.
• F9 actually “recalculates” all values on the
workbook.
• This is done automatically whenever you
change any cell in the workbook.
Building a Monte Carlo
Simulation Model
1. Identify the random values of interest, i.e.
the things you model will need to
randomly generate. (Outcome of flipping
a coin, time a customer requires to
complete a transaction, number of
machine failures on a given day, etc.)
Building a Monte Carlo
Simulation Model
2. Define a mapping for the desired random
values, in such a way that the
probabilities are observed.
• May map from “the numbers on [0,1)”, if
using Excel’s rand() function, or
• May map from “the X-digit integers” if using a
random number table or multisided die
Building a Monte Carlo
Simulation Model
3. Define the logic associated with the
system (and model).
Example #2-- Machine failures
• You are asked to recommend whether
your company should purchase a
maintenance agreement for the copy
machine.
• Maintenance agreement costs $1000 per year
and covers service call charges for all
unscheduled maintenance.
• Without agreement, unscheduled maintenance
calls cost $50 each.
Example #2-- Machine failures
• You find that the copy machine has
breakdowns in this manner:
• In any given day,
– the probability of one machine failure is .03,
– the probability of two failures is .01,
– and the probability of 3 or more failures is 0.
Example #2-- Machine failures
1. What are the RANDOM VALUES in this
situation?
# of failures on any given day
Example #2-- Machine failures
2. MAPPING: Since the probabilities have at most
2 significant digits, we might generate 2-digit
random numbers.
We might map them to the “number of failures
in a day” like this:
00-96map to
0 failures
97-97map to
1 failure
99
map to
2 failures
Example #2-- Machine failures
3. LOGIC (TO SIMULATE ONE YEAR OF OPERATION):
1.
2.
3.
4.
Start
Let DAY =1 (DAY will tell what day of the year it
is)
Generate and record # of failures for the day
(using mapping).
Is DAY = 365?


If no, then add one to DAY and go to step 3.
If yes, then stop and compute the total number of
failures.
Example #2-- Machine failures
• Once the model is built, we run it a
number of times, and perform statistical
analysis of the results in order to predict
how the real system will behave.
Example #2-- Machine failures
• To run the system, we generate random numbers (using
a computer or a table or whatever).
• For our first run, we might choose to generate 2-digit
random numbers from, a pair of 10-sided dice.
• Alternatively we could use, the numbers from some
section of a Random Number table like Table 16.2 (p.
720 of your text)
Example #2-- Machine failures
• We can keep track of our observations in a table
or chart.
• Day #
random #
# of failures
1
2
3
4
5
and so on...
Example #2-- Machine failures
• After 365 (simulated) days, we could count the
number of failures, and compute the cost of
service calls with and without maintenance
agreement.
• We could run the model a number of times and
then average the observations to reach a
conclusion. (In actuality, we’d probably build a
confidence interval for the mean # of failures per
year.)
Example #2-- Machine failures
• For example suppose the number of
failures per (simulated) year were:
– 24, 20, 19, 18, 19, 16, 14, 17, 14,17
– Estimated average number of failures per
year (from this simulation) = 17.8
Example #2-- Machine failures
• Cost of paying $50 per maintenance call
times average of 17.8 failures per year = $890
per year.
• Cost of maintenance contract = $1000. per
year.
• Conclusion: Don’t buy the maintenance
contract.
Example #2-- Machine failures
• Why didn’t each (simulated) year get the
same number of failures?
• What conclusion would we have reached if
we’d stopped after 2 (simulated years)?
• How many years should we simulate?
How many times to run a
simulation model?
• Make several (N0) preliminary runs of the
model, recording the value of the quantity
you wish to predict, and then computing
the sample standard deviation (s).
• The total estimated number of runs
required to get a (1- α) confidence interval
of width ≤ W is given by:
• N ≥ (t2 * s2) / (W/2)2
• Where t is the t-statistic for N0-1 degrees
of freedom and α/2 , where α=level of
significance
Homework
• At this point you should be able to complete the
following homework problems in Chapter 16:
–
–
–
–
#3
#6
#8
#13
Random Number Options in Excel
• VLOOKUP to generate samples from a
discrete distribution
– To generate samples from a discrete
distribution, we store the description of the
distribution in 2 columns:
• The first holds the cumulative probability
distribution. (offset by one row and starting with
zero)
• The second holds the values that the random
variable can take
Random Number Options in Excel
• In the cells which are to hold the randomly
generated values, we specify
=VLOOKUP(RAND(), area where table describing distribution is stored, 2)
• The first argument is a randomly generated value
between 0 and 1
• The third argument is the column number (in the
table) where the values are stored
EXAMPLE #3--Inventory
• Consider an inventory system which
uses a reorder quantity model.
• Suppose the assumptions of EOQ,
EPLS, Shortages, or Quantity
Discounts models are not satisfied.
Specifically suppose demand is not
“known and constant”.
• How to determine a good lot size, Q?
EXAMPLE #3--Inventory
• Items cost $10 each and annual holding rate is
45%. Fixed cost to place an order is $15.
Weekly demand is distributed in this way:
Weekly Demand
9
10
11
12
13
Probability
.1
.2
.4
.2
.1
• The company is considering using lot sizes of 50,
75, and 100.
• Use simulation to determine which lot size tends
to give the lowest annual costs.
Homework
• At this point you should be able to complete the
following homework problems in Chapter 16:
– #15
Random Number Options in Excel
– How to generate samples from a Normal
distribution with mean μ and standard
deviation σ?
=NORMINV(R, μ, σ)
– How to generate samples from a
Uniform distribution on [a,b)
=a+(b-a)*R
where R is a random number on [0,1)
EXAMPLE #4--Inventory
• Items cost $10 each and annual holding
rate is 45%. Fixed cost to place an order
is $15. Weekly demand is normally
distributed with mean of 22 units and a
standard deviation of 5 units.
• The company is considering using lot sizes
of 50, 75, and 100.
• Use simulation to determine which lot size
tends to give the lowest annual costs.
EXAMPLE #4--Inventory
• Items cost $10 each and annual holding
rate is 45%. Fixed cost to place an order
is $15. Weekly demand is uniformly
distributed between 15 and 20 units.
• The company is considering using lot sizes
of 50, 75, and 100.
• Use simulation to determine which lot size
tends to give the lowest annual costs.
Homework
• At this point you should be able to complete the
following homework problems in Chapter 16:
– #17
– #21
– Dates assignment (on Blackboard)
Waiting Line Models
• Up until now, the examples we have considered could be
considered “static” models, in that they have involved
independent trials
– In the Machine Failure problem, the number of failures on one day did
not affect the number of failures on any other day.
– In the Inventory examples, the demand in one week did not affect the
demand in another week.
• How can we create a model of a system in which that’s not
the case?
– That is, what if the state of the system changes as a result of one
event, so that the state of the system is different when the next event
occurs?
Waiting Line Models
•
•
•
•
Consider a customer service system with one server
Customers arrive with interarrival times distributed like this:
Interarrival time
Probability
.5 minutes
10%
1 minute
20%
1.5 minutes
40%
2 minutes
20%
2.5 minutes
10%
Service times are distributed normally with mean=1.5 minutes, and
standard deviation = .5 minutes
Create a simulation model which simulates 1000 customer arrivals and
computes
–
–
–
Average wait time
# of customers who must wait
% of customers who must wait
Waiting Line Models
• Challenge:
– Modify your model for 2 servers
Download