Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing a Discrete Event Simulation Tool Peter L. Jackson School of Operations Research and Industrial Engineering March 15, 2003 Cornell University.

Similar presentations


Presentation on theme: "Designing a Discrete Event Simulation Tool Peter L. Jackson School of Operations Research and Industrial Engineering March 15, 2003 Cornell University."— Presentation transcript:

1 Designing a Discrete Event Simulation Tool Peter L. Jackson School of Operations Research and Industrial Engineering March 15, 2003 Cornell University Applied Systems Engineering II

2 15 March 2003Peter L. JacksonSimDesign2 Orientation

3 15 March 2003Peter L. JacksonSimDesign3 Mission To develop a graphically-oriented discrete event simulation modeling tool for use in Applied Systems Engineering II

4 15 March 2003Peter L. JacksonSimDesign4 Requirements (Version 1.0) The tool shall be free, public domain The tool shall permit graphical description of simulation model The tool shall be extensible by students The tool shall exploit MS Excel 97+ interface The tool shall provide basic simulation services The tool shall be simple (minimal documentation required)

5 15 March 2003Peter L. JacksonSimDesign5 Functional Analysis Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output

6 15 March 2003Peter L. JacksonSimDesign6 Requirements The tool shall not require more than two weekends of development time The tool shall analyze a graph and construct the shell of a simulation model Students shall provide code for model components The tool shall run the model and store outputs (trace) Students shall analyze the trace

7 15 March 2003Peter L. JacksonSimDesign7 Derived Requirements Graphical model may not use text attributes on arcs (Excel 97 limitation) Graphical model must encode all node attributes in text string (to meet development time target) State variables for trace shall be defined by a range name Students must code updates to range elements

8 15 March 2003Peter L. JacksonSimDesign8 Issue What modeling approach to use? Functional flow block diagram Event graph Activity diagram Tradeoffs Resolution Event graph (mimic commercial software “Sigma” by Lee Schruben)

9 15 March 2003Peter L. JacksonSimDesign9 Essential Functions of Graphical Model Events Conditions Triggers Delays State transitions Event cancellation Initialization On node Arc On node On arc On node

10 15 March 2003Peter L. JacksonSimDesign10 Idea for Text String “?condition+delay=transition” Tokens ?,+,= identify components Condition is function name Delay is function name Transition is function name Students code functions in Visual Basic

11 15 March 2003Peter L. JacksonSimDesign11 Issues and Resolution How to represent event cancellation? Use dashed or dotted line type How to represent initial event? It is the only node that has no incoming arcs

12 15 March 2003Peter L. JacksonSimDesign12 Starting Spreadsheet: SimTemplate.xls Put your model on Sheet1 Check for diagnostics on sheet SimLog View output on sheet SimTrace Test/run your model

13 15 March 2003Peter L. JacksonSimDesign13 Sample Model Use any autoshapes and formatting that you want What matters: Text strings Arc connections and direction Arc type: solid or dashed

14 15 March 2003Peter L. JacksonSimDesign14 Analyze and Run Interaction First build the model and check for errors Debug: run one event at a time Switch to view different sheets (Model, Log, Trace) as desired Set simulation duration Run until done

15 15 March 2003Peter L. JacksonSimDesign15 Automated Model Interpretation: SimLog

16 15 March 2003Peter L. JacksonSimDesign16 Switch to Visual Basic Editor Development Code: Do not modify (all variables and objects beginning with “Sim” are reserved) User Code: Put your code here

17 15 March 2003Peter L. JacksonSimDesign17 You Write the Code: Declare Your State Variables 'Declare your variables here Global Queuelength As Integer Global ServerBusy As Integer Global CompletedCustomerCount As Long ‘Queuelength is the variable tracking the number of customers in the queue. 'global means it is available for use in other modules; 'ServerBusy will be true if the server is busy; false otherwise.

18 15 March 2003Peter L. JacksonSimDesign18 Write the Event Functions (to change the state) Function initialize() 'every simulation should have a function which initializes the state variables Queuelength = 0 'we start with an empty queue ServerBusy = False 'we start with an idle server CompletedCustomerCount = 0 End Function Function arrival() 'this represents the arrival of a customer Queuelength = Queuelength + 1 End Function Function beginservice() 'this function represents the start of service by a server. ServerBusy = True End Function Function endservice() 'this function represents the end of service by a server; the customer leaves at this point Queuelength = Queuelength - 1 'we count the customer as being in the queue until the end of service ServerBusy = False CompletedCustomerCount = CompletedCustomerCount + 1 End Function

