42
MIT 2.853/2.854 Manufacturing Systems Introduction to Simulation Lecturer: Stanley B. Gershwin ... with many slides by Jeremie Gallien Copyright c 2009 Stanley B. Gershwin.

MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare 2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

MIT 2.853/2.854Manufacturing Systems

Introduction to Simulation

Lecturer: Stanley B. Gershwin... with many slides by Jeremie Gallien

Copyright c©2009 Stanley B. Gershwin.

Page 2: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

Copyright c©2009 Stanley B. Gershwin. 2

Slide courtesy of Jérémie Gallien. Used with permission.

Page 3: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

A computer simulation is a computer program ...

• that calculates a hard-to-calculate quantity usingstatistical techniques; OR

• that models the behavior of a system by imitatingindividual components of the system and theirinteractions.

I am not entirely satisfied with this definition — it doesnot seem restrictive enough. If all goes well, you willknow what a computer simulation is after this lecture.

Copyright c©2009 Stanley B. Gershwin. 3

Page 4: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

By contrast, a mathematical model is ...

• a mathematical representation of a phenomenon ofinterest.

Computer programs are often used to obtainquantitative information about the thing that ismodeled.

Copyright c©2009 Stanley B. Gershwin. 4

Page 5: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

Purposes

Simulation is used ...

• for calculating hard-to-calculate quantities ...

⋆ from mathematics and science,⋆ from engineering, especially system design.

• for developing insight into how a system operates,

• for demonstrating something to bosses or clients.

Copyright c©2009 Stanley B. Gershwin. 5

Page 6: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

Types of simulation

•Static, for the evaluation of a quantity that is difficultto evaluate by other means. The evolution of asystem over time is not the major issue.

•Dynamic, for the evaluation of quantities that arisefrom the evolution of a system over time.

Copyright c©2009 Stanley B. Gershwin. 7

Page 7: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

Types of simulation

•Static — Monte Carlo

•Dynamic

⋆ Discrete time⋆ Discrete event⋆ Solution of differential equations — I don’t consider

this simulation, but others do.

Copyright c©2009 Stanley B. Gershwin. 7

Page 8: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

Types of simulation

Copyright c©2009 Stanley B. Gershwin. 8

Slide courtesy of Jérémie Gallien. Used with permission.

Page 9: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

What isSimulation?

Types of simulation

Copyright c©2009 Stanley B. Gershwin. 9

Slide courtesy of Jérémie Gallien. Used with permission.

Page 10: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Time Simulation

Appropriate for systems in which:

• Time is discrete.

⋆ If time in the real system is continuous, it is discretized.

• There is a set of events which have a finite number of possibleoutcomes. For each event, the outcome that occurs isindependent of the other simultaneous events and of all pastevents.

• There is a system state which evolves according to the eventsthat occur.

⋆ That is, the system is a discrete time Markov chain.⋆ Often, other systems can be transformed into or

approximated by discrete time Markov chains.Copyright c©2009 Stanley B. Gershwin. 10

Page 11: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Time Simulation

To model a random event that occurs with probabilityp, let u be a pseudo-random number which isdistributed uniformly between 0 and 1.

•Generate u.

• If u ≤ p, the event has occured. Otherwise, it hasnot.

Copyright c©2009 Stanley B. Gershwin. 11

Page 12: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Time Simulation

Two-Machine Line

