24
General Simulation Principles Christos Alexopoulos and Dave Goldsman Georgia Institute of Technology, Atlanta, GA, USA 5/27/18 1 / 24

General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

General Simulation Principles

Christos Alexopoulos and Dave Goldsman

Georgia Institute of Technology, Atlanta, GA, USA

5/27/18

1 / 24

Page 2: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Outline

1 Steps in a Simulation Study

2 Some Definitions

3 Time-Advance Mechanisms

4 Two Modeling Approaches

5 Simulation Languages

2 / 24

Page 3: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Steps in a Simulation Study

Steps in a Simulation Study

(i) Problem Formulation — statement of problem.

Profits are too low. What to do?

Customers are complaining about the long lines. Help!

(ii) Objectives and Planning — what specific questions should beanswered?

How many workers to hire?

How much buffer space to insert in the assembly line?

(iii) Model Building — both an art and science.

M/M/k queueing model?

Need physics equations?

3 / 24

Page 4: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Steps in a Simulation Study

(iv) Data Collection — what kinds of data, how much?

Continuous? Discrete?

What exactly should be collected?

Budget considerations.

(v) Coding — decide on language, write program.

Modeling paradigm — Event-Scheduling or Process-Interaction?

100s of languages out there.

(vi) Verification — is the code OK? If not, go back to (v).

(vii) Validation — is the model OK? If not, go to (iii) and (iv).

4 / 24

Page 5: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Steps in a Simulation Study

(viii) Experimental Design — what experiments need to be run toefficiently answer our questions?

Statistical considerations

Time / budget

(ix) Run Experiments — press the “go” button and make yourproduction runs, often substantial. May require a lot of time.

(x) Output Analysis — statistical analysis, estimate relevantmeasures of performance.

Often iterative with (viii) and (ix).

Almost always need more runs.

(xi) Write Reports, Implement, and Make Management Happy.

5 / 24

Page 6: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Some Definitions

Outline

1 Steps in a Simulation Study

2 Some Definitions

3 Time-Advance Mechanisms

4 Two Modeling Approaches

5 Simulation Languages

6 / 24

Page 7: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Some Definitions

A system is a collection of entities (people, machines, etc.) thatinteract together to accomplish a goal.

A model is an abstract representation of a system, usuallycontaining math/logical relationships describing the system interms of states, entities, sets, events, etc.

System state: A set of variables that contains enough informationto describe the system. Think of the state as a system “snapshot.”

E.g., in a single-server queue, all you might need to describe thestate are: LQ(t) = number of people in queue at time t, andB(t) = 1 [0] if server is busy [idle] at time t.

Entities can be permanent (e.g., a machine) or temporary (e.g.,customers), and can have various properties or attributes (e.g.,priority of a customer or average speed of a server).

7 / 24

Page 8: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Some Definitions

A list (or queue) is an ordered list of associated entities (e.g., alinked list, or a line of people).

An event is a point in time at which the system state changes(and which can’t be predicted with certainty beforehand). E.g.,an arrival event, a departure event, a machine breakdown event.“Event” technically means the time that the thing happens, butloosely refers to “what” happens (e.g., an arrival).

An activity is a duration of time of specified length (aka anunconditional wait). E.g., an exponential customer interarrivaltime or a constant service time (since we can explicitly generatethose).

A conditional wait is a duration of time of unspecified length.E.g., a customer waiting time — we don’t know that directly (wejust know arrival and service times).

8 / 24

Page 9: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

Outline

1 Steps in a Simulation Study

2 Some Definitions

3 Time-Advance Mechanisms

4 Two Modeling Approaches

5 Simulation Languages

9 / 24

Page 10: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

The simulation clock is a variable whose value representssimulated time (which doesn’t equal real time).

Time-Advance Mechanisms — how does the clock move?

Always moves forward (never goes back in time). Two ways:Fixed-Increment Time Advance: Update the state of the system atfixed times, nh, n = 0, 1, 2, . . ., where h is chosen appropriately.This is used in continuous-time models (e.g., differentialequations) and models where data are only available at fixedtimes (e.g., at the end of every month). Not really emphasized inthis course!Next-Event Time Advance: The simulation clock is initialized at0. Times of all known future events are determined and placed inthe future events list (FEL), ordered by time. The clock advancesto the most imminent event, then to the next most imminent event,etc. At each event, the system state is updated, and the FEL isupdated.