19 15 March 2003Peter L. JacksonSimDesign19 Write the Condition Functions: to Test the State Function isidle() As Integer 'Functions that return a true/false value must be declared as integer isidle = Not ServerBusy 'ServerBusy is either true/false so Not ServerBusy is either false/true. End Function Function isqueue() As Integer If Queuelength > 0 Then isqueue = True Else isqueue = False 'this illustrates the if...then...else statement End Function

20 15 March 2003Peter L. JacksonSimDesign20 Write the Code to Generate Delays and Durations Function interarrivaltime() As Variant 'this function returns a random interarrival time; functions that return a value for time should use the variant data type Dim duration As Variant 'local variable declaration; duration will be the length of the interarrival time duration = 5 + Rnd() * 3 'duration will be a random number between 5 and 8. interarrivaltime = duration 'this is how you return a value End Function Function servicetime() As Variant servicetime = 4 + Rnd() * 3 'servicetime will be a random number between 4 and 7 End Function

21 15 March 2003Peter L. JacksonSimDesign21 Debug: Step Through Model

22 15 March 2003Peter L. JacksonSimDesign22 How a Discrete Event Simulation Works Scheduled Events Sorted in Increasing Order of Scheduled Time Time: Event: 4.0 EndService 4.3 Arrival … later times … other events Remove Next Scheduled Event Advance Simulation Clock Execute State Change Function If Condition Satisfied… Generate Next Event(s) with later time(s) Insert Event into Schedule Current Time: 3.3 Current Time: 4.0

23 15 March 2003Peter L. JacksonSimDesign23 Common Modeling Problem: What Happens First? Simulated robots playing soccer Given current velocities, what happens first: Two robots collide? One robot hits wall? One robot intercepts ball? Etc. Need to compute the time of all these events and select the minimum as the next event that really happens Or…

24 15 March 2003Peter L. JacksonSimDesign24 Canceling Events Schedule all possible event types: Two robots collide One robot hits wall Etc. Let the simulation determine which happens first When any of these event types happens, cancel all other pending events of related type

25 15 March 2003Peter L. JacksonSimDesign25 Example: Random Server Breakdowns

26 15 March 2003Peter L. JacksonSimDesign26 Automated Model Interpretation

27 15 March 2003Peter L. JacksonSimDesign27 More Code To Write Function Breakdown() 'no change in state; ServerBusy stays true End Function Function TimeToFail() As Variant 'this function returns a random time to fail Dim duration As Variant 'local variable declaration; duration will be the length of the time to fail duration = 5 + Rnd() * 3 'duration will be a random number between 5 and 8. TimeToFail = duration 'this is how you return a value End Function Function RepairAndServiceTime() As Variant 'this function returns a random time to repair and complete service Dim duration As Variant duration = 10 + Rnd() * 3 'duration will be a random number between 10 and 13. RepairAndServiceTime = duration 'this is how you return a value End Function

28 15 March 2003Peter L. JacksonSimDesign28 Define Ranges to Store Variables

29 15 March 2003Peter L. JacksonSimDesign29 Write Code to Store Variables Function OutputVariables() Worksheets("Sheet1").Range("Queue_Length").Value = Queuelength Worksheets("Sheet1").Range("Completions").Value = CompletedCustomerCount End Function Your range names Your state variables

30 15 March 2003Peter L. JacksonSimDesign30 Modify Code to Store Variables After Each Event

31 15 March 2003Peter L. JacksonSimDesign31 Input/Output You really need to store only the variables that have changed Code could be made more efficient If you want to read input data from the 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.

32 15 March 2003Peter L. JacksonSimDesign32 Creating a Trace A trace is a history of your state variables after each event The simulator automatically writes out whatever 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. You must define these two ranges.

33 15 March 2003Peter L. JacksonSimDesign33 Define Trace and Label Ranges

34 15 March 2003Peter L. JacksonSimDesign34 What a Trace Looks Like Two rows for each event: begin and end. Second row captures time spent in state (“Elapsed time”)

35 15 March 2003Peter L. JacksonSimDesign35 X-Y Scatter Plot Delete the plot to make the simulation run faster: you can add it again later

36 15 March 2003Peter L. JacksonSimDesign36 Statistics Computed After Each Run Statistics inserted into first four lines of trace output. Four statistics computed (Min, Max, Mean, Std. Dev.) even if they don’t make sense for your particular state variables

37 15 March 2003Peter L. JacksonSimDesign37 Project Completed Build Graphical Model Code Components Debug Model Run Model, Collect Output Analyze Output

38


Download ppt "Designing a Discrete Event Simulation Tool Peter L. Jackson School of Operations Research and Industrial Engineering March 15, 2003 Cornell University."

Similar presentations


Ads by Google