chapters 1, 2 & 3: a brief...

34
1 Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson Northwestern University July 2017

Upload: others

Post on 25-Sep-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

1

Chapters 1, 2 & 3:A Brief Introduction

©Barry L. NelsonNorthwestern University

July 2017

Page 2: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Why do we simulate?

• We typically choose to simulate a dynamic, stochastic system when the performance measure we want…– Is not analytically tractable.– Is not computationally tractable.– Cannot be approximated with a bound on the

error.

• Let's start with a very simple example to remind us what we are doing and why.

2

Page 3: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

3

Discrete-event simulation example

Page 4: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

4

Page 5: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

5

Page 6: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

6

Features

Page 7: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

7

Outputs

Page 8: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

8

Time averages

Page 9: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

9

Performance measures

Page 10: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

10

This book

Page 11: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Structure of a discrete-event simulation

• Main program– Initialize state variables,

clock, statistics– Schedule at least one

future event– Simulation loop: Until

ending condition met• Call Timer to find next

event• Call event subprogram

– Final update of statistics and report results

• Timer subprogram– Remove next event from

event calendar– Advance clock– Return event type

• Event subprograms– Update state variables– Schedule any future

events– Update statistics

Page 12: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

12

Dim Clock As Double ' simulation clockDim NextFailure As Double ' time of next failure eventDim NextRepair As Double ' time of next repair eventDim S As Double ' system stateDim Slast As Double ' previous value of the system stateDim Tlast As Double ' time of previous state changeDim Area As Double ' area under S(t) curve

Private Function Timer() As StringConst Infinity = 1000000

' Determine the next event and advance timeIf NextFailure < NextRepair Then

Timer = "Failure"Clock = NextFailureNextFailure = Infinity

ElseTimer = "Repair"Clock = NextRepairNextRepair = Infinity

End IfEnd Function

Global declarations

Programming quick start

Page 13: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

13

Private Sub TTF()' Program to generate a sample path for the TTF example

Dim NextEvent As StringConst Infinity = 1000000Rnd (-1)Randomize (1234)

' Initialize the state and statistical variablesS = 2Slast = 2Clock = 0Tlast = 0Area = 0

' Schedule the initial failure eventNextFailure = WorksheetFunction.Ceiling(6 * Rnd(), 1)NextRepair = Infinity

' Advance time and execute events until the system failsDo Until S = 0

NextEvent = TimerSelect Case NextEventCase "Failure"

Call FailureCase "Repair"

Call RepairEnd Select

Loop

' Display outputMsgBox ("System failure at time " _

& Clock & " with average # functional components " & Area / Clock)End

End Sub

Page 14: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

14

Private Sub Failure()' Failure event' Update state and schedule future events

S = S - 1If S = 1 Then

NextFailure = Clock + WorksheetFunction.Ceiling(6 * Rnd(), 1)NextRepair = Clock + 2.5

End If

' Update area under the S(t) curveArea = Area + Slast * (Clock - Tlast) Tlast = ClockSlast = S

End Sub

Private Sub Repair()' Repair event' Update state and schedule future events

S = S + 1If S = 1 Then

NextRepair = Clock + 2.5NextFailure = Clock + WorksheetFunction.Ceiling(6 * Rnd(), 1)

End If

' Update area under the S(t) curveArea = Area + Slast * (Clock - Tlast) Tlast = ClockSlast = S

End Sub

Page 15: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Important Computer Simulation Concepts

15

U X YSource of randomness, usually assumed i.i.d. U(0,1)

Input random variables with known distributions that we specify; ex: component TTF is DU(1,2,3,4,5,6)

Output random variables whose properties we want to estimate; ex: system TTF

algorithm logic

Page 16: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Random-number generation

16

Page 17: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Random-variate generation

17

Page 18: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Replications

18

Page 19: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

19

Private Sub TTFRep()' Program to generate a sample path for the TTF example

Dim NextEvent As StringConst Infinity = 1000000Rnd (-1)Randomize (1234)

' Define and initialize replication variablesDim Rep As IntegerDim SumS As Double, SumY As DoubleSumS = 0SumY = 0For Rep = 1 To 100

' Initialize the state and statistical variablesS = 2Slast = 2Clock = 0Tlast = 0Area = 0

' Schedule the initial failure eventNextFailure = WorksheetFunction.Ceiling(6 * Rnd(), 1)NextRepair = Infinity

' Advance time and execute events until the system failsDo Until S = 0

NextEvent = TimerSelect Case NextEvent

Case "Failure"Call Failure

Case "Repair"Call Repair

End SelectLoop

' Accumulate replication statisticsSumS = SumS + Area / ClockSumY = SumY + Clock

Next Rep' Display output

MsgBox ("Average failure at time " _& SumY / 100 & " with average # functional components " & SumS / 100)

EndEnd Sub

Replication version of TTF

Initialize random number generator

Page 20: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Canonical examples

• To illustrate things as we go along we will use 4 ½ small examples that are– Easy to simulate.– Don't actually need to be simulated (they are

pretty tractable).

• This will allow us to see the issues that arise in general without getting buried in details.

• These examples are also useful for testing new ideas in simulation.

20

Page 21: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

M(t)/M/∞ queue

• A queue with "ample" (infinite) servers. Used to design systems that should have adequate capacity nearly always.

• Arrivals are described by a nonstationaryPoisson arrival process with rate λ(t).

• Service times are independent and identically distributed exponential with finite mean τ.

• Examples: parking lot for large mall; cell phone system.

21

Page 22: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

22

More on M(t)/M/∞

Page 23: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

23

λ(t)

Mean number of cars in the garage m(t)

Distribution of number in the garage at mean m*

Page 24: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Simulation issues

• How do we simulate a nonstationary arrival process?

• How do we program a simulation that could (conceptually) have nearly an infinite number of "car departure" events?

• What relevant performance measure can we actually get out of a simulation?

24

Page 25: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

25

Stochastic activity network (SAN)

Page 26: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

26

More on the SAN

Page 27: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

27

Simulation issues

Page 28: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

M/G/1 queue

• A single-queue, first-come-first-served service system with one server.

• Arrivals are described by a stationary Poisson arrival process (interarrivals exponential 1/λ)

• Service times are independent and identically distributed with finite mean τ and standard deviation σ.

• Examples: video kiosk, ticket window, ATM machine, receptionist.

28

Page 29: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

29

M/G/1 & Lindley's equation

Page 30: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

30

What is known?

Page 31: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Simulation issues

• The quantities of interest are defined in the limit; easy (sometimes) mathematically; hard (nearly always) in simulation.

• The experiment design is not so clear: One very long run or multiple replications?

• As ρ→ 1 both the mean and the variability of Y explode (e.g., the standard deviation of Ygrows as 1/(1-ρ)).

31

Page 32: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

The AR(1) surrogate model

32

Page 33: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

33

Asian option

Page 34: Chapters 1, 2 & 3: A Brief Introductionusers.iems.northwestern.edu/~nelsonb/IEMS435/Chapter1-2-3.pdf · Chapters 1, 2 & 3: A Brief Introduction ©Barry L. Nelson. Northwestern University

Simulation issues

34