10 / 24

Page 11: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

Notes on FELs:

The system state can only change at event times. Nothing reallyhappens between events.

The simulation progresses by sequentially executing (dealingwith) the most imminent event on the FEL.What do we mean by “dealing with”?

The clock advances to the most imminent event.The system state is updated, depending on what type of event it is(arrival, departure, etc.). For example, if it’s an arrival event, youmay have to turn on an idle server, or add a new customer to thequeue of a busy server.Update the FEL.

11 / 24

Page 12: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

What do we mean by “Update the FEL”? Any time there’s anevent, the simulation may update the chronological order of theFEL’s events by inserting new events, deleting events, movingthem around, or doing nothing.

Example: After guy arrives at a queue, typical simulationprograms will immediately spawn the next arrival time. If thisarrival time is significantly far enough in the future, we’ll simplyput it at the “end” of the FEL (in terms of ordered execution timesof the events).If that next arrival turns out to happen before another event, e.g., aslow server finishing his current customer, then that next arrivalhas to be inserted in the interior of the FEL (in terms of orderedexecution times).What if the arrival is a nasty-looking guy, and a number ofcustomers currently in line get disgusted and leave or switch toother lines? Then you have to delete or move entries in the FEL.

12 / 24

Page 13: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

Need efficient list processing (e.g., linked lists) for the FEL.Singly and doubly linked lists intelligently store the events in anarray that allows the chronological order of the events to beaccessed.Such lists easily accommodate insertion, deletion, switching ofevents, etc.Take a Computer Science course to learn more.

Be careful about events that take place (or are scheduled to takeplace) at the same time, e.g., a guy shows up at the same timethat another guy finishes getting served. It is important toestablish ground rules for how to deal with ties.Every discrete-event simulation language maintains a FELsomewhere deep in its heart.Good news: Most commercial simulation packages take care ofthe FEL stuff for you, so you don’t have to mess around at allwith FEL logic. It’s completely transparent!

13 / 24

Page 14: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

Next-Event Time Advance Example (adapted from BCNN): Considerthe usual single-server FIFO queue that will process exactly 10customers. The arrival times and service times are:

customer 1 2 3 4 5 6 7 8 9 10

arrival time 1 3 4 10 17 18 19 20 27 29

service time 5 4 1 3 2 1 4 7 3 1

Let’s construct a table containing entries for event time, system state,queue, future events list, and cumulative statistics (cumulative serverbusy time and customer time in system).

Let A denote an arrival event and D a departure (e.g., 2A is thecustomer 2 arrival). Suppose that services have priorities over arrivalsin terms of updating the FEL; so we’ll break ties by handling a servicecompletion first — get those guys out of the system!

14 / 24

Page 15: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Time-Advance Mechanisms

Next-Event Time Advance Example (cont’d):

Cumul StatsClock System State Queue FEL busy time in

t LQ(t) B(t) (cust, arr time) (event time, event type) time sys

0 0 0 ∅ (1, 1A) 0 01 0 1 ∅ (3, 2A), (6, 1D) 0 03 1 1 (2, 3) (4, 3A), (6, 1D) 2 24 2 1 (2, 3), (3, 4) (6, 1D), (10, 4A) 3 46 1 1 (3, 4) (10, 2D), (10, 4A) 5 1010 0 1 ∅ (10, 4A), (11, 3D) 9 18...

Tedious as this may appear, the computer handles all of this stuff in aflash. 2

15 / 24

Page 16: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Outline

1 Steps in a Simulation Study

2 Some Definitions

3 Time-Advance Mechanisms

4 Two Modeling Approaches

5 Simulation Languages

16 / 24

Page 17: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

I hinted in the last section that commercial discrete-event simulationpackages help you avoid a lot of grief by automatically handling theFEL and carrying out the drudgery themselves. How is that possible?

