Top Banner
Simulation II IE 2030 Lecture 18
49

Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Dec 26, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation II

IE 2030

Lecture 18

Page 2: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Outline: Simulation II

• Advanced simulation demo

• Review of concepts from Simulation I

• How to perform a simulation– concepts: state variables, events, etc.– example

• Sampling

• Verification and Validation

Page 3: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Core Concepts

• Steady State

• Transient

• Sample size, run length

• Variability of runs

• State variables

• Event

• Clock

• Activity

• Simulation Table

• FEL (future event list)

Page 4: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Concepts from Simulation I

• (Pseudo-) Random number generator

• Length of run– startup or

transient behavior– steady state

• Stability• Variability of runs

There is no perfect random number generator

Should be enough to get steady state behavior. Often initial behavior is atypical

E.g. of queue length 2 runs of a simulation

perform differently

Page 5: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Using pseudo-random numbers

• Most generators produce a (pseudo)random value x uniformly distributed on [0,1].

• Example: you want 1 w.p. 1/3, 2 w.p.1/3,• and 5 w.p. 1/3.

� 0 <= x <= 1/3 gives value 1� 1/3<= x <= 2/3 gives value 2� 2/3<= x <= 1 gives value 5

� cumulative distribution function F :� F(.9)=0; F(1)=1/3 ; F(2)=2/3; F(5)=1

Page 6: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Using pseudo-random #’s

• What are you doing? Let F* be the inverse of the cumulative distribution function of your distribution. – F*(x)= 1 for 0 <= x <= 1/3– F*(x) = 2 for 1/3 < x <= 2/3– F* (x) = 5 for 2/3 < x <= 1– You are computing F*(x) where x is U[0,1]

ctovey:

don’t worry about < vs. <=

ctovey:

don’t worry about < vs. <=

Page 7: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Another example: exponential

• You want to generate a value for an exponentially distributed random variable.

• You have x, a uniform [0,1] value

• Compute F*(t) = - log(1-t)

• Apply F* to x

Page 8: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Using tables of random numbers

• Use consecutive values in table to approximate a uniform distribution– then apply same method shown for U[0,1]

• If you only need a Bernoulli p=1/2 valuecan use one value more directly e.g. even/odd or 0-4 and 5-9.

• Same for some other simple discrete distributions, probabilities in tenths

• thirds: skip 0, 1-3,4-6,7-9

Page 9: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

How to perform a simulation

• State variables -- describe state of system, give a “system snapshot”.

• Event: anything that can change the state of the system

• FEL, Future Event List• Clock• Keep all these and any desired cumulative

statistics in a simulation table

Page 10: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 5.6x2 = 4.8x3 = 7.9

n =3

Clock2:14

2:16n decreases by 1

Future Event List

Page 11: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 5.6x2 = 4.8x3 = 7.9

n =3

Clock2:15

2:16n decreases by 1

Future Event List

(we don’t need this)

Page 12: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 5.6x2 = 4.8x3 = 7.9

n =3

Clock2:16

2:16n decreases by 1

Future Event List

Page 13: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 5.6x2 = 4.8x3 = 7.9

n =2

Clock2:16

2:21x1 = x3 - x2

Future Event List

Page 14: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 5.6x2 = 4.8x3 = 7.9

n =2

Clock2:21

2:21x1 = x3 - x2

Future Event List

Page 15: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Events and State VariablesState variables

x1 = 3.1x2 = 4.8x3 = 7.9

n =2

Clock2:21

2:25n increases by 2

Future Event List

Page 16: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Example: Clocks and Socks(Foley & Tovey)

• I have n pairs of socks in my dryer. I remove socks 1 at a time and place them on top of the dryer. When I get a matching pair, I fold them and place them in my laundry basket.

• How much room do I need on top of my dryer?

Page 17: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Clocks and Socks

• n couples plan to meet under the clock at 6:00 pm. People arrive 1 at a time. When a couple meets, they leave to go eat dinner.

• How big does the crowd under the clock get?

Page 18: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

clocks and socks

• Orders for parts arrive at a warehouse. Each order is for Kmin to Kmax different parts.

• The ASRS system retrieves one type of part for one order at at time.

• Partially completed orders are stored on pallets in a WIP storage area.

• How big should the WIP storage area be?

Page 19: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulating Clocks and Socks

• Assume n pairs distinct socks• notation: Li, Ri, i=1,...,n: the two socks• Assume I remove a sock from dryer in 1 sec. I

check for match and fold, all in 2 sec– Could have assumed I check for a match in 5 sec; fold

and toss into basket in 3 sec.

* This is like implementing an algorithm. You usually have to make additional decisions or assumptions.

Page 20: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

clocks and socks: state variables

• For each i=1,...n, Li and Ri can equal– D if in dryer– T if on top of dryer– DT if being moved to dryer top– B if in basket

• The values of the variables Li and Ri (together with the clock time t) provide a complete system snapshot

Page 21: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

initial snapshot

• Li = Ri = D for all i=1,...,n

• t=0

• useful extra state variable (not logically necessary): – nD = # of socks in dryer

• nD = 2n initially

– nT = # socks on dryer top• nT = 0 initially

Page 22: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Future event list

• Event: anything that can change the state of a system

• FEL: a list of events that you know about, but that have not yet occurred, i.e. with times > =t (usually >t)

• First event on FEL: time 0. Grab a sock from dryer. (t=0)

• Second event will be: put sock on dryer top (t=1).

Page 23: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Event types

• 1st type (grab) : a sock leaves the dryer. Its state changes from D to DT. nD decreases.

• 2nd type (arrive top): a sock arrives at the dryer top. Its state changes from DT to T.

• 3rd type (fold): a pair of socks is matched, folded, and put in basket. Both socks have a change in state from T to B

