DiscreteEventSimulation 4xgs - Two Useful Modeling...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Two Useful Modeling Approaches Functional Modeling g Behavioral Modeling g Initialize Discrete Event Simulation Peter L. Jackson Professor School of O.R. and I.E. 2/14/2011 CookiesInQueue Arrival InterarrivalTime OvenIsEmpty Start OvenCycleTime Finish Industrial Data and Systems Analysis 1 2/14/2011 Industrial Data and Systems Analysis 2 Key Lessons (Preview) Discrete event simulation is a highly Overview Motivation: The Cookie Problem A Model of Behavior: Discrete Event flexible method of describing the behavior of a system Basic simulation services can be implemented in MS Excel, but require user coding in VBA Simulation Th structure of a simulation model can The t t f i l ti d l be described with an event graph B ildi Building, running, and analyzing a i d l i simulation model is a structured process 2/14/2011 A Graphical Language Programming a Simulation in MS Excel 3 2/14/2011 Industrial Data and Systems Analysis Industrial Data and Systems Analysis 4 Before You Buy a Simulation Package P k See how you would use it to model The Cookie Problem Trays of c.c. y arrive every 13.5 minutes on average Oven cycle is 13.5 minutes but cannot be interrupted Maximum throughput is 2 trays every 13 5 13.5 minutes the following situation: An oven takes 13.5 minutes to bake cookies. The oven can hold h ld up to t t two trays of cookies. Th number of t t f ki The b f trays i th in the oven does not affect baking time. The trays can be of different types of cookies but you cannot open the door g ,y p y while the cookies are baking. That is, you can put trays into the oven only after the current oven cycle has ended. Trays of chocolate chip cookies arrive every tc minutes. Trays of peanut butter cookies arrive every tp minutes. What is the average number of trays of peanut butter cookies waiting to be cooked, assuming tc is uniformly distributed over [9,18] and tp is uniformly distributed over [12,16]? 2/14/2011 Queues of trays can build up due to randomness of arrivals Trays of p.b. arrive every 14 minutes on average 5 2/14/2011 Oven capacity is two trays (can be of mixed type) Industrial Data and Systems Analysis 6 Industrial Data and Systems Analysis Questions Maximum throughput is 2 trays/13.5 min. Questions (continued) If arrivals are random (uniformly ( y What will be the average throughput ? Easy, determined by average arrival rate distributed), what will be the average number of trays in queue? C Cannot t ll using analytical methods t tell, i l ti l th d Must simulate Answer depends on scheduling rule "Always fill oven" or "cook on arrival" If there is no randomness, what will b th th i d h t ill be the maximum number of trays in queue? If arrivals are random, what will be the Answer depends on priority rule Ex. "Minimize the c.c. queue x. Minimi e queue" average number of p.b. trays in queue? b f b t i ? 2/14/2011 Industrial Data and Systems Analysis 7 2/14/2011 Industrial Data and Systems Analysis 8 Discrete Event Simulation The system is described by a state The state changes only at discrete points in time, called events , The interval between events is called a delay, or duration. The delay could be y y The Cookie Problem What is the state of the system? At what points in time (events) does the random Events can trigger other events depending on conditions that depend on the state 2/14/2011 state change? What are the delays? What events could trigger other events? What are the conditions under which events are triggered? Industrial Data and Systems Analysis 9 2/14/2011 Industrial Data and Systems Analysis 10 The Power of Discrete Event Simulation Si l ti Can model extremely complex behavior Keep It Simple Two models of semiconductor fab One focused on wafer-level simulation Kept track of each tray of wafers with simple language of "states", "events", "delays", "conditions", and "triggers" Can jump in time from one event to another Nothing `interesting' happens between events: One focused on machine cycles Counted wafers no change in state Rapidly simulate days/weeks/years of real-time activity S Same question asked of b th models ti k d f both d l Is there enough capacity to meet demand? If state is simple (eg. inventory counts) then Same answer from both models But one model (wafer counter) ran 10,000 X processing time and memory required are very small Industrial Data and Systems Analysis faster 2/14/2011 11 2/14/2011 Industrial Data and Systems Analysis 12 Overview Motivation: The Cookie Problem A Model of Behavior: Discrete Event Simulation A Graphical Language Programming a Simulation in MS Excel 2/14/2011 How a Discrete Event Simulation Works W k At any point in time there is an ordered list of events scheduled to occur in the future (the event queue) The state of the system is described by state variables The simulation engine removes the first event from the event queue and advances the simulation clock to the time recorded on that event The function associated with that event is called The simulation engine checks to see if any trigger conditions are satisfied The function may change the values of the state variables The simulation continues until there are no more events in the q , p event queue, or until a simulation stop time is reached Industrial Data and Systems Analysis If a trigger condition is satisfied, the simulation engine creates a new event for each trigger The scheduled time for the new event is the current simulation clock time plus any delay associated with the trigger The new event is inserted into the event queue in order of the event time Industrial Data and Systems Analysis 13 2/14/2011 14 How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time Time: 4 0 4.0 Event: EndService 4.3 43 Arrival ... l t times later ti ... other events Time: 4 0 4.0 Event: EndService 4.3 43 Arrival Current Time: 3.3 C t Ti 33 Remove N t R Next Scheduled Event 2/14/2011 Current Time: 3.3 C t Ti 33 Industrial Data and Systems Analysis 15 2/14/2011 Industrial Data and Systems Analysis 16 How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time 4.3 43 Arrival Current Time: 3.3 C t Ti 33 Current Time: 4.0 Time: 4.0 Event: EndService 2/14/2011 4.3 43 Arrival Current Time: 4.0 C t Ti 40 Execute State E t St t Change Function 18 Advance Ad Simulation Clock Industrial Data and Systems Analysis 17 Time: 4.0 Event: EndService 2/14/2011 Industrial Data and Systems Analysis How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time 4.3 43 Arrival Current Time: 4.0 C t Ti 40 4.3 43 Arrival Current Time: 4.0 C t Ti 40 Generate Next N t Event(s) with later time(s) 20 Time: 4.0 Event: EndService 2/14/2011 If Condition Satisfied... Time: 4.0 Event: EndService 19 2/14/2011 If Condition Satisfied... Industrial Data and Systems Analysis Industrial Data and Systems Analysis How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time 4.3 43 Arrival Current Time: 4.0 C t Ti 40 Insert Event into Schedule 4.3 43 Arrival Current Time: 4.0 C t Ti 40 Insert Event into Schedule 2/14/2011 Industrial Data and Systems Analysis 21 2/14/2011 Industrial Data and Systems Analysis 22 How a Discrete Event Simulation W k Si l ti Works Scheduled Events Sorted in Increasing Order of Scheduled Time How a Discrete Event Simulation W k Summary Si l ti Works: S Scheduled Events Sorted in Increasing Order of Scheduled Time 4.3 43 Arrival Current Time: 4.0 C t Ti 40 Remove N t R Next Scheduled Event 2/14/2011 Time: 4 0 4.0 Event: EndService 4.3 43 Arrival ... l t times later ti ... other events Insert Event into Schedule Current Time: 3.3 C t Ti 33 Current Time: 4.0 Remove N t R Next Scheduled Event Advance Ad Simulation Clock Execute State E t St t Change Function If Condition Satisfied... Generate Next N t Event(s) with later time(s) 24 Industrial Data and Systems Analysis 23 2/14/2011 Industrial Data and Systems Analysis A Model of Behavior: Events Change th St t of th S t Ch the State f the System A Model of Behavior: Events T i E t Trigger Oth E Other Events t State of System Change Events State of System Change Events Check Trigger Based on current Conditions If true, Add Triggers Based on current Time Delays After delay, fire 2/14/2011 Industrial Data and Systems Analysis 25 2/14/2011 Industrial Data and Systems Analysis 26 A Model of Behavior: Has B i i H a Beginning and an End d E d Initializes A Model of Behavior: Uses Event-Specific Data U E tS ifi D t Initializes First Event Fi t E e t Fires First Event Fi t E e t Fires State of System Change Events Check Trigger State of System Change Events Check Make current Belong to Trigger Pass to new events Based on current Conditions If true, Add Triggers If not exceeded, trigger events Based on current Conditions Based on current Event Data Is type of Triggers If true, Add Time of Occurrence Based on current If not exceeded, trigger events Based on current Time Delays After delay, fire Time Limit Time Delays Based on current Time Limit After delay, fire 2/14/2011 Industrial Data and Systems Analysis 27 2/14/2011 Industrial Data and Systems Analysis 28 A Model of Behavior: Computes Statistics St ti ti Initializes A Model of Behavior: Discrete Event Si l ti E t Simulation Initializes First Event Fi t E e t Fires First Event Fi t E e t Fires Trace Records Records Change Summarize Statistics Map to Technical Performance Measures State of System Trace Records Records Change Summarize Statistics Map to Technical Performance Measures State of System Events Check Make current Events Check Belong to Make current Trigger Pass to new events Belong to Trigger Pass to new events Based on current Conditions Based on current Event Data Is type of Triggers Based on current Conditions Based on current Event Data Is type of Triggers If true, Add Time of Occurrence Based on current If not exceeded, trigger events Based on current If true, Add Time of Occurrence Time Delays Based on current If not exceeded, trigger events Time Delays Based on current Time Limit Time Limit After delay, fire After delay, fire 2/14/2011 Industrial Data and Systems Analysis 29 2/14/2011 Industrial Data and Systems Analysis 30 The Simplified Cookie Problem Trays of cookies arrive every 13.75 minutes on average Time between arrivals uniformly distributed in [10.5,17] Oven cycle is 25 minutes but cannot be interrupted Maximum throughput is 2 trays every 25 minutes Modeling State of the system Q = number of trays in queue (0,1, 2,...) P = number of trays in oven (0,1, or 2) y ( ) Events that change system A queue of t f trays can build up due to randomness of arrivals Oven capacity is two trays Arrival (Q increases) Start (Q decreases, P increases) Finish (P decreases) Initialize (set P and Q to initial values) 2/14/2011 Industrial Data and Systems Analysis 31 2/14/2011 Industrial Data and Systems Analysis 32 Modeling Triggers and Delays Start triggers Finish with delay of 25 Modeling Conditional Triggers Arrival triggers Start if P=0 P 0 Call this condition OvenIsEmpty OvenIsEmpty = if(P=0,true,false) py ( ) minutes Call this OvenCycleTime OvenCycleTime = 25 Arrival triggers Arrival with delay of 13.75 minutes, on average Finish triggers Start if Q>0 Call this condition CookiesInQueue CookiesInQueue = if (Q>0,true,false) Call this InterarrivalTime InterarrivalTime =10.5 + Rnd()*(17-10.5) * Rnd() is pseudo-random number in (0,1) 2/14/2011 Industrial Data and Systems Analysis 33 2/14/2011 Industrial Data and Systems Analysis 34 Modeling State Changes Arrival: Q = Q+1 Q 1 Finish: P = 0 Start: if Q > 2 then P = 2, else P = Q; Q = Q2 Overview Motivation: The Cookie Problem A Model of Behavior: Discrete Event P Simulation Note that Start does not get triggered unless g gg Q is at least 1 Initialize: Q=0,P=0 A Graphical Language Programming a Simulation in MS Excel 2/14/2011 Industrial Data and Systems Analysis 35 2/14/2011 Industrial Data and Systems Analysis 36 Let's Invent a Graphical Language Similar to Schruben's Event Graph Schruben s The Simplified Cookie Model Initialize language Supportable by MS Excel drawing tools pp y g IsNextQueueIdle Condition NextQueue ToConsider Switch Arrival InterarrivalTime OvenIsEmpty BeginService Event Start EndService Event ServiceTime Delay CookiesInQueue Finish OvenCycleTime 2/14/2011 Industrial Data and Systems Analysis 37 2/14/2011 Industrial Data and Systems Analysis 38 The Simplified Cookie Model (Complete) (C l t ) Q=0; P=0 Initialize Graph Rules There must be one event node that has no Q=Q+1 Arrival InterarrivalTime =10.5+rnd()*(6.5) =10 5+rnd()*(6 5) OvenIsEmpty =if(P=0,true,false) If Q>2 then P=2, else P=Q; Q=Q-P OvenCycleTime incoming arcs (triggers): this is the first event Nodes must be connected (use MS Excel connectors) t ) Condition nodes trigger all outgoing arcs, if condition is true There are no "yes/no" branches in this language You will need two condition nodes to model a branching Start CookiesInQueue =if(Q>0,true,false) Finish process (one for the "yes" and one for the "no") yes no ) =25 P=0 39 Events can be triggered only by other events, through condition nodes and delay nodes 2/14/2011 2/14/2011 Industrial Data and Systems Analysis Industrial Data and Systems Analysis 40 Homework This week: Create an MS Excel style event Overview Motivation: The Cookie Problem A Model of Behavior: Discrete Event graph to model the general cookie problem Keep track of number of trays of peanut butter cookies and number of trays of chocolate chip cookies Simulation Next week: program and run the A Graphical Language Programming a Simulation in MS Excel 41 2/14/2011 simulation model We will post a solution to this week's problem in time for you to write a program next week Industrial Data and Systems Analysis 2/14/2011 Industrial Data and Systems Analysis 42 Programming the Simulation Model M d l Use Visual Basic for Applications (VBA) in A Structured Process (IDEF0) Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output MS Excel Use simulation template file to start "SimplifiedCookie2010.xls" p Contains code to analyze graph and run simulation Simplified model is already coded 2/14/2011 Industrial Data and Systems Analysis 43 2/14/2011 Industrial Data and Systems Analysis 44 Model in MS Excel Use Tokens in Text Strings Template code ignores shape Use tokens to indicate type of node = for events + for delays ? for conditions 2/14/2011 Industrial Data and Systems Analysis 45 2/14/2011 Industrial Data and Systems Analysis 46 Model With Tokens Analyze and Run Dialog First Fi t build the model and check for errors Switch to view different sheets (Model, Log, Trace) as desired Debug: run one event at a ti time Set simulation duration Run until done d 48 2/14/2011 Industrial Data and Systems Analysis 47 2/14/2011 Industrial Data and Systems Analysis English Interpretation on Sheet "SimLog" Sh t "Si L " A Structured Process Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output 2/14/2011 Industrial Data and Systems Analysis 49 2/14/2011 Industrial Data and Systems Analysis 50 Switch to Visual Basic Editor (<Alt><F11>) ( Alt F11 ) You Write the Code: Declare Your State Variables 'Declare your variables here Declare Global Q As Integer Global P As Integer Global CumulativeCompletions As Integer Global means it is available for use in other modules. Q is the variable tracking the number of trays in the queue. P i the number of trays i the oven. is h b f in h CumulativeCompletions is a statistic we want to compute; it is not essential to the model. model 2/14/2011 Development Code: Do not modify (all variables and objects beginning with "Sim" are reserved) User Code: Put your code h U C d P t d here. Add more modules if you like 2/14/2011 Industrial Data and Systems Analysis 51 Industrial Data and Systems Analysis 52 Write the Event Functions (to change th state) h the t t ) Function Initialize() ''every simulation should have a function i l i h ld h f i which initializes the state variables Q=0 P=0 CumulativeCompletions = 0 C l i C l i End Function Function Arrival() 'this 'thi represents the arrival of a tray of cookies t th i l f t f ki Q=Q+1 End Function Write the Condition Functions: to Test the State t T t th St t Function CookiesInQueue() As Integer 'this illustrates the if...then...else statement If Q > 0 Then CookiesInQueue = True Else CookiesInQueue = False End Function Function Start() 'this function represents the start of the oven cycle If Q > 2 Then P = 2 Else P = Q Q=Q-P End Function Function Finish() 'this function represents the end of the oven cycle CumulativeCompletions = CumulativeCompletions + P P=0 End Function Function OvenIsEmpty() As Integer If P = 0 Then OvenIsEmpty = True Else OvenIsEmpty = False End F E d Function i Condition functions must return C diti f ti t t an integer: True = -1; False = 0 2/14/2011 2/14/2011 Industrial Data and Systems Analysis 53 Industrial Data and Systems Analysis 54 Write the Code to Generate Delays and D D l d Durations ti Function OvenCycleTime() As Variant y () 'functions that return a value for time should use the Variant data type OvenCycleTime = 25 End Function Function InterarrivalTime() As Variant 'this function returns a random interarrival time Dim duration As Variant 'local variable declaration; duration will be the length of the interarrival time duration = 10.5 + Rnd() * 6.5 'duration will be a random number uniformly distributed between 10.5 and 17. InterarrivalTime = duration 'this is how you return a value this End Function A Structured Process Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output 2/14/2011 Industrial Data and Systems Analysis 55 2/14/2011 Industrial Data and Systems Analysis 56 Debug: Step Through Model =Initialize Define Ranges to Store Variables V i bl +InterarrivalTime =Initialize =Arrival +InterarrivalTime =Arrival ?OvenIsEmpty =Initialize ?OvenIsEmpty =Start =Arrival +InterarrivalTime ?CookiesInQueue +OvenCycleTime ?OvenIsEmpty =Start ?CookiesInQueue =Finish =Start S +OvenCycleTime =Finish +OvenCycleTime ?CookiesInQueue =Finish 2/14/2011 Industrial Data and Systems Analysis 57 2/14/2011 Industrial Data and Systems Analysis 58 Write Code to Store Variables Function O F i OutputVariables() V i bl () Worksheets("Sheet1").Range("Number_of_Trays_in_Queue").Value = Q Worksheets("Sheet1").Range("Number_of_Trays_in_Oven").Value = P ( ) g ( y ) Worksheets("Sheet1").Range("Cumulative_Completions").Value = CumulativeCompletions End Function Modify Code to Store Variables Aft Each Event V i bl After E h E t Function Initialize() 'every simulation should have a function which initializes the state variables Q=0 P=0 CumulativeCompletions = 0 OutputVariables End Function Function Arrival() 'this represents the arrival of a tray of cookies Q=Q+1 OutputVariables End Function Function Start() 'this function represents the start of the oven cycle If Q > 2 Then P = 2 Else P = Q Q=Q-P OutputVariables End Function Function Finish() 'this function represents the end of the oven cycle CumulativeCompletions = CumulativeCompletions + P C l ti C l ti C l ti C l ti P=0 OutputVariables 2/14/2011 End Function Industrial Data and Your state variables Your range names 2/14/2011 Industrial Data and Systems Analysis 59 Systems Analysis 60 Input/Output If you want to read input data from the First Event spreadsheet (eg. Initial parameter settings), use ranges in a similar way. Now, single step through your simulation watching your variables change with each event. The more variables you track, the easier it will be to debug your model model. 2/14/2011 Industrial Data and Systems Analysis 61 2/14/2011 Industrial Data and Systems Analysis 62 Second Event Third Event 2/14/2011 Industrial Data and Systems Analysis 63 2/14/2011 Industrial Data and Systems Analysis 64 Fourth Event Fifth Event 2/14/2011 Industrial Data and Systems Analysis 65 2/14/2011 Industrial Data and Systems Analysis 66 A Structured Process Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output Creating a Trace A trace is a history of your state variables after each event h t The simulator automatically writes out whatever y is in the range called "SimTraceRange" before and after each event Stored on separate lines of sheet "SimTrace" It also writes out the labels found in the range called "SimTraceLabelRange" at the head of this list. list You must define these two ranges. 67 2/14/2011 2/14/2011 Industrial Data and Systems Analysis Industrial Data and Systems Analysis 68 Define Trace and Label Ranges What a Trace Looks Like Two rows for each event: begin and end. Second row captures time spent in state ti ti t t ("Elapsed time") 2/14/2011 Industrial Data and Systems Analysis 69 2/14/2011 Industrial Data and Systems Analysis 70 A Structured Process Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output XY X-Y Scatter Plot 3.5 35 3 2.5 2 Series2 1.5 1 0.5 0 0 500 1000 1500 2000 2500 3000 3500 4000 4500 2/14/2011 Industrial Data and Systems Analysis 71 2/14/2011 Industrial Data and Systems Analysis 72 Statistics Computed After Each Run Statistics inserted into first four lines of trace One Problem If you copy and paste a node or a output. Four statistics computed (Min, Max, Mean, Std. Dev.) D ) even if th d 't make sense f your they don't k for particular state variables connector, MS Excel does not give it a new name. Since my code uses the name of the autoshape to identify it, my code gets confused. Be sure to create each node from the shapes menu fresh, to make sure i h a h f h k it has unique name. 73 2/14/2011 2/14/2011 Industrial Data and Systems Analysis Industrial Data and Systems Analysis 74 Process Complete Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output Overview Motivation: The Cookie Problem A Model of Behavior: Discrete Event Simulation A Graphical Language Programming a Simulation in MS Excel 75 2/14/2011 2/14/2011 Industrial Data and Systems Analysis Industrial Data and Systems Analysis 76 Key Lessons Discrete event simulation is a highly A Model of Behavior: Discrete Event Si l ti E t Simulation Initializes flexible method of describing the behavior of a system Basic simulation services can be implemented First Event Fi t E e t Fires Trace Records Records Change Summarize Statistics Map to Technical Performance Measures in MS Excel, but require user coding in VBA State of System Events Check Make current Th structure of a simulation model can The t t f i l ti d l Belong to Trigger Pass to new events Based on current Conditions Based on current be described with an event graph B ildi Building, running, and analyzing a i d l i simulation model is a structured process 2/14/2011 Event Data Is type of Triggers If true, Add Time of Occurrence Based on current If not exceeded, trigger events Time Delays Based on current Time Limit After delay, fire Industrial Data and Systems Analysis 77 2/14/2011 Industrial Data and Systems Analysis 78 ...
View Full Document

This note was uploaded on 03/18/2012 for the course ORIE 3120 taught by Professor Jackson during the Spring '09 term at Cornell University (Engineering School).

Ask a homework question - tutors are online