It comes down to a choice between two modeling “world views” —the event-scheduling approach (/) vs. the process-interactionapproach (,).

Event-Scheduling Approach. Concentrate on the events and how theyaffect the system state. Help the simulation evolve over time bykeeping track of every event in increasing order of time of occurrence.This is a bookkeeping hassle.

You might use this approach if you were programming in C++ orPython from scratch. If you think that you’d like to do so, see the nextfew pages outlining a generic simulation program. . .

17 / 24

Page 18: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Generic Simulation Program Flowchart (from Law’s book).

Main Program0. Initialization Routine

Set clock to 0Initialize system state and statistical countersInitialize FEL

1. Invoke Timing Routine — what/when is the next event?Determine next event type — arrival, departure, end simulationeventAdvance clock to next time

2. Invoke Event Routine — for event type iUpdate system stateUpdate statistical countersMake any necessary changes to FEL. E.g., if you have an arrival,schedule the next arrival or maybe schedule end of simulationevent. If simulation is now over, write report and stop. Ifsimulation isn’t over, go back to the Timing Routine.

3. Go back to 118 / 24

Page 19: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Details on Arrival EventSchedule next arrivalIs server busy?

If not busy,Set delay (wait) for that customer = 0Gather appropriate statistics (e.g., in order to ultimately calculateaverage customer waiting times)Add one to the number of customers processedMake server busyReturn to main program

If busy,Add one to number in queue.If queue is full, panic (or do something about it)If queue isn’t full, store customer arrival timeReturn to main program

19 / 24

Page 20: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Details on Depature EventIs the queue empty?

If empty,Make server idleEliminate departure event from consideration of being the nexteventReturn to main program

If not empty,Subtract one from number in queueCompute delay of customer entering service and gather statisticsAdd one to the number of customers delayed (processed)Schedule departure for this customerMove each remaining customer up in the queueReturn to main program

20 / 24

Page 21: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Putting together and coding the previous three charts (and how theyinteract with each other) gives us a nice but tedious event-schedulingsolution. But this is really quite a mess!

Luckily, to accomplish this in a process-interaction language (likeArena), all you have to do is:

Create customers every once in a while

Process (serve) them, maybe after waiting in line

Dispose of the customers after they’re done being processed

This is soooo easy. . .

21 / 24

Page 22: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Two Modeling Approaches

Process-Interaction Approach. We use this approach in class.Concentrate on a generic customer (entity) and the sequence of eventsand activities it undergoes as it progresses through the system. At anytime, the system may have many customers interacting with eachother as they compete for resources. You do the generic customermodeling in this approach, but you don’t deal with the eventbookkeeping — the simulation language handles the event schedulingdeep inside for all of the generic customers. Saves lots ofprogramming effort.

Example: A customer is generated, eventually gets served, and thenleaves. CREATE-PROCESS-DISPOSE. Easy, Easy, Easy!

Arena or any other good simulation language adopts this approach.

22 / 24

Page 23: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Simulation Languages

Outline

1 Steps in a Simulation Study

2 Some Definitions

3 Time-Advance Mechanisms

4 Two Modeling Approaches

5 Simulation Languages

23 / 24

Page 24: General Simulation Principlessman/courses/6644/Module04...What do we mean by “Update the FEL”? Any time there’s an event, the simulation may update the chronological order of

Simulation Languages

More than 100 commercial languages out there.Examples (from low- to high-level): FORTRAN, SIMSCRIPT,GPSS/H, Extend, Arena, FlexSim, Simio, AnyLogic, Automod.5–10 major players at schoolsHuge price range from <$1,000 to $100,000

FreewareSeveral nice packages in Java, Python (e.g., SimPyl).Little bit higher learning curve, but not too bad.

When selecting a language, you should take into account:Cost considerations: $$, learning curve, programming costs,run-time costs, etc.Ease of learning: documentation, syntax, flexibilityWorld view: E-S, P-I, continuous models, combinationFeatures: random variate generators, statistics collection,debugging aids, graphics, user community

Where to learn simulation languages?HereConferences such as the Winter Simulation ConferenceVendor short courses

24 / 24