chapter 1
DESCRIPTION
ıgoıgoıTRANSCRIPT
INDR 344 Modeling and Simulation
Department of Industrial EngineeringKoç University
SPRING 2015Chapter 1
Basic Simulation ModelingLerzan Ormeci
ENG 207, Ext: [email protected]
2
Syllabus What is simulation? Simulation examples Why simulation in IE? The nature of simulation Systems, models and simulation
Plan of the day
INDR 344 Modeling and Simulation
Teaching assistants (All the info TBA): Faruk Akın, Can Oz, Ozge Soyogul, Mirehsan Hesam Sadatizamanabad
Textbook: A.M. Law, Simulation Modeling and Analysis, 5th Edition, McGraw-Hill, 2007
Lab sessions: TUB5 in ENGB19, WEB5, FRB2 in SOS180
Course webpage/F-drive: includes the lecture notes, the lab and case descriptions, problems and data, homework problems (http://courses.ku.edu.tr/indr344)
Lecture slides: Available on the network drive of the course COURSES/SHARE/INDR 344. In addition, there are some resources available to students at Web site of the previous version of the textbook: http://www.mhhe.com/engcs/industrial/lawkelton/.
Labs: Labs constitute an essential part of the course. You will learn the simulation programming and the simulation software, which you will use in your projects.
Class activities: Class exercises will be held at the end of the classes. Class participation is another essential part of the course.
Lectures, labs and class activities
Lab sessions are scheduled primarily to learn ARENA, and may also discuss some of the homework and review exercises.
There will be some homework assignments related to certain lab sessions that should be completed after the lab session.
Every week a lab session will be held. The description of the lab will be announced in the
week before the lab. Students are expected to think/work on the lab assignments before the lab.
Students will work on the assignments either individually or in groups of two.
The first set of lab sessions will start next week.
Labs
The active involvement of students in discussing statistical tools and inferences with good questions and plausible answers.
NOT mere attendance NOR asking insensible questions.
The behavior in class will also be a part of your grade.
Class participation
Each group will consist of at most two students. Problems on the recent material covered in
class or on the material covered by the recent homework assignments will be asked.
Each group of two will work on the problems together, and turn in one written assignment.
In-Class Group Assignments
As a requirement, the students will complete a simulation project in groups of preferably four that will be formed in the first two weeks.
The groups will identify a complex system
and analyze it through simulation by using ARENA. They will report their analysis and findings by submitting a written report and making a presentation.
Project
9
Project deadlines
Milestone Deadline NotesForming of groups Feb 20, 2015 By e-mail to [email protected] definition March 09, 2015 One paragraph definition to be sent
by e-mail to your TA.Progress meeting Week of
March 23-27, 2015 Meet with your TA about the progressProgress report 1 April 13, 2015 One page report about the progressProgress report 2 April 27, 2015 Report describing data analysis and
process modelingFinal presentation May 11-15, 2015Final report May 20, 2015
Exams: In-Class and Lab ExamsThe examinations will be closed-book and closed-notes; but the students will either be allowed to bring an A4 size formula sheet with them, or computational formulas will be provided. Mobile phones and programmable calculators are not permitted. The lab exam will take place in a computer lab and will comprise a modeling exercise to be solved using software.◦ Midterm: 25%, Final: 35%
Lab attendance and assignments: 10% In-class exercises and class participation: 10% Group project presentation and report: 20%
Components of the grades
Week Topic Book Exam1 Basic Simulation Modeling 1 --2 Modeling Complex Systems 2 --3 Simulation Software 3 --4 Review of Basic Probability and Statistics 4 --
5 Building Valid, Credible and Detailed Models 5 --
6 Selecting Input Probability Distributions 6 --7 Selecting Input Probability Distributions 6 --8 Random Number Generators 7 --9 HOLIDAY -- HOLIDAY10 Random Number Generators 7 MIDTERM 11 Generating Random Variates 8 --12 Generating Random Variates 8 --13 Output Data Analysis for a Single System 9 --14 Project presentations -- --15 Output Data Analysis for a Single System 9 --
Tentative schedule of the course
Other issues - 1 Class notes/homework solutions: To be
placed regularly on the F-drive/website. Grades: To be announced in KUSIS. All
objections to grades should be made within 7 days of their announcement.
Midterm schedule: The tentative week is given, but the exact times and dates will be announced later (when the registration office schedules them) on the course web page.
NO CHEATING IN HOMEWORKS-CASES-LABS-EXAMS!! CONSEQUENCE WILL BE DISCIPLINARY ACT.
1. If a group of students cheat on one of the homeworks-cases-labs, first they will be warned and their grades for that particular homework will be given as 0. Note that we have no concern about who actually did the homework, and who just copied from her/him. They are all in the group who have cheated.
2. If any of the students cheat on another of the homeworks-cases-labs, they will be directed to the disciplinary committee.
3. If any of the students cheat on any exam, they will be directed to the disciplinary committee.
Other issues - 2
Exam rules:◦ Seating according to seating charts, no pre-seating.◦ Prepare your own cheat sheet (single two-sided A4 sheet) with your own
hand-writing. The aim of a cheat sheet is two-fold: to remind you the formulas during the exam and to provide a good review of the material while preparing it. Make sure that you prepare it on your own and do not include any problem solutions in your hand-written cheat sheet. We will check and collect them together with the exam.
◦ Everyone should bring their own calculators. We will not allow any calculator sharing or the use of cell-phones.
◦ You can have only pencils, erasers, calculators, cheat sheets and the exam papers on/below/beside your desk. You will put all your belongings either at the front or at the back of the classroom. We will not see anything except for In particular, all cell phones must be turned off and put away during the exam.
◦ Bring your school IDs with you.
Other issues - 3
Make-up policy: The make-up exams will be given to students who have a valid excuse within a week of the actual exam date. Students should be prepared accordingly.
Late policy: Late homework/project submission is not allowed.
Other issues - 4
What comes to your mind when you hear the word “simulation”?
16
Some questions
Wikipedia says:“Simulation is the imitation of the operation of a real-world process or system over time. The act of simulating something first requires that a model be developed; this model represents the key characteristics or behaviors/functions of the selected physical or abstract system or process. The model represents the system itself, whereas the simulation represents the operation of the system over time.”
17
What is simulation?
What comes to your mind when you hear the word “simulation”?
Have you seen simulations in your life before?
18
Some questions
Computer games? Excel assignments in Indr252?
19
Examples
What comes to your mind when you hear the word “simulation”?
Have you seen simulations in your life before?
Why do you think we need simulation in IE?
20
Some questions
How would you calculate how much you are going to wait in a queue?
• Any assumptions?• Are they valid?• How can we check their validity?
How would you calculate how much you are going to wait in queues if you visit Disneyland?
A queueing network?
• How to analyze them analytically?• Assumptions?
More questions on• If you are a visitor:
• How would you calculate how much you are going to wait in queues?
• …• If you are a manager of Disneyland:
• How would you calculate the effect of having one more attraction point on the queue lengths of all other points?
• If you are a manager of Disneyland: How would you decide on the effects of the entrance prices?
• …
Other complicated systems?
• Hospitals• Factories• Inventory systems• …
– Very broad term – methods and applications to imitate or mimic real systems, usually via computer
Applies in many fields and industries Very popular and powerful method
Simulation
Simulation can tolerate complex systems where analytical solution is not available.
Allows uncertainty, non-stationarity in modeling unlike analytical models
Allows working with hazardous systems Often cheaper to work with the simulated system Can be quicker to obtain results when simulated
system is experimented.
Advantages of Simulation
Don’t get exact answers, but only approximations, estimates
Requires data and statistical analysis of data to build the simulation model
Requires statistical design and analysis of simulation experiments
Requires simulation expert and compatibility with a simulation software
Softwares and required hardware might be costly Simulation modeling can sometimes be time
consuming.
The Bad News
Most real-world systems are too complex to allow realistic models to be evaluated analytically. These models are usually studied by means of simulation.
First, see whether you can solve the problem analytically; if you cannot, then use simulation.
Simulation is the technique that imitates the operations of a complex real-world system where a computer is generally used to evaluate a model numerically, and data are gathered in order to estimate the desired true characteristics of the model.
29
The Nature of Simulation
Statistical analysis often uses data that is gathered in the past. Simulation is based on statistical analysis of data that is generated on the future observations of a system by imitating its operations.
Simulation is one of the most widely used techniques in operations research, management science and industrial engineering.
30
The Nature of Simulation
Simulation Process Develop a conceptual model of the system
◦ Define the system, goals, objectives, decision variables, output measures, input variables and parameters.
Input data analysis: ◦ Collect data from the real system, obtain probability
distributions of the input parameters by statistical analysis
Build the simulation model: ◦ Develop the model in the computer using a HLPL, a
simulation language or a simulation software
Simulation Process (cont’d.) Output Data Analysis:
◦ Run the simulation several times and apply statistical analysis of the ouput data to estimate the performance measures
Verification and Validation of the Model:◦ Verification: Ensuring that the model is free from logical
errors. It does what it is intended to do.◦ Validation: Ensuring that the model is a valid
representation of the whole system. Model outputs are compared with the real system outputs.
Simulation Process (cont’d.) Analyze alternative strategies on the validated
simulation model. Use features like:◦ Animation◦ Optimization◦ Experimental Design
Sensitivity analysis:◦ How sensitive is the performance measure to the
changes in the input parameters? Is the model robust?
Getting a sum of 7 or 8 when two dice are rolled? Getting a 1 or 2 when a single die is rolled?
We can easily find the probability of each event and compare.
But let’s try to simulate:◦ We need two dice!
Since we don’t have a die we need to emulate the dice on a computer.
34
Which is more likely?
To estimate probabilities we need to roll the dice several times.
To estimate the probability exactly we need to roll the die infinitely many times but this is impractical even for a computer.
We’ll roll a finite number of times and then perform a statistical analysis.
35
Which is more likely?
The input model is more complicated and requires estimation itself ◦ i.e. number of patients arriving to an emergency room in a
certain time interval The process is much more complicated
◦ Patients are seen by a nurse and directed to a room (if available)
◦ The best doctor available has to be directed (she may be busy consulting other patients)
◦ The doctor’s exam may take a random amount of time.◦ The next step depends on the exam…
We need to emulate the dynamics and then replicate several times for statistical analysis.
36
Why are most simulation examples much more complicated?
37
Examples of simulation models in IE Systems, models and simulation Classifying simulation models Discrete-event simulation models Simulating a queueing system
Plan of the day
Designing and analyzing manufacturing systems Determining hardware and software requirements
for communications networks or for computer systems
Designing and operating transportation systems like airports, freeways, ports and subways
Evaluating designs and operations of service systems like hospitals, call centers, post offices
Reengineering of business processes Determining ordering policies for inventory systems Analyzing financial or economic systems
38
Examples
System: a collection of entities (like people or machines) that act and interact together toward the accomplishment of some logical end.
State: the collection of variables necessary to describe a system at a particular time. For example, number of customers at 10:30 on a summer day in each attraction point and the ticket box office of Disneyland Paris.
39
Systems, Models and Simulation
A system is said to be: discrete if the state variables change
instantaneously at separated points in time (Number of customers in a service system, number of machines working in a manufacturing system),
continuous if the state variables change continuously in time (The level of water in a dam, price of a share of stock).
40
Systems, Models and Simulation
41
The systems approach
• static if it represents the system at a particular time (often called Monte Carlo models) or dynamic if it represents a system that changes in time. The two dice are static
• deterministic if all components are known with certainty or stochastic if there are random components.
• continuous if the system is continuous or discrete if the system is discrete.
42
Simulation Model Classification
Simulating the roll of two dice. Let U be a continuous random variable in the interval (0,1). Then 6U is a continuous random variable in the interval (0,6). Define FLOOR(x) as the largest integer that is less than or
equal to x. Then FLOOR(6U)+1 is a discrete random variable that has
the same probability mass function as the number in the roll of a single die!
Estimate the expected value of the sum of the numbers that show up when two dice are rolled by simulation.
Estimate the probability of getting a sum of 7.
A static simulation
Consider a retailer that sells ski-jackets. The sales season is very short and the
items have to be ordered in advance. The demand for green jackets are
uniformly distributed between 0 and 100. Assume you order Q=40, 50, or 80 jackets
in advance, what is the expected sales in each case?
A Simple Inventory Example
Consider a retailer that sells ski-jackets. The sales season is very short and the
items have to be ordered in advance. What if the probability distribution of the
demand for green jackets were more complicated, as the demand here is actually a function of the weather?
Assume you order Q=40, 50, or 80 jackets in advance, what is the expected sales in each case?
A Simple Inventory Example
In dynamic systems, uncertainty has combined or accumulated events over time: this is more complicated to handle.
Most of this course focuses on modeling and simulating discrete-event dynamic systems where arrives take place at distinct points in time: arrivals and departures from a queue, arrival of a call to a call center, arrival of an ambulance to an emergency room, process completion of a part in a job-shop etc.
Simulating Dynamic Systems
Discrete-event simulation concerns the modeling of a system as it evolves over time by a representation in which the state variables change instantaneously at separate points in time.
Examples: Disneyland, hospitals, factories, airports … Many systems that falls into the working interest of IEs
We will start with one of the simplest such systems: a single server queue …
47
Discrete-Event Simulation
Aim: To estimate the expected delay (waiting time) in queue (line) of arriving customers and the utilization of the server.
The states of this system are:◦ Status of the server (busy (1) or idle (0))◦ The number of customers in the queue◦ The time of arrival of each customer in the queue
The system state changes due to the following two possible events:◦ Arrival of a customer◦ Departure of a customer due to service completion
This is in general a dynamic stochastic model since the state variables change over time in a random fashion.
A single server queuing system
49
A deterministic queue
3 4 7 8 11 12 15 t
N(t)
Customers arrive every 4 minutes, each service time is three minutes. Let us assume that at time 0-, the system is empty and that the first arrival takes place at time 0. Let us simulate for 15 minutes.
A deterministic queue: performance measures
12)(15
0
dttN
15
)()(15
00
dttN
T
dttNn
T
54
1512
n
50
3 4 7 8 11 12 15 t
N(t)
Average number of customers in the system:
A deterministic queue: performance measures
315
0}0)({ dtI tN
15
15
0}0)({
0}0)({
0
dtI
T
dtIp
tN
T
tN
153
p
51
3 4 7 8 11 12 15 t
N(t)
Percentage of time server is idle:
Arrivals occur every 4 minutes but the service time is a random variable P{S=1}=1/2 and P{S=5}=1/2.
The simulation becomes much more difficult. Q(t) is now a stochastic process. There are several sample paths that can take place in
the first 15 minutes. In fact, if S were a continuous random variable, there
would be infinitely many sample paths. Generating the next event is not trivial.
52
Adding a small randomness
Generating a sample pathLet S1=5, S2=5, S3=1, S4=5 and simulate for T=15 minutes
Time Event N(t) B(t) Q(t)
0 A1 1 1 0
4 A2 2 1 1
5 D1 1 1 0
8 A3 2 1 1
10 D2 1 1 0
11 D3 0 0 0
12 A4 1 1 0
15 End 1 1 0
1517
15
)(15
0 dttN
n
171)1215(0)1112(1)1011(2)810(1)58(2)45(1)04()(15
0
dttN
In a simulation, the simulation time or clock can be advanced in two ways:
54
Simulation Clock
• Next-event time advance (the clock advances instantaneously to the time of the next possible event)
• Fixed-increment time advance (the clock advances instantaneously for a predetermined fixed amount)
55
Queueing System ExampleFor a queueing system, the mathematical model consists of the following variables:
• ti = time of arrival of the i th customer (t0 = 0)• Ai = ti – ti-1 = interarrival time between (i-1)st and i th customers• Si = service duration of the i th customer • Di = delay in queue of the i th customer• ci = ti + Di + Si = departure time of the i th customer• ei = time of occurrence of the i th event of any type
(i th value of the simulation clock, e0 = 0)
56
Next-Event Time Advance Illustration
Generated by computer
System state: the collection of state variables necessary to describe the system at a particular time
Simulation clock: a variable giving the value of the simulated time
Event list: a list containing the next time when each type of event will occur
Statistical counters: variables used for storing statistical information about system performance
Initialization routine: a subprogram to initialize the simulation at time 0
Timing routine: a subprogram that determines the next event from the event list and then advances the simulation clock to the time when that event is to occur
57
Components of a Simulation Model
Event routine: a subprogram that updates the system state when a particular type of event occurs
Library routines: a set of subprograms used to generate random observations from probability distributions that were determined as part of the simulation model
Report generator: a subprogram that computes estimates (from the statistical counters) of the desired measures of performance and produces a report when the simulation ends
Main program: a subprogram that invokes the timing routine to determine the next event and then transfers control to the corresponding event routine to update the system state. It also checks for termination and invokes the report generator
58
Components of a Simulation Model
59
Program Flowchart
A1, A2, A3, … are independent and identically distributed (IID) random variables
S1, S2, S3, … are IID random variables FIFO service discipline We want to simulate the system until n customers have
completed their delays, i.e., the simulation will stop when the nth customer enters service.
Estimate:◦ d(n) = mean delay◦ q(n) = mean number observed in queue (excluding the
one in service)◦ u(n) = server utilization
60
Simulation of a Single Server Queue (G/G/1)
Define the stochastic processes Q(t) = number in queue at time t (excluding the customer in
service) N(t) = number in queue at time t (including the customer in
service) B(t) = status of server (0 or 1) at time t T(n) = time required to observe n delays (simulation
duration) Ti = total time during the simulation that the queue is of
length i Dk = delay of the kth customer
61
Simulation of a Single Server Queue (G/G/1)
)(
)()(ˆ
)(
)()(ˆ)(
)()(ˆ
)(ˆ
ˆ)(ˆ)(
)()(ˆ
)(
0
)(
0)(
00
0
00
1
nT
dttBnu
nT
dttQnqdttQiT
nT
iTnq
nTTp
pinqipnq
nDn
Dnd
nT
nT
nT
ii
ii
ii
ii
ii
n
kk
62
G/G/1 Calculations
pi = Proportion of time there are i customers
Area under Q curve
Area under B curve
Independence problem! (More details later)
63
Simulating a queueing system
Plan of the day
Define the stochastic processes Q(t) = number in queue at time t (excluding the customer in
service) N(t) = number in queue at time t (including the customer in
service) B(t) = status of server (0 or 1) at time t T(n) = time required to observe n delays (simulation
duration) Ti = total time during the simulation that the queue is of
length i Dk = delay of the kth customer
64
Simulation of a Single Server Queue (G/G/1)
Generated Data: Inter-arrival times: A1 = 0.4, A2 = 1.2, A3 = 0.5, A4 = 1.7, A5 = 0.2, A6 = 1.6, A7 = 0.2, A8
= 1.4, A9 = 1.9Processing times: S1 = 2.0, S2 = 0.7, S3 = 0.2, S4 = 1.1, S5 = 3.7, S6 = 0.6
Convert inter-arrival times to arrival times:I1 = A1 =0.4 (this is the arrival time of customer 1)I2 = I1 + A2 =0.4+1.2=1.6 (this is the arrival time of customer 2)I3 = I2 + A3 =1.6+0.5=2.1 (this is the arrival time of customer 3)…
65
Simulating the system
66
Simulating the systemt Event
sNext Event
N(t) Q(t) B(t)
0 {I1} I1 (0.4) 0 0 00.4 {I2,
C1 }I2 (1.6) 1 0 1
1.6 {I3, C1 }
I3 (2.1) 2 1 1
2.1 {I4, C1 }
C1 (2.4)
3 2 1
2.4 {I4, C2 }
C2 (3.1)
2 1 1
…Note that Ii and Ci are arrival times and service completion times of customer I respectively.
Simulating the system: calculating performance measures
t Events
Next Event
N(t)
0 {I1} I1 (0.4) 0 00.4 {I2,
C1 }I2 (1.6) 1 0+00.4=0
1.6 {I3, C1 }
I3 (2.1) 2 0+11.2=1.2
2.1 {I4, C1 }
C1 (2.4)
3 1.2+20.5=2.2
2.4 {I4, C2 }
C2 (3.1)
2 2.2+30.3=3.1
…Cumulative processes such as can be calculated on the fly.
dNt
0
)(
dNt
0
)(
Arrival event:
If event=arrival◦ N(t)=N(t-)+1◦ B(t)=1◦ If N(t-)>=1 then
Q(t)=Q(t-)+1◦ Else
Q(t)=Q(t-)
Events and updating the state variables
Departure event:
If event=departure– N(t)=N(t-)-1– If N(t-)=1 then
• B(t)=0• Q(t)=0
– Else• Q(t)=Q(t-)-1• B(t)=1
69
Example: the queue length Q
Simulated Data: A1 = 0.4, A2 = 1.2, A3 = 0.5, A4 = 1.7, A5 = 0.2, A6 = 1.6, A7 = 0.2, A8 = 1.4, A9 = 1.9S1 = 2.0, S2 = 0.7, S3 = 0.2, S4 = 1.1, S5 = 3.7, S6 = 0.6
6.8)6(4.1)2.76.8(
7.1)8.52.7()1.24.2(3.2)6.58.5()0.49.4(
)4.21.3()6.11.2(2.3)9.46.5(
)1.30.4()0.06.1(
3
2
1
0
TTT
T
T
Calculations
70
Example: the queue length Q
Simulated Data: A1 = 0.4, A2 = 1.2, A3 = 0.5, A4 = 1.7, A5 = 0.2, A6 = 1.6, A7 = 0.2, A8 = 1.4, A9 = 1.9S1 = 2.0, S2 = 0.7, S3 = 0.2, S4 = 1.1, S5 = 3.7, S6 = 0.6
Calculations
15.16.89.9
)6()6(ˆ
9.9)4.13()7.12(
)3.21()2.30(
0
0
T
iTq
iT
ii
ii
71
Example: the busy process BCalculations
90.06.87.7
6.8)8.36.8()4.03.3(
)6(
)()6(ˆ
)6(
0
T
dttBu
T
6.8)6(4.1)2.76.8(
7.1)8.52.7()1.24.2(3.2)6.58.5()0.49.4()4.21.3()6.11.2(
2.3)9.46.5()1.30.4()0.06.1(
3
2
1
0
TTTTT
72
Calculations
15.16.89.9
)6()6(ˆ
9.9)4.13()7.12()3.21()2.30(
0
0
T
iTq
iT
ii
ii
Not really reliable because of lack of data!
90.06.87.7
6.8)8.36.8()4.03.3(
)6(
)()6(ˆ
)6(
0
T
dttBu
T
73
Snapshots of the System During Simulation
Figure 1.7 Snapshots of the system and of its computer representation at time 0 and each
of the 13 succeeding event times
74
Snapshots of the System During Simulation
75
Snapshots of the System During Simulation
76
Snapshots of the System During Simulation
77
Snapshots of the System During Simulation
78
Snapshots of the System During Simulation
Goes on... See book for complete set of snapshots.
79
Snapshots of the System During Simulation
5.7 9.9 7.7ˆ ˆ(6) 0.95, (6) 1.15, (6) 0.906 8.6 8.6
d q u Stopping Rule
Suppose that X has the exponential distribution with mean , and U has the uniform distribution on [0, 1]
Given a random number U on [0, 1], then the transformation
is another random variate with the distribution
which implies that X has the exponential distribution with mean .
80
Random Variate Generation
// 1}{)(,1}{)(
1}{)(,}{)(
xU
xX
UU
edx
xUdPxfexXPxF
dxxUdPxfxxUPxF
UX ln
// 1}{}/{ln}ln{}{ xx eeUPxUPxUPxXP
There are many routines to generate random numbers on [0, 1] and this transformation procedure can be used to generate random numbers (variates) that have the exponential distribution. Almost all programming languages have such a routine.
To get more accurate results, the length of the simulation must be extended (perhaps n = 1,000 or more). The simulation cannot be performed manually and we need a computer to perform the simulation.
81
Random Variate Generation
82
Flowchart for Arrivals Routine
83
Flowchart for Departures Routine
Typical Output Report when n = 1,000 Customers
Note that the model that is simulated is an M/M/1 queue for which analytical results are available as given below.
)000,1(ˆ460.05.01
)000,1(ˆ418.05.0)(
)000,1(ˆ430.05.0)(
1,2,1
0
2
uPu
qLq
dWd
s
q
q
Another common stopping rule to terminate a simulation is to use a fixed run length. The simulation stops as soon as the simulation clock exceeds this fixed duration. The simulation program should be adjusted accordingly. This is done by defining a new event as the termination event scheduled at the fixed time.
85
Alternative Stopping Rules
86
Output Report when T = 480 Minutes (8 Hours)
2
0
1, 2, 1
ˆ0.5 0.399 (480)( )
ˆ0.5 0.394 (480)( )
ˆ1 0.5 0.464 (480)
q
q
s
d W d
q L q
u P u
A company that sells a single product would like to determine how many items it should have in inventory for each of the next n months. The times between demands are IID exponential random variables with a mean of 0.1 month. The size of the demands, D, are IID random variables which are 1, 2, 3 or 4 with probabilities 1/6, 1/3, 1/3 and 1/6 respectively. Such a demand process is known as a compound Poisson process.
87
Simulation of an Inventory System
Simulate the system for a period of n months At the beginning of each month, the inventory
level is reviewed and a decision is made on how much to order. If Z units are ordered, then the cost is K + iZ where K = $32 is the setup cost and i = $3 is the incremental cost. The lead time for deliveries is random and uniformly distributed between 0.5 and 1 month.
88
Simulation of an Inventory System
The company uses a stationary (s, S) policy so that if the inventory level is I, then
If demand exceeds the inventory level, the excess demand is backlogged and satisfied by future deliveries. But, there is a shortage cost = $5 per item per month in backlog. Moreover, there is a holding cost of h = $1 per item per month held in inventory.
Our aim is to choose the best-performing values of (s,S) among 9 possible choices of (s,S).
I(t) = inventory position at time t I+(t) = max {I(t), 0} = number of items physically on hand at time
t I-(t) = max {-I(t), 0} = number of items backlogged at time t
Simulation of an Inventory System
sIsIIS
Z if0 if
90
I
Ihn
dttII
n
dttII
nn
cost shortage Average
holding Average
)(,
)(00
The Inventory System
Suppose that U has the uniform distribution on [0, 1], then it turns out that
has the exponential distribution with mean (0.1 month). If we also define
then
which implies that L has the uniform distribution between a (0.5 month) and b (1 month).
91
Random Variate Generation
UX ln
UabaL )(
abax
abaxUPxUabaPxLP
)(}{
Similarly, if we define
then D is a discrete random variable which is equal to 1, 2, 3 or 4 with probabilities 1/6, 1/3, 1/3 and 1/6 respectively.
92
Random Variate Generation
165 if4
65
21 if3
21
61 if2
610 if1
U
U
U
U
D
93
Flowchart for Evaluation Routine
94
Fortran and C program codes are developed and given in the textbook. The simulation is run for n = 120 months and the output on the right is obtained.
95
Steps in a Sound Simulation Study
Maybe queue is unbounded!Are the numbers reasonable?
Is it M/M/1, What are the parameters?...
For a bank ATM simulation:1 ATM simulate it2 ATM simulate it3 ATM simulate...
See how performance measures change.
96
Other Types of Simulation Continuous Simulation
This involves models where the state variables change continuously over time and events are not discrete.
Example 1.3: Let y(t) and x(t) denote respectively the size of two biological populations of predators (sharks) and preys (food fish) at time t. The interaction between them can be described by the following continuous model through differential equations:
dx(t)/dt = rx(t) – ax(t)y(t)
dy(t)/dt = -sy(t) + bx(t)y(t)
This is a deterministic model that can be solved by numerical methods (A finite-difference approach can be made). It can be made stochastic by adding stochastic terms to it to obtain stochastic differential equations, like
dx(t)=(rx(t) – ax(t)y(t))dt + x(t)dw(t)where dw(t) is the so-called white-noise. There are simulation programs (like SIMULINK, Dymola, Arena, AweSim and Extend) for such continuous simulation models.
97
Continuous Simulation
98
Deterministic Solution
Continuous Simulation
Discrete-Continuous Simulation This involves mixtures where discrete events as well as
continuous state changes are possible (Arena, AweSim and Extend).
Monte Carlo Simulation This is basically a static simulation method without events
occurring in dynamic time. It generally involves generation and use of uniform random variates to estimate a quantity of interest.
Example 1.5: Suppose that g(x) is not an analytically
integrable function and we want to evaluate the integral
99
Other Types of Simulation
.)(b
a
dxxgI
This deterministic problem can be analyzed using Monte Carlo simulation by taking X as a uniformly distributed random variable between a and b so thatX = a + (b – a)U. Let Y = (b - a)g(X), then
The integral I can now be estimated by estimating the mean
of Y through Monte Carlo simulation by generating U(a,b) IID random variates X1, X2, … , Xn.
100
Monte Carlo Simulation
Idxxgab
dxxgabdxxfxgab
XgEabXgabEYE
b
a
b
ab
a X
)()(
)()()()()(
)()()()(
nUabagab
nXgab
nY
nYIn
i in
i in
i i
111))(()()()(
)(ˆ
fx(x) = 1/(b-a)
101
Simulation Results
A short review on simulation Advantages/disadvantages/pitfalls of
simulation Class exercise from Tuesday Modeling complex systems
102
Plan of the day
Simulation is often the only type of investigation for complex real-world systems with stochastic elements that cannot be analytically evaluated.
It allows one to estimate the performance of a system under a projected set of operating conditions.
Alternative proposed system designs or alternative operating policies can be compared via simulation.
There is better control over experimental conditions in simulation than there is in experimenting with the system itself.
Simulation allows one to study the system with a long time frame due to time compression.
103
Advantages
Each run of a simulation run provides an estimate and not the exact value of model characteristics. An analytical model and its solution, if available, is always preferable.
Simulation models are often expensive and time-consuming to develop.
The large volume of numbers produced or the persuasive impact of a realistic animation often creates a tendency to place more confidence in the results than it is justified.
104
Disadvantages
Failure to have a well-defined set of objectives Inappropriate level of model detail Failure to communicate with management Misunderstanding of the simulation by management Treating simulation as a computer programming exercise Lack of simulation methodology and statistics knowledge Failure to collect good system data Inappropriate simulation software Using software packages without knowing what it is really
doing Belief that easy-to-use simulation packages require lower
level of technical competence
105
Pitfalls
Misuse of animation Failure to understand sources of randomness Using arbitrary distributions Analyzing the output data from only one
simulation run (replication) Treating the output values as true values and not
estimates Comparing alternatives based on one replication Using the wrong performance measures
106
Pitfalls
107
Solution of the class exercise Summary of what we did in the last class Random variate generation Complete the simulation of a single-server
queue Simulation of an inventory system Other types of simulation Advantages/disadvantages of simulation
108
Plan of the day
The university management is considering a shuttle service between Sariyer and the university. The shuttle buses are to be scheduled once in 5 minutes from Sariyer. The following table presents the inter-arrival times of the students:
You are supposed to report on the waiting times of the students. Do the simulation for these 21 people to find the average waiting time of a student.
The management needs to decide on the capacity of the shuttles. Their options are 4, 13, and 17. If one shuttle is full, they need to provide another shuttle with the same capacity. Let Ci be the cost of a shuttle with i capacity, C4=5, C13=10, and C17=15. Depending on your simulation analysis, which capacity would you suggest?
109
Class exercise
Customer 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21Inter-arrival time 0.4 0.6 0.4 1.0 1.1 0.4 0.1 0.5 1.3 0.7 0.4 0.8 0.1 0.3 1.1 0.2 1.9 1.4 2.0 0.4 0.2
Shuttle 1 2 3 4
# in the shuttle
8 8 3 ?
Customer 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Inter-arrival time 0.4 0.6 0.4 1.0 1.1 0.4 0.1 0.5 1.3 0.7 0.4 0.8 0.1 0.3 1.1 0.2 1.9 1.4 2.0 0.4 0.2
Arrival time 0.4 1.0 1.4 2.4 3.5 3.9 4.0 4.5 5.8 6.5 6.9 7.7 7.8 8.0 9.2 9.4 11.3 12.7 14.7 15.1 15.3Waiting time 4.6 4.0 3.6 2.6 1.5 1.1 1.0 0.5 4.2 3.5 3.1 2.3 2.2 2.0 0.8 0.6 3.7 2.3 0.3 4.9 4.7
110
Solution