Page 24: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Clock and Sock Activities

• Activity: a time interval. Triggers an event.

• Activity: moving sock from dryer to top– event triggered: sock arrives on top of dryer

• Activity: checking for a match (2sec)– event triggered: possibly, fold (placing sock

pair in basket); certainly, grab sock from dryer, unless nD=0

Page 25: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=0- (startup)

• L1=D• R1=D• L2=D• R2=D• nD=4• nT=0

• t=0 Grab a sock from dryer

Page 26: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=0

• L1=D• R1=D• L2=DT• R2=D• nD=3• nT=0

• t=0 Grab a sock from dryer – to process this event

we need a random integer in [1,...,nD]. In this case, say it is 3. So grab L2.

Page 27: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=0+

• L1=D• R1=D• L2=DT• R2=D• nD=3• nT=0

• t=1 arrive top sock L2 placed on top of dryer

Page 28: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=1

• L1=D• R1=D• L2=T• R2=D• nD=3• nT=1

• t=1 arrive top sock L2• t=3 grab a sock from

dryer

Page 29: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=1+

• L1=D• R1=D• L2=T• R2=D• nD=3• nT=1

• t=3 grab a sock from dryer

Page 30: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=3

• L1=DT• R1=D• L2=T• R2=D• nD= 2• nT=1

• t=3 grab a sock from dryer. Needs random integer from 1 to 3=nD. In this case, say it was 1.

Page 31: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=4

• L1=T• R1=D• L2=T• R2=D• nD= 2• nT=2

• event t=4 arrive top L1

Page 32: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=4+

• L1=T• R1=D• L2=T• R2=D• nD= 2• nT=1

• t=6 grab a sock

Page 33: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=6

• L1=T• R1=DT• L2=T• R2=D• nD= 1• nT=2

• t=6 grab a sock, say it is R1

Page 34: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=6+

• L1=T• R1=DT• L2=T• R2=D• nD= 1• nT=2

• t=7 arrive top R1

Page 35: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Processing Events

• (grabz) : Sock z state changes from D to DT. nD--. Sock move activity (1 sec) triggers arrive top z.

• (arrive top z): Sock z state changes from DT to T. nT++. Checking for match, 2 secs: If z’s match is on T, triggers fold z’s pair. Triggers grab unless nD=0.

• (fold): both socks change state from T to B.nT decreases by 2.

Page 36: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=7

• L1=T• R1=T• L2=T• R2=D• nD= 1• nT= 3

• t=7 arrive top R1

Page 37: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=7+

• L1=T• R1=T• L2=T• R2=D• nD= 1• nT= 3

• t= 9 fold pair 1• t=9 grab (R2)

– we process the fold before the grab

Page 38: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=9

• L1=B• R1=B• L2=T• R2=D• nD= 1• nT= 1

• t= 9 fold pair 1• t=9 grab (R2)

– we process the fold before the grab

Page 39: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=9

• L1=B• R1=B• L2=T• R2=DT• nD= 0• nT= 1

• t=9 grab (R2)

Page 40: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=9+

• L1=B• R1=B• L2=T• R2=DT• nD= 0• nT= 1

• t=10 arrive top R2

Page 41: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=10

• L1=B• R1=B• L2=T• R2=T• nD=0• nT= 2

• t=10 arrive top R2

• add the event:• t=12 fold pair 2• don’t add grab event

since nD=0

Page 42: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Simulation: n=2t=12

• L1=B• R1=B• L2=B• R2=B• nD=0• nT= 0

• t=12 fold pair 2

• no events are placed on FEL -- simulation terminates

Page 43: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

other variables• Summary stats you might keep track of:

– number of socks on top of dryer– maximum number of socks on top of dryer– average (by time? by sock pick?) number of socks on dryer

top– for each i, length of time 2,1, and 0 socks in pair i are in dryer

• You can walk through your simulation a second time to collect these statistics. – Almost always easier to collect them as the simulation

progresses

Page 44: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Clocks and Socks

• If we were only interested in nT, number on dryer top, we could eliminate the activity of checking for a match.

• If checking for a match took longer when nT was big, we might let the activity time in the simulation vary with nT, and collect more information about time spent checking.

Page 45: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Sampling

• How to deal with transient behavior:– discard it– use long enough runs that its effect is negligible– “hot-start” the simulation (can be risky)– run length: how do you know in “steady state”?

• Not defined for one sample path

• the more variability, the longer run length is needed

• Variability from one run to another– sample size: number of runs

Page 46: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Verification & Validation• Building the model

right– like debugging a

computer program

– use a pseudo-random number generator that is deterministic given the seed

• Building the right model– does the model

accurately predict what happens in the real system?

– Several levels of validation

– use many seeds

Page 47: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Verification & Validation• Building the

model right• Examples of bugs:

– triggering a grab when nD=0

– not decreasing nT

• Building the right model– Do we really remove

socks from the dryer in random order?

– Are our activity times accurate (if we care)?

– Does it accurately predict dryer top usage?

Page 48: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

Types of Validation

• Face Validity: Does an expert think that the simulation model behaves realistically?– domain expert, not simulation expert

• Weak External Validity: Does the output of the simulation match the behavior of the system that is being simulated?

Page 49: Simulation II IE 2030 Lecture 18. Outline: Simulation II Advanced simulation demo Review of concepts from Simulation I How to perform a simulation –concepts:

More Kinds of Validation• Strong External Validity: Make a change to the

simulation model and make the corresponding change to the actual system. Compare the simulation output to the actual system behavior. – Does the model correctly predict the effects of

changes to the system?

• Validation of Assumptions: Test the assumptions made by the model. – E.g., independence or distribution of arrivals