PERL code excerpt, Machine 1:for ($step=0; $step <= $T; $step++){

• if($alpha1[$step]==1)

⋆ {if (rand(1)<$p1){$alpha1[$step+1]=0}

else{$alpha1[$step+1]=1}}

• else

⋆ {if (rand(1)<$r1){$alpha1[$step+1]=1}

else{$alpha1[$step+1]=0}}

• if(($alpha1[$step+1]==1)&&($n[$step]<$N)) {$IU=1}

else{$IU=0}

Copyright c©2009 Stanley B. Gershwin. 12

Page 13: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Time Simulation

Two-Machine Line

Machine 2 is similar, except:

if(($alpha2[$step+1]==1)&&($n[$step]>0)){$ID=1;$out++;}

else{$ID=0}

where $out is a counter for the number of partsproduced.

Buffer:

$n[$step+1]=$n[$step]+$IU-$ID;

Copyright c©2009 Stanley B. Gershwin. 13

Page 14: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Time Simulation

Two-Machine Line

•Advantage: easy to program

• Limitations:

⋆ geometric distributions, or others that can beconstructed from geometric distributions;

⋆ discrete time, or highly discretized continuous time

•Disadvantage: slow. Calculation takes place at everytime step.

Copyright c©2009 Stanley B. Gershwin. 14

Page 15: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

•Appropriate for systems in which:

⋆ Events occur at random times and have a finite setof possible outcomes.

⋆ There is a system state that evolves according tothe events that occur.

•Time can be discrete or continuous. Discretization isunnecessary.

•These conditions are much less restrictive than fordiscrete time simulations.

Copyright c©2009 Stanley B. Gershwin. 15

Page 16: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

Method:

1. Starting at time 0, determine the next time of occurence for allpossible events. Some times will be obtained deterministically;others from a random number generator.

2. Create an event list , in which all those events are sorted bytime, earliest first.

3. Advance the clock to the time of the first event on the list.

4. Update the state of the system according to that event.

Copyright c©2009 Stanley B. Gershwin. 16

Page 17: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

5. Determine if any new events are made possible by the changein state, calculate their times (in the same way as in Step 1),and insert them into the event list chronologically.

6. Determine if any events on the list are made impossible by thecurrent event. Remove them from the event list. Also, removethe current event from the list.

7. Go to Step 3.

Copyright c©2009 Stanley B. Gershwin. 17

Page 18: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

Two-Machine Line

Assume the system starts with both machines up, thebuffer with n > 1 parts in it. The clock is at t = 0.

• Possible next events: M1 failing, M2 failing. Pick times for bothevents from the up-time distributions.

• Advance clock to the first event. Suppose it is M1 failing.

⋆ Possible next events: M2 failing (already on the list), bufferemptying, M1 getting repaired.

⋆ Pick the time for M1 getting repaired from M1’s down-timedistribution. Calculate the time for the buffer emptyingdeterministically from the current buffer level.

Copyright c©2009 Stanley B. Gershwin. 18

Page 19: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

Two-Machine Line

• Delete current event from the list, and advance the clock to thenext event. Assume it is the buffer emptying.

⋆ Now we have to adjust the list because M2 cannot fail whilethe buffer is empty.

⋆ The only possible next event is the repair of M1. Pick thetime from the random number generator.

• etc.

Copyright c©2009 Stanley B. Gershwin. 19

Page 20: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

Two-Machine Line

Copyright 2002 © Jérémie Gallien

Discrete-Event Algorithm

initialization()

timing(event_list)

event_occurence(next_event)

termination test?

report_generator(stat_counters)

• all variables are initialized

• next_event is determined;• sim_clock is updated.

• system_stateis updated;• stat_countersis updated;• rv_generation()is used to

update event_list.

• based on number of iterations, precision achieved, etc…

• statistical analysis, graph, etc…

Copyright c©2009 Stanley B. Gershwin.

Slide courtesy of Jérémie Gallien. Used with permission.

20

Page 21: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Discrete Event Simulation

Two-Machine Line

•Advantages:

⋆ Fast. Calculation only occurs when an eventoccurs.

⋆ General. The time until an event occurs can haveany distribution.

⋆ Commercial software widely available.

• Limitations: ????

•Disadvantage: Hard to program. (But see“Advantages.”)

Copyright c©2009 Stanley B. Gershwin. 21

Page 22: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Random numbers are needed. This is not trivialbecause a computer is inherently deterministic.

•They must be

⋆ distributed according to a specified distribution; and⋆ independent.

• It is also very desirable to be able to reproduce thesequence if needed — and not, if not needed.

Copyright c©2009 Stanley B. Gershwin. 22

Page 23: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. . 23

Slide courtesy of Jérémie Gallien. Used with permission.

Page 24: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

A pseudo-random number generator is a function F

such that for any number ω, there is a set of numbersZ1(ω), Z2(ω), ... that satisfy

Zi+1(ω) = F (Zi(ω))

Z0(ω) = ω is the seed

and the sequence of Zi(ω) satisfies certainconditions.

Copyright c©2009 Stanley B. Gershwin. 24

Page 25: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 25

Slide courtesy of Jérémie Gallien. Used with permission.

Page 26: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

• The sequence Zi(ω) is determined — deterministically — byZ0(ω) = ω.

• A small change in ω causes a large change in Zi(ω).

• Since the user can specify the seed, it is possible to re-run asimulation with the same sequence of random numbers. This issometimes useful for debugging, sensitivity analysis, etc.

• Often, the computer can choose the seed (for example, usingthe system clock). This guarantees that the same sequence isnot chosen.

Copyright c©2009 Stanley B. Gershwin. 26

Page 27: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 27

Slide courtesy of Jérémie Gallien. Used with permission.

Page 28: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 28

Slide courtesy of Jérémie Gallien. Used with permission.

Page 29: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 29

Slide courtesy of Jérémie Gallien. Used with permission.

Page 30: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 30

Slide courtesy of Jérémie Gallien. Used with permission.

Page 31: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Random numbers

Pseudo-random number generator

Copyright c©2009 Stanley B. Gershwin. 31

Slide courtesy of Jérémie Gallien. Used with permission.

Page 32: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

•The purpose of simulation is to get quantitativeperformance measures such as production rate,average inventory, etc.

•The data that comes from a simulation is statistical.Therefore, to get useful numerical results from asimulation,

⋆ there must be enough data; and⋆ the data must be obtained under stationary

conditions ... although there are sometimes exceptions.

Copyright c©2009 Stanley B. Gershwin. 32

Page 33: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Enough data:

• The data is treated like measurement data from the real world.Sample means, sample variances, confidence intervals, etc.must be calculated.

• The more times the simulation is run (ie, the greater thenumber of repetitions) the smaller the confidence intervals.

• The longer the simulation is run, the closer the results fromeach run are to one another, and consequently, the smaller theconfidence intervals.

• However, ...

Copyright c©2009 Stanley B. Gershwin. 33

Page 34: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Warmup:

•To evaluate average production rate, inventory, etc.,the system must be in steady state.

•But the simulation will start with the system in aknown state, so it will not be in steady stateimmediately.

•Some time is required to get the system in steadystate. This is the transient period. It depends on thecharacteristics of the system.

Copyright c©2009 Stanley B. Gershwin. 34

Page 35: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

•Therefore, we should not collect data starting at time0; we should start only after the system reachessteady state.

•The initial period before data is collected is thewarmup period.

•Required: warmup period ≥ transient period.

•Problem: it is very hard to determine the transientperiod.

Copyright c©2009 Stanley B. Gershwin. 35

Page 36: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Example:

• 20-machine line.

• ri = .1, pi = .02, i = 1, ..., 19; r20 = .1, p20 =

.025.

•Ni = 1000, i = 1, ..., 19.

•The simulation is run for 1,000,000 steps; data isaveraged over 10,000 steps.

Copyright c©2009 Stanley B. Gershwin. 36

Page 37: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Production rate

Initial transient

0.7

0.72

0.74

0.76

0.78

0.8

0.82

0.84

0 100000 200000 300000 400000 500000 600000 700000 800000 900000 1e+06

Production Rate

Copyright c©2009 Stanley B. Gershwin. 37

Page 38: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Buffer levels

0

100

200

300

400

500

600

700

800

900

1000

0 100000 200000 300000 400000 500000 600000 700000 800000 900000 1e+06

Buffer 1Buffer 10Buffer 19

Copyright c©2009 Stanley B. Gershwin. 38

Page 39: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Copyright 2003 © Jérémie Gallien

The Simulation Process1 Define the simulation goal

2 Model the system

4 Implement, debug and play

5 Sensitivity Analysis,Data collection, Validation

6 Design & run experiment

7 Analyze and communicate

• Never skip!

• Keep the goal in mind!• Customer feedback!

• Choice of tool is key• Sensitivity analysis

• Never skip• Customer feedback!

• Use confidence intervals +predictive accuracy!

• Run length, warm start, variance reduction…

3 Preliminary data collection • Rough estimates

Copyright c©2009 Stanley B. Gershwin.

Slide courtesy of Jérémie Gallien. Used with permission.

39

Page 40: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Typical Errors

• Start modeling before knowing what question you want to answer

• Constructing a model of the universe• Not enough feedback from person

knowledgeable with system• Collect data before knowing how your model

will use it• Report results without understanding where

they come from/their qualitative interpretation

Copyright 2003 © Jérémie Gallien

Slide courtesy of Jérémie Gallien. Used with permission.

Copyright c©2009 Stanley B. Gershwin. 40

Page 41: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

DynamicSimulation

Technical IssuesStatistics, Repetitions,Run Length, and Warmup

Copyright 2003 © Jérémie Gallien

System Modeling

• “Everything should be made as simple as possible, but not simpler.” Albert Einstein.

• The simulation goal should be the guiding light when deciding what to model

• Start to build your model ON PAPER!

• Get client/user feedback early, and maintain model + assumption sheet for communication purposes

• Collect data and fit distributions… after modeling the system, with sensitivity analysis in mind!

Copyright c©2009 Stanley B. Gershwin.

Slide courtesy of Jérémie Gallien. Used with permission.

41

Page 42: MIT 2.853/2.854 Manufacturing Systems...MIT OpenCourseWare  2.854 / 2.853 Introduction To Manufacturing Systems Fall 2016

MIT OpenCourseWarehttps://ocw.mit.edu

2.854 / 2.853 Introduction To Manufacturing SystemsFall 2016

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.