Simulation Programming: Quick Start

As a first step toward more sophisticated simulation programming, this chapter presents a VBA simulation of the TTF example in  Chap. 1 . It also provides a gentle introduction to some important simulation concepts, and a brief overview of VBA, leaving th

  • PDF / 272,815 Bytes
  • 21 Pages / 439.36 x 666.15 pts Page_size
  • 29 Downloads / 183 Views

DOWNLOAD

REPORT


Simulation Programming: Quick Start

As a first step toward more sophisticated simulation programming, this chapter presents a VBA simulation of the TTF example in Chap. 1. It also provides a gentle introduction to some important simulation concepts, and a brief overview of VBA, leaving the details to Chap. 4. Good reference texts on VBA as used for simulation and modeling are Elizandro and Taha (2008) and Albright (2007). All readers should go through Sects. 2.1 and 2.2 of this chapter, even if they will not ultimately program their simulations in VBA. The focus here is on basic discrete-event simulation programming principles without using any special simulation support functions or objects. These principles form the core ideas for more sophisticated and scalable programming.

2.1 A TTF Simulation Program Like all programming languages, VBA has variables. The key variables in the TTF simulation are S, representing the number of functioning components, NextFailure, which holds the time of the next pending component failure, NextRepair, the corresponding time of the next component repair, and Clock, the current time on the simulation clock. The simulation will have a routine, called a Sub in VBA, for each event type. Three things happen in event routines: 1. The system state is updated; 2. Future events are scheduled; and 3. Statistics are computed or accumulated. Figure 2.1 shows the event routines for the TTF simulation. We describe Sub Failure in some detail; the reader should work through the logic of Sub Repair. When a failure occurs, the number of functional components always decreases by 1. If this leaves the system with only one functional component (S = 1), then B.L. Nelson, Foundations and Methods of Stochastic Simulation: A First Course, International Series in Operations Research & Management Science 187, DOI 10.1007/978-1-4614-6160-9 2, © Springer Science+Business Media New York 2013

7

8

2 Simulation Programming: Quick Start Private Sub Failure() ’ Failure event ’ Update state and schedule future events S = S - 1 If S = 1 Then NextFailure = Clock + _ WorksheetFunction.Ceiling(6 * Rnd(), 1) NextRepair = Clock + 2.5 End If ’ Update area under the S(t) curve Area = Area + Slast * (Clock - Tlast) Tlast = Clock Slast = S End Sub Private Sub Repair() ’ Repair event ’ Update state and schedule future events S = S + 1 If S = 1 Then NextRepair = Clock + 2.5 NextFailure = Clock + _ WorksheetFunction.Ceiling(6 * Rnd(), 1) End If ’ Update area under the S(t) curve Area = Area + Slast * (Clock - Tlast) Tlast = Clock Slast = S End Sub

Fig. 2.1 Event routines for VBA simulation of the TTF problem

just prior to this event there were no failed components nor any component under repair. Therefore, we need to schedule the failure time of the spare component that has just became active, and schedule the repair completion for the active component that has just failed. Events are always scheduled at the current Clock time plus an increment into the future. Repairs always take 2.5 days, so NextRepair = Clock + 2.5. How