Professional Documents
Culture Documents
by
Shivan Mohd
Study Leader
: Professor WR Gevers
Degree of Confidentiality
: Grade A
Date
: October 1999
ii
DECLARATION
Hereby I, Shivan Chad Mohd, declare that this study project is my own original work and that all
sources have been accurately reported and acknowledged, and that this document has not been
previously in its entirety or in part been submitted at any university in order to obtain an
academic qualification.
S. C. Mohd
4 October 1999
iii
ACKNOWLEDGMENTS
The author wishes to express sincere appreciation to Prof WR Gevers for his assistance in the
preparation of this manuscript. In addition, I would like to thank SPL for allowing me to make
use to their computer and printing equipment and making time available for me to complete
this mini-study project.
The core of this project is a computer simulation model. Although every effort has been taken to
ensure the proper operation of the model, neither the author of the program, nor the study leader
can and will be held liable for any loss of income due to incorrect information used in the
program. The program must be used as aid in making a business decision and not the deciding
factor. At the time of release, the software had no form of virus attached to it. For a more
definitive solution, the author could be contacted and will give guidelines as to your specific
problem.
iv
ABSTRACT
A mini-study project presented on the use of Microsoft Excel 2000 in the field of simulation.
The mini-study project covers the principles of queuing and its outputs. The simulation model
will test various scenarios of queuing theory. Inputs can be changed to suit the users
requirements. Results may be analysed to determine an optimal queuing environment.
v
OPSOMMING
Hierdie mini-werkstuk illustreer die gebruik van Excel 2000 in die veld van simulasie. Die
beginsels van toustaan modelle word gedek, asook die tipiese resultate. Die simulasiemodel
modelleer en toets verskillende toustaan scenarios. Toevoere kan verander word na gelang van
die gebruiker se keuse. Die resultate kan ontleed word om die optimale toustaan omgewing te
bepaal.
vi
TABLE OF CONTENTS
Declaration
Acknowledgments
Abstract
Opsomming
List of tables
List of figures
ii
iii
iv
v
viii
ix
CHAPTER 1. INTRODUCTION
1.1 INTRODUCTION
1.2 METHODOLOGY USED
1.3 LIMITATIONS AND RESTRICTIONS
1.4 MINIMUM REQUIREMENTS
1.5 DEVELOPMENT OF THE REPORT
1
2
2
3
3
2.1 INTRODUCTION
2.2 THE STRUCTURE OF THE QUEUING SYSTEM
2.2.1 The Customers and their source
2.2.2 The arrival process
2.2.3 The service facility and service process
2.2.4 The Queue
2.2.5 Degree of Patience
2.3 SUMMARY
4
4
4
4
5
5
6
6
3.1 INTRODUCTION
3.2 INPUTS REQUIRED
3.2.1 Unit of time
3.2.2 The duration of the simulation
3.2.3 The number of servers
3.2.4 The maximum number of customers allowed in the queue
3.2.5 The arrival rate
3.2.6 The service rate
3.3 SIMULATION OF RANDOM EVENTS
3.3.1 Exponential
3.3.2 Constant
3.3.3 Normal
3.3.4 Triangular
3.3.5 Observed Probabilities
3.4 SEQUENCE OF EVENTS
3.5 SUMMARY
7
7
7
7
7
8
8
9
9
9
9
10
10
10
11
12
13
4.1 INTRODUCTION
4.2 ANALYTICAL MODELS
4.3 SIMULATION RESULTS
4.4 OTHER STEPS TO VALIDATE RESULTS
4.5 SUMMARY
13
13
14
15
17
vii
CHAPTER 5. USER GUIDE
18
5.1 INTRODUCTION
5.2 USING THIS GUIDE
5.3 CONTROL CENTRE
5.4 ACTIONS BUTTONS
5.4.1 Change Inputs Button
5.4.2 Run Simulation Button Button
5.4.3 Add to History File button
5.4.4 Clear History Button
5.5 NAVIGATION BUTTONS
5.6 SUMMARY
18
18
19
21
21
24
26
26
26
28
29
6.1 SUMMARY
6.2 RECOMMENDATIONS
29
29
LIST OF SOURCES
30
31
33
43
viii
LIST OF TABLES
Table 2.1: Examples of queues
11
14
14
15
16
16
ix
LIST OF FIGURES
Figure 5.1: Welcome Screen
19
20
21
23
24
25
26
CHAPTER 1
1. INTRODUCTION
1.1 INTRODUCTION
Queuing is a part of many peoples lives. Managing queues and keeping them as short as
possible is a mammoth task and many people prefer to avoid the exercise of trying to calculate
the most user friendly and cost effective queuing environment. In an attempt to make this task a
bit easier, the model developed, will show the characteristics of queues by simulating the
queuing environment.
The model was designed and created for two main reasons:
To simulate a queuing environment based on various factors of queuing e.g. arrival
distribution, services rate, number of servers etc and presenting the results in format that
would make the analysis of the results easier.
The second reason is to show students:
a) how problems (in this case: queuing), can be solved by using spreadsheets as the analytical
tool and by allowing the student to try various combinations of inputs and comparing results;
b) the logic of queuing simulation.
Students and managers who wish to optimise the operations where people or items needs to be
serviced within an appropriate time could use the model. The Model will report simulated results
of the users inputs, thus allowing for various scenarios. Optimal loading for service points could
be determined. It would also allow for controlling queue length and server idle time. In most
situations, a simulation model is a computer model that imitates a real-life situation. Often,
simulation can provide the decision maker with important information. A simulation model
might help answer questions such as the following:
If a service point is added, how will the average waiting time of the customer decrease?
2
If the service time is reduced, by how much will the average waiting time reduce?
Although analytical models can help in answering the questions above, simulation will give the
user a better feel as to the possible outputs of the data inputted. The program caters for both
theoretical probability distributions and observed probabilities.
1.2 METHODOLOGY USED
The model was created using Excel 2000. The main objectives are, to show how simulation can
be accomplished by using Excel spreadsheets and for the model to be practical in application.
Most of the program logic uses Visual Basic and Excel functions to simulate data and calculate
results. Once the program was complete, the data produced were validated using random checks
and the use of an analytical model to compare the analytical results against simulated results. By
covering the theory of queuing, the user will have a better understanding of the model. The
limitations of the model will be discussed in the next paragraph.
1.3 LIMITATIONS AND RESTRICTIONS
The program has its limitations and should only be used as a guideline. It makes the following
assumptions:
The population is from an infinite source
Customers arrive individually and not in groups
Only single or multi-facility No mixed facility
First come first served
The model does not take into account the following:
Balking
Reneging
Costs
3
1.4 MINIMUM REQUIREMENTS
For the model to work, the following minimum requirements with respect to hardware and
software must be adhered to:
486 100 MHz processor
At least 26 MBytes of RAM
Excel 97 or higher
Windows 95 or higher
1.5 DEVELOPMENT OF THE REPORT
The report covers the following subject areas:
Queuing theory: a quick overview A revision of queuing theory and the area the model will
cover, is presented. The queuing theory chapter will help the user in recapping on the theory
of queuing which would help the user understand the logic and results produced.
Logic of the model presented Understanding how the results were derived is a key factor
when working with the model presented. The sequence of the simulation is covered in this
area.
Verification of the model The focus of this chapter is to prove that the results are correct.
The user may be more comfortable in using the model once it has been proven that the model
produces the correct results.
User guide If a user requires clarification as to how the program is to be used, a section
covering the use of the program is included in this document.
CHAPTER 2
2. QUEUING THEORY: A QUICK OVERVIEW
2.1 INTRODUCTION
In order to understand the program, an overview to discuss some important points and
terminology would be appropriate and helpful when working through the program. The chapter
covers the minimal requirements needed for the simulation of queues.
2.2 THE STRUCTURE OF THE QUEUING SYSTEM
5
A constant arrival distribution is periodic, with exactly the same time between successive
arrivals. In productive systems, about the only arrivals that truly approach a constant interarrival period are those that are subject to machine control. Much more common are variable
(random) arrival distributions. In observing arrivals at a service facility, there are two
viewpoints: The time between successive arrivals can be analysed to see if the times follow
some statistical distribution. Usually, in elementary analytical models it is assumed that the
time between arrivals is exponentially distributed.
6
Table 2.1: Examples of queues
System
Computer
Bank
Telephone
Library
Queue
Jobs
People
Callers
Books to be shelved
Service
Process facilities
Tellers
Switchboards
Librarians Assistants
CHAPTER 3
3. THE LOGIC OF THE MODEL PRESENTED
3.1 INTRODUCTION
Once a good understanding of the queuing theory has been formed, the user will have a better
understanding of the logic of the model presented. The purpose of this chapter is to clarify the
flow of inputs, processes and outputs of the model.
3.2 INPUTS REQUIRED
8
3.2.4 The maximum number of customers allowed in the queue
The user can set the number of customers the queue can handle. For example: 20 will mean that
once the queue length reaches 20, customers would be turned away until the number in queue
drops to below 20. The customer who will be turned away will then be recorded under the
Number of Customers turned away heading on the report sheet. The parameter is governed by
the size available for queuing. If the area in which people are allowed to queue can only house
10 people then the limit must be set to ten. If unlimited space is available for queuing then the
parameter must be set to 1000.
9
3.2.6 The service rate
The average service rate will be in the form of e.g. six per time of unit. It means that if the
customers arrive at a rate of 6 every hour (time unit) then the average time per service will be 1/6
= 0.166 hours, and this is the number placed in the input box. The average time per service is
automatically converted to a service rate, which is reported to the Input Screen. The average time
per service on the Input Screen will not be used if the program is using the observed probability
option. By using the Monte-Carlo methodology, random times will be selected from the service
time probabilities table. The average time per service is then used in the simulation process
The distribution pattern of the mean service time is independent of that of the inter-arrival
times.
3.3 SIMULATION OF RANDOM EVENTS
When simulating data, random numbers are required. In the model, random numbers are
required for the inter-arrival time and the service time. Excel provides a facility that generates
random numbers. In the Visual basic format, the Rnd function is used. When observed values
are used, the Monte Carlo methodology is used to generate random times.
Five different probability distributions may be selected. Durations are simulated as shown
below for the various distributions.
a) Exponential
When the exponential option is selected, the program uses the following statement:
Duration = MeanArriveTime * Log(Rnd)
Where Log represents the natural logarithm.
b) Constant
When the constant option is selected, the program uses the following statement:
10
Duration = MeanArriveTime
c) Normal
When the normal option is selected, the program uses the following statement:
Duration = NormInv (Random Number, Standard Deviation, MeanArriveTime) (Returns the
inverse of the normal cumulative distribution for the specified mean and standard deviation)
If a negative number is generated, the program will loop until the generated number is positive.
Only positive numbers are used in the simulation.
d) Triangular
When the triangular option is selected, the program uses the following statement:
ValA = (MaximumValue - MinimumValue)
If Randomnum <= StdCArrive (Standardised C)
Then
MeanArriveTime = ValA * Sqr (Randomnum * StdCArrive)
Else
MeanArriveTime = ValA * (1 - Sqr ((1 - StdCArrive) * (1 -Randomnum)))
End If
Duration = Minimum Value + MeanArriveTime
e) Observed Probabilities
Developed during the Manhattan (Atomic Bomb) Project in the 1940s, Monte Carlo simulation
involves feeding a large number of random inputs (in this case, inter-arrival and service times)
into a model while recording the range of outputs. The random inputs are analogous to rolls of
dice or spins of a roulette wheel at a casino, hence the name. The option of observed
probabilities uses the Monte Carlo Methodology using inputs (inter-arrival and service times)
from the user and extracting information from the probabilities table to complete the simulation.
The probabilities table is a set of specific inter-arrival times and its corresponding probability.
11
For example, an inter-arrival time of six may have a probability of 20%. Of all the other interarrival times the inter-arrival time of six appears 20% of the time within the given environment.
The formulae used within Excel to determine the times based on the probabilities: =
VLOOKUP().
The duration is calculated by generating a random number e.g. 0.54 and using it as a percentage.
The random number is used to compare the number against the probability table generated by
the user. The comparison will result in a corresponding inter-arrival or service time. The
newfound time is used as the duration within the simulation program.
3.4 SEQUENCE OF EVENTS
To start the simulation the user has to click on the Run Simulation button. Once this has been
done, the following sequence of events takes place:
Table 3.1: Sequence of events
Main Routine
RunSimulation
RunSimulation
RunSimulation
RunSimulation
Sub Routine
Initialize
Timing
UpdateAreas
Arrive
RunSimulation
12
run the depart routine.
Depart
RunSimulation
RunSimulation
RunSimulation
RunSimulation
RunSimulation
RunSimulation
RunSimulation
RunSimulation
Check
Averages
Queuelength
Buildreport
Report
CreateChart
Finishoff
A comprehensive list of all the routines and what functions it performs can be found in
Appendix A. Appendix C shows the actual code used to generate the results.
3.5 SUMMARY
The fundamental aim of the chapter is to show the user how the results are generated on a logical
level and the emphasis was removed from the more technical programming side. Many
computations are made to get a result before the next routine may execute, but once the logic is
set-up correctly, the results will be consistent. Users may find the visual basic code to be lengthy
and complex, however Excel still performs at a reasonably fast pace.
13
CHAPTER 4
4. VERIFICATION OF MODEL
4.1 INTRODUCTION
The purpose of the verification stages is two fold:
To prove that the results are reliable and the model works correctly.
To ensure that the results are consistent and accurate. The word accurate is used loosely as in
simulation, the result will vary every time but should average out closely to the analytical
results.
The methodology used will be:
Show which formulas will be used to test the results.
Build a table of inputs (Table 4.1), which will include both single and multiple servers.
Insert the input data in to the analytical formulas.
Insert the input data into the simulation model.
Compare the average simulated results to the analytical result (Table 4.2). (Outputs)
Compare theoretical inter-arrival times to simulated inter-arrival times (Table 4.4). (Input)
Compare theoretical service times to simulated service times (Table 4.4). (Input)
Compare theoretical statistical data to simulated statistical data (Table 4.5).
4.2 ANALYTICAL MODELS
An analytical model, which was supplied by Professor WR Gevers, was used to test the results
of the simulated model.
The model properties are based on the:
M / M / s model.
14
In the above model M / M denotes that both the inter-arrival times and the service time for each
server is exponentially distributed. s denotes the number of servers. Customers are serviced in
a First-Come-First-Serve fashion.
4.3 SIMULATION RESULTS
Five different models based on the exponential distribution were analysed. The input parameters
are shown in Table 4.1. The analytical results together with the results of each of three
simulation runs are reported in Table 4.2.
Table 4.1: Inputs for comparison
Inputs
Average Inter-arrival time
Run1
0.04
2.00
0.40
Run4
0.17
0.03
1.50
2.00
0.60
0.50
0.75
Days
500
0.75
Minutes
800
0.83
Minutes
800
1.18
Days
500
0.93
Hours
1000
Run2
Run3
Run5
0.27
Run1
Run2
Run3
Run4
Run5
0.090
4.500
1.290
Traffic
2.977
Simulated Run 1
0.095
4.196
1.090
intensity
2.765
Simulated Run 2
0.093
4.375
1.440
To high
2.673
Simulated Run 3
0.089
5.689
1.200
Units
Days
Minutes
Minutes
Days
Hours
Analytical
2.250
2.250
3.230
Traffic
11.024
Simulated Run 1
2.405
2.080
2.843
intensity
10.230
Simulated Run 2
2.307
2.010
3.521
To high
9.856
Simulated Run 3
2.238
2.860
3.345
3.000
11.277
15
The simulated results appear to be similar to the analytical results. When running the program it
was found that the higher the traffic intensity the longer the simulation should run to get a
simulated answer similar to the analytical answer. The comparison above, focuss on the output
data.
4.4 OTHER STEPS TO VALIDATE RESULTS
Table 4.3: A Sample of the Details Table
Customer
Number
Duration Of
Service
Service
1
2
3
1.1881
0.3703
0.2300
1.1881
1.5584
1.7884
1.1881 Server 1
1.5584 Server 2
1.7884 Server 1
0.4944
0.7515
0.0587
Table 4.3 represents a sample of the Details Table in the simulation program. Table is used to
show which columns will be used in the following comparison.
Added to the comparison in Section 4.3, the averages of the:
Inter-arrival time
Duration of service,
were found by using the Detailed Results table in the Detailed results spreadsheet. By
comparing the Averages in the detailed results table against the actual values used to perform the
simulation, a variation can be found. Even though the random times generated are different to
the original inputs, due to the distributions, the averages are similar to the original values that
were inputted. The comparisons are shown in Table 4.4 for all of the distributions available
within the model. The comparison above focuss on the inputs of the environment.
16
Table 4.4: Input time versus simulated time
Description
Distribution
Traffic Intensity
Inter-Arrival time
inserted by user
Average simulated
inter-arrival time
Variation
Service time inserted
by the user
Average simulated
service time
Variation
Run 1
Run 2
Exponential
0.75
Average
0.0400
Constant
0.75
Average
2.0
Run 3
Run 4
Run 5
Normal
0.83
Average
0.40
Std Deviation
0.1
Triangular
0.99
Minimum 1
Most Likely 2
Maximum 3
Observed
0.85
Prob Time
0.7
5
0.1
4
0.1
3
0.1
2
Average
4.40
4.23
0.0406
2.0
0.37
1.91
0.0006
Average
0.0300
0.000
Average
1.5
0.03
Average
2.00
Std Deviation
0.5
0.09
Minimum 5
Most Likely 6
Maximum 7
0.0290
1.5
2.05
5.96
Average 7.5
7.45
0.0010
0.000
0.05
0.04
0.05
Prob
0.1
0.2
0.2
0.5
0.17
Time
4
6
7
9
The simulated results as shown in Table 4.4 appear to be similar to the analytical results. That
gives confidence that the simulator simulates the times correctly. A further check would be to
test the simulated times for statistical significant deviation from the expected values. This has
been done for the observed distribution in Table 4.5.
Average Time
Sample Size
Standard Deviation
Significance Level
Confidence Interval
High
Low
4.400
47
1.020
0.05 (95%)
7.500
47
1.688
0.05 (95%)
4.692
4.108
7.983
7.017
The observed inter-arrival time of 4.23 falls well in to the 95% confidence interval, and so does
the simulated service time of 7.45. This indicates that the observed probability distribution
17
seems to be simulated correctly.
4.5 SUMMARY
It can be seen that there is a small variation between the simulated results and the analytical data.
Both the input data e.g. inter-arrival time, and the output results e.g. number of clients in queue,
are similar when comparing the theoretical data and the simulated results. A conclusion can be
drawn: the simulated results proves to be within a reasonable accuracy when compared to the
analytical results.
18
CHAPTER 5
5. USER GUIDE
5.1 INTRODUCTION
The following section will explain systematically what each button will do when activated.
When loading the Excel simulation file, the user will be prompted to enable the built in macros:
The macros must be enabled, for the program to work. Once the macros have been enabled,
the user will be presented with a Welcome screen (Figure 5.1).
5.2 USING THIS GUIDE
New and experienced users of Microsoft Excel may use this manual. The user will be able to
simulate basic queuing scenarios. The program is written in a friendly format using a quasi form
of wizard that will try to attempt to catch any incorrect information where possible. The manual
will help the user will be able to use this program by making use of this manual.
Some of the screens are password protected. To unprotect a screen, use the usb password. The
password is caps sensitive.
It is compulsory to place information in the input boxes. If the boxes are not completed as
required, with the result of information being omitted, the simulation program will inform the
user to re-enter the required data. The appropriate input box will automatically be displayed.
19
5.3 CONTROL CENTRE
20
21
5.4 ACTIONS BUTTONS
22
Day
b) The number of units that the simulation must run
The number of units that the simulation must run limits the number of observations to generate.
For example, if the units are hours, the arrival rate is 20 per hour, the limit is set to 8 hours as in
a working day then the result will be approximately 160 observations. The higher the limit, the
closer the result will be to the analytical result, however the system takes much longer to
simulate as the time is increased.
c) The number of servers
In the input box, the number of servers must be specified. If, for example two bank tellers are
used to service clients then the number 2 must be inserted in the box.
d) The maximum number of customers allowed in the queue.
The program allows the option of either having an unlimited number of space available for the
customers to queue (setting equals a 1000) or a limited amount of space. It would be used when
the area in which to queue can only hold, for example, 20 customers, the setting would be set to
20. The system now rejects any customer that enters the system if the queue length in longer
than 20.
Once the relevant data has been entered and the continue key clicked, the following screen
appears (Figure 5.4).
23
24
25
5.4.3 Update Probability Tables Button
The Update Probability Tables-button takes the user to the probability table screen. Here the
user will enter the observed probabilities for both the arrival time and the service time.
26
5.4.4 Add to History File Button
The "Add to History File"-button allows the program to add / save simulated results in a
spreadsheet. It allows the user to save up to five simulated runs. First, clear the history file by
pressing the Clear History button (Paragraph 5.4.4). Then run a simulation. Once the
simulation has run, press the Add To History File button and it will save it to the history
screen. Refer to Fig 5.7.
27
5.5 NAVIGATION BUTTONS
The navigation buttons are used to navigate from screen to screen. Each screen represents a set
of data and it is as follows:
(Please check the Appendix B for a list of all the screens for a more detailed description.)
a) Welcome Screen
The Welcome screen is the introduction screen.
28
g) The Detailed Results Screen
The Detailed Results screen shows information about each customer and each server.
5.6 SUMMARY
The user guide covers the navigation of simulation program. An important characteristic, of the
simulation program to remember is, only times, should be inputted when prompted for arrival or
service durations. The other information is self-explanatory. The sequence of usage is irrelevant
i.e. any button may be clicked to see what it does. When trying to run a simulation for the users
environment, the Change Inputs button must be clicked followed by the Run simulation
button.
29
CHAPTER 6
6. SUMMARY AND RECOMENDATIONS
6.1 SUMMARY
The core of this study project consists of a queuing simulation model that was built in the Excel
environment with visual basic.
environment that he/she would like to improve. Topics, covered by the document, are from the
input stage to the output stage and how to use the results. Computer simulation is one of the
most versatile of all management science tools, and its popularity is growing constantly. The
simulation model demonstrated how the random function in Excel allows a user to simulate a
wide variety of problems. However, it only represents a small fraction of what simulation can
accomplish. However, the users should come away with an increased understanding of the
concept of simulation.
6.2 RECOMMENDATIONS
To enhance the simulation experience the user could take advantage of a powerful add-in
package, @RISK, that facilitates simulation (not for queuing), particularly statistics gathering
and presentation of results. The add-in, along with the functionality of Excel itself, allows
individuals with virtually no programming skills to perform complex and realistic simulations.
Even this, however, is only the tip of the iceberg in terms of what simulation can accomplish.
There are many special-purpose simulation packages that can simulate complex queuing systems
and a variety of other processes, and these packages are being, using increasingly often in the
business world. The material covered in this document should give the user a start in the use
simulation, however the extent to which simulation is used in the working environment is
extremely large and complex!
30
LIST OF SOURCES
Winston, W.L. & Albright, S.C. 1997. Practical Management Science: Spreadsheet Modelling
and Applications. Belmont, CA: Duxbury
Turban, E. & Meredith, J.R. 1994. Fundamentals of Management Science. 6th ed. BurrRidge,
Ill: Irwin
Microsoft Corporation. 1999. Excel spreadsheet. Version 2000.
31
32
GetInputs
RunSimulation
It's function
The routine prompts the user for either the standard deviation or the min, most
likely and maximum value depending on what the user chose as the distribution
process
33
34
LIST OF SCREENS
B.1 WELCOME SCREEN
35
B.2 INPUTS SCREEN
36
B.3 REPORTS SCREEN
37
The information supplied by the program must be compared to the desired results of the
management of the queuing environment so that a compromise can be sought.
Probability of distribution number in queue
The probability of distribution number in queue information pertains to the queue that is
formed within the environment. The information supplied is concerning the queue and not the
entire system
38
39
B.5 GRAPHICAL DISTRI BUTION SCREEN
40
B6. DETAILS SCREEN
41
In form of a continuous clock, the time of arrival is calculated, by adding the randomly generated
inter-arrival time to the last arrival time.
Time service starts
In form of a continuous clock, the time of the service start is shown. The time is based on First
come First served i.e. the first available server will take on a new customer. The model checks
for servers that are idle, and of those servers that are idle, it will assign the client to the server
with the lowest number i.e. server two will get preference over server three and four etc.
Server number to perform the service
Shows the server number that serviced the customer.
Duration of service
Show the duration of the service. The service time is randomly generated.
Clock time the service ends
The clock time the service ends time is based on the randomly generated duration of service
time i.e. Time service start plus Duration of service equals Clock time the service ends.
Waiting time of customer in minutes
If the customer waits then the time waited is recorded in this field
Queue length
The field shows the queue length at the point where the customer enters the system.
The rest of the information is the same as what is in the blue table expert for the last column in
the green table. The column shows the idle time for each server.
42
B.7 AVERAGES SCREEN
43
44
45
DialogSheets("QGeneral Inputs").Show
DialogSheets("QArrival Inputs").EditBoxes("AvgCustArrive").Text = 0
Worksheets("Inputs").Range("ArivDist").Value = 1
DialogSheets("QArrival Inputs").Show
DialogSheets("QService Inputs").EditBoxes("AvgCustService").Text = 0
Worksheets("Inputs").Range("ServDist").Value = 1
DialogSheets("QService Inputs").Show
'check if probs = 1
checkforo = Worksheets("Inputs").Cells(4, 6).Value
Do Until checkforo > 1
arivedist = Worksheets("Inputs").Range("ArivDist").Value
If arivedist = 5 Or 4 Then
Worksheets("Inputs").Range("ArriveTime").Value =
Worksheets("Inputs").Range("MostLikArrive").Value
Else
MsgBox "Note: You have selected a Zero Value for the Arrival time. The program cannot run with a zero
value. Please insert a value greater than one!"
DialogSheets("QArrival Inputs").EditBoxes("AvgCustArrive").Text = 0
DialogSheets("QArrival Inputs").Show
End If
checkforo = Worksheets("Inputs").Cells(4, 6).Value
Loop
checkforo = Worksheets("Inputs").Cells(3, 6).Value
Do Until checkforo > 1
servdist = Worksheets("Inputs").Range("ServDist").Value
If servdist = 5 Or 4 Then
Worksheets("Inputs").Range("serveTime").Value = 1
Else
MsgBox "Note: You have selected a Zero Value for the Service time. The program cannot run with a zero
value. Please insert a value greater than one!"
DialogSheets("QService Inputs").EditBoxes("AvgCustService").Text = 0
DialogSheets("QService Inputs").Show
End If
checkforo = Worksheets("Inputs").Cells(3, 6).Value
Loop
'warn user of prob <> 1
arrivedist1 = Worksheets("Inputs").Range("ArivDist").Value
Select Case arrivedist1
Case 1, 2, 3, 4
Case 5
MsgBox ("You have selected the 'Observed Probabilities' distribution option for the inter-arrival time,
please Update the Arrival Probability Table before you run the simulation.")
Worksheets("Observed Prob").Select
Worksheets("Observed Prob").Cells(1, 1).Select
Case Else
End Select
arrivedist1 = Worksheets("Inputs").Range("servDist").Value
Select Case arrivedist1
Case 1, 2, 3, 4
46
Case 5
MsgBox ("You have selected the 'Observed Probabilities' distribution option for the service time per server,
please Update the Service Probability Table before you run the simulation.")
Worksheets("Observed Prob").Select
Worksheets("Observed Prob").Cells(1, 1).Select
Case Else
End Select
DialogSheets("Navigation Bar").hide
End Sub
Sub RunSimulation()
Dim arivedist, servdist As Integer
' check if prob = 1 if not abort
arivedist = Worksheets("Inputs").Range("ArivDist").Value
servdist = Worksheets("Inputs").Range("ServDist").Value
47
MsgBox "You have selected the 'Observed Probabilities' as your distribution, however the service
probability total must add up to one. Please correct any errors."
Worksheets("Observed Prob").Cells(3, 6).Select
DialogSheets("Navigation Bar").hide ' hide bar
Exit Sub
End If
End If
Else
End If
If arivedist = 5 Then
Worksheets("Inputs").Range("ArriveTime").Value = Worksheets("Observed
Prob").Range("Averagearrival").Value
MsgBox "Note: You have chosen the Average Arrival Time as the distribution pattern. The Average of
the times will be displayed (for reporting purposes) on the input screen as 'Average time between arrivals',
however this average will not be used in the simulation."
End If
If servdist = 5 Then
Worksheets("Inputs").Range("ServeTime").Value = Worksheets("Observed
Prob").Range("Averageserve").Value
MsgBox "Note: You have chosen the Average Service Time as the distribution pattern. The Average of
the times will be displayed (for reporting purposes) on the input screen as 'Average time for each service',
however this average will not be used in the simulation."
End If
48
Report ' Put the outputs on the Report sheet
CreateChart ' create chart
Worksheets("Reports").Select ' goto reports sheet
DialogSheets("Navigation Bar").hide ' hide bar
End Sub
Sub finishoff()
Dim count As Single
count = NumCusts + 2
Worksheets("table2").Select
' format table
Range(Cells(3, 1), Cells(count, 6)).Select
Selection.Copy
Range("G3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range(Cells(2, 7), Cells(count, 11)).Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("K3"), Order1:=xlAscending, Key2:=Range("I3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Range("L3").Select
ActiveCell.FormulaR1C1 = "0"
Range("L4").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-R[-1]C[-2]"
Range("L4").Select
Selection.AutoFill Destination:=Range(Cells(4, 12), Cells(count, 12)), Type:=xlFillDefault
Worksheets("Table2").Cells(3, 12).Value = Worksheets("Table2").Cells(3, 9).Value
count = 0
Dim nextcustomer As Single
Do Until count = NumCusts
'find blanks and fill
nextcustomer = Worksheets("Table2").Cells(3 + count, 12).Value
If nextcustomer < 0 Then
Worksheets("Table2").Cells(3 + count, 12).Value = 0
Else
End If
count = count + 1
Loop
End Sub
Sub Averages()
'find averages
Worksheets("Summary").Select
ActiveSheet.PivotTables("PivotTable").PivotSelect "", xlDataAndLabel
Selection.ClearContents
Rows("7:16").Select
Selection.Delete Shift:=xlUp
Worksheets("table2").Select
'calculate customer delay
Range(Cells(3 + NumCusts, 6), Cells(3 + NumCusts, 6)).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-" & NumCusts & "]C:R[-1]C)"
Worksheets("Summary").Cells(2, 2).Value = Worksheets("Table2").Cells(3 + NumCusts, 6).Value
Range(Cells(3 + NumCusts, 6), Cells(3 + NumCusts, 6)).ClearContents
49
End Sub
Sub check()
'check for zeros
Dim count As Single, nextcustomer As Single, nextcustomer1 As Double
count = 0
Do Until count = NumCusts
nextcustomer = Worksheets("Table2").Cells(3 + count, 2).Value
nextcustomer1 = Worksheets("Table2").Cells(3 + count, 6).Value
If nextcustomer <= 0 Then
Worksheets("Table2").Cells(3 + count, 2).Value = Worksheets("Table2").Cells(3 + count, 3).Value
Else
End If
If nextcustomer1 <= 0 Then
Worksheets("Table2").Cells(3 + count, 6).Value = 0
Else
End If
count = count + 1
Loop
End Sub
Sub Initialize()
50
Dim i As Integer
Time = 0
NumBusy = 0
NumInQ = 0
TimeLastEvent = 0
serverno = 0
NumCusts = 0
NumLost = 0
TotDelays = 0
MaxDelay = 0
AreaNumInQ = 0
MaxInQ = 0
AreaUtil = 0
Nextcust = 1
timingcount = 0
Worksheets("Table2").Range("Clearcontents").ClearContents
'rest parameters
Worksheets("Reports").Range("NumLost") = 0
Worksheets("Reports").Range("NumCusts") = 0
Worksheets("Reports").Range("MaxDelay") = 0
Worksheets("Reports").Range("AvgDelay") = 0
Worksheets("Reports").Range("AvgNumInQ") = 0
Worksheets("Reports").Range("MaxInQ") = 0
Worksheets("Reports").Range("Util") = 0
arivdist = Worksheets("Inputs").Range("ArivDist").Value
Select Case arivdist ' Evaluate ArivDist
Case 1 ' Case for Poisson and Exponetial
' Schedule an arrival from the exponential distribution
TimeNextEvent(1) = -MeanArriveTime * Log(Rnd)
Case 2 'Case for Constant distribution
TimeNextEvent(1) = MeanArriveTime
Case 3 ' Case for Normal Distribution
StdDevArrive = Worksheets("Inputs").Range("StdDevArrive").Value
MeanArriveTime = Worksheets("Inputs").Range("ArriveTime").Value
Randomnum = Rnd
meanarrivetime2 = MeanArriveTime
MeanArriveTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
MeanArriveTime)
Do Until MeanArriveTime > 0
Randomnum = Rnd
MeanArriveTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
meanarrivetime2)
Loop
MeanArriveTime = MeanArriveTime
TimeNextEvent(1) = MeanArriveTime
Case 4 ' Case Triangular
Randomnum = Rnd
MostLikelyValue = Worksheets("Inputs").Range("MostLikArrive").Value
MinimumValue = Worksheets("Inputs").Range("MinArriveValue").Value
MaximumValue = Worksheets("Inputs").Range("MaxValueArrive").Value
StdCArrive = Worksheets("Inputs").Range("StdCArrive").Value
51
ValA = (MaximumValue - MinimumValue)
If Randomnum <= StdCArrive Then
MeanArriveTime = ValA * Sqr(Randomnum * StdCArrive)
Else
MeanArriveTime = ValA * (1 - Sqr((1 - StdCArrive) * (1 - Randomnum)))
End If
MeanArriveTime = MinimumValue + MeanArriveTime
TimeNextEvent(1) = MeanArriveTime
Case 5
'Calls the MeanArriveTime from a cell within the observed probibiltie work sheet. The cell uses the
VLOOKUP commamd to detemne the time.
MeanArriveTime = Worksheets("Observed Prob").Range("MeanArriveT").Value
TimeNextEvent(1) = MeanArriveTime
Case Else
MsgBox ("Please Select one of the options presented")
End Select
Worksheets("Table2").Cells(3 + Nextcust, 2).Value = TimeNextEvent(1)
' Don't schedule a departure because there are no customers being served
For i = 1 To numservers
TimeNextEvent(i + 1) = 100000
Next
End Sub
Sub Timing()
Dim i As Integer, MinTimeNextEvent As Single
MinTimeNextEvent = 99999
' Find type and time of next event (most imminent event)
For i = 1 To numservers + 1
If TimeNextEvent(i) < MinTimeNextEvent Then
MinTimeNextEvent = TimeNextEvent(i)
If i = 1 Then
NextEventType = 1
Else
' For a departure event, also record the index (2 to NumServers + 1)
' of the server who finished
NextEventType = 2
FinishedServer = i
End If
End If
Next
' Update the clock to the time of the next event
Time = MinTimeNextEvent
End Sub
Sub Arrive()
Dim SchedDep As Single, meanarrivetime2, i As Integer, starttime As Double
arivdist = Worksheets("Inputs").Range("ArivDist").Value
Select Case arivdist ' Evaluate ArivDist
52
Case 1 ' Case for Poisson and Exponetial
' Schedule an arrival from the exponential distribution
TimeNextEvent(1) = Time - MeanArriveTime * Log(Rnd)
Case 2 'Case for Constant distribution
TimeNextEvent(1) = Time + MeanArriveTime
Case 3 ' Case for Normal Distribution
StdDevArrive = Worksheets("Inputs").Range("StdDevArrive").Value
MeanArriveTime = Worksheets("Inputs").Range("ArriveTime").Value
Randomnum = Rnd
meanarrivetime2 = MeanArriveTime
MeanArriveTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
MeanArriveTime)
Do Until MeanArriveTime > 0
Randomnum = Rnd
MeanArriveTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
meanarrivetime2)
Loop
MeanArriveTime = MeanArriveTime
TimeNextEvent(1) = Time + MeanArriveTime
Case 4 ' Case Triangular
Randomnum = Rnd
MostLikelyValue = Worksheets("Inputs").Range("MostLikArrive").Value
MinimumValue = Worksheets("Inputs").Range("MinArriveValue").Value
MaximumValue = Worksheets("Inputs").Range("MaxValueArrive").Value
StdCArrive = Worksheets("Inputs").Range("StdCArrive").Value
ValA = (MaximumValue - MinimumValue)
If Randomnum <= StdCArrive Then
MeanArriveTime = ValA * Sqr(Randomnum * StdCArrive)
Else
MeanArriveTime = ValA * (1 - Sqr((1 - StdCArrive) * (1 - Randomnum)))
End If
MeanArriveTime = MinimumValue + MeanArriveTime
TimeNextEvent(1) = Time + MeanArriveTime
Case 5
MeanArriveTime = Worksheets("Observed Prob").Range("MeanArriveT").Value
TimeNextEvent(1) = Time + MeanArriveTime
Case Else
MsgBox ("Please Select one of the options presented")
End Select
Worksheets("Table2").Cells(3 + Nextcust, 2).Value = TimeNextEvent(1)
starttime = Time
If NumInQ = MaxInSys Then
NumLost = NumLost + 1
Exit Sub
End If
If NumBusy = numservers Then
NumInQ = NumInQ + 1
If NumInQ > MaxInQ Then
MaxInQ = NumInQ
End If
' Keep track of each customer's arrival time (for later stats)
TimeArrival(NumInQ) = Time
53
' Otherwise, customer can go directly into service
Else
' Make the first idle server busy and schedule a departure
NumBusy = NumBusy + 1
i=2
SchedDep = TimeNextEvent(i)
' This loop searches for the first idle server
Do
If SchedDep > 99999 Then
ServiceSeq = 1
'Determine the Service Distribution
'schedule an Service based on users input
servdist = Worksheets("Inputs").Range("ServDist").Value
' Stop
Select Case servdist ' Evaluate ServDist
Case 1 ' Case for Poisson and Exponetial
' Schedule an Service from the exponential distribution
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time - MeanServeTime * Log(Rnd)
Else
Stop
TimeNextEvent(FinishedServer) = Time - MeanServeTime * Log(Rnd)
End If
Case 2 'Case for Constant distribution
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case 3 ' Case for Normal Distribution
StdDevService = Worksheets("Inputs").Range("StdDevService").Value
MeanServeTime = Worksheets("Inputs").Range("ServeTime").Value
Randomnum = Rnd
meanservetime2 = MeanServeTime
MeanServeTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
MeanServeTime)
Do Until MeanServeTime > 0
Randomnum = Rnd
MeanServeTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevArrive,
meanservetime2)
Loop
MeanServeTime = MeanServeTime
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case 4 ' Case Triangular
Randomnum = Rnd
MostLikelyValue = Worksheets("Inputs").Range("MostLikService").Value
MinimumValue = Worksheets("Inputs").Range("MinServiceValue").Value
MaximumValue = Worksheets("Inputs").Range("MaxValueService").Value
StdCService = Worksheets("Inputs").Range("StdCService").Value
ValB = (MaximumValue - MinimumValue)
54
If Randomnum <= StdCService Then
MeanServeTime = ValB * Sqr(Randomnum * StdCService)
Else
MeanServeTime = ValB * (1 - Sqr((1 - StdCService) * (1 - Randomnum)))
End If
MeanServeTime = MinimumValue + MeanServeTime
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case 5
MeanServeTime = Worksheets("Observed Prob").Range("MeanServiceT").Value
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
Stop
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case Else
MsgBox ("Please Select one of the options presented")
End Select
Exit Do
Else
i=i+1
SchedDep = TimeNextEvent(i)
End If
Loop
End If
If i = 0 Then
Else
serverno = i - 1
End If
If serverno > 0 And i > 0 Then
'update table
Worksheets("Table2").Cells(2 + Nextcust, 1).Value = Nextcust
Worksheets("Table2").Cells(2 + Nextcust, 4).Value = TimeNextEvent(i)
Worksheets("Table2").Cells(2 + Nextcust, 3).Value = starttime
Worksheets("Table2").Cells(2 + Nextcust, 5).Value = "server " & serverno
Nextcust = Nextcust + 1
Else
End If
End Sub
Sub Depart()
Dim i As Integer, Delay As Single, starttime As Double, servetemp As Double, numberone As Double,
numbertwo As Double
servetemp = serverno
' Update number of customers who have finished
NumCusts = NumCusts + 1
55
' Check if any customers are waiting in queue - if not, make the
' server who just finished idle by resetting the TimeNextEvent to a
' large number
If NumInQ = 0 Then
NumBusy = NumBusy - 1
TimeNextEvent(FinishedServer) = 100000
' Otherwise, take customer from front of queue into service
Else
NumInQ = NumInQ - 1
'Worksheets("Table2").Cells(2 + Nextcust, 13).Value = NumInQ
' Delay is the time this customer has been waiting in line
Delay = Time - TimeArrival(1)
56
Do Until MeanServeTime > 0
Randomnum = Rnd
MeanServeTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevService,
meanarrivetime2)
Loop
MeanServeTime = MeanServeTime
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case 4 ' Case Triangular
Randomnum = Rnd
MostLikelyValue = Worksheets("Inputs").Range("MostLikService").Value
MinimumValue = Worksheets("Inputs").Range("MinServiceValue").Value
MaximumValue = Worksheets("Inputs").Range("MaxValueService").Value
StdCService = Worksheets("Inputs").Range("StdCService").Value
ValB = (MaximumValue - MinimumValue)
If Randomnum <= StdCService Then
MeanServeTime = ValB * Sqr(Randomnum * StdCService)
Else
MeanServeTime = ValB * (1 - Sqr((1 - StdCService) * (1 - Randomnum)))
End If
MeanServeTime = MinimumValue + MeanServeTime
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case 5
MeanServeTime = Worksheets("Observed Prob").Range("MeanServiceT").Value
If ServiceSeq = 1 Then
TimeNextEvent(i) = Time + MeanServeTime
Else
TimeNextEvent(FinishedServer) = Time + MeanServeTime
End If
Case Else
MsgBox ("Please Select one of the options presented")
End Select
i = serverno + 1
starttime = Time
If serverno > 0 And i > 0 Then
serverno = FinishedServer - 1
'update tables
Worksheets("Table2").Cells(2 + Nextcust, 6).Value = Delay
Worksheets("Table2").Cells(2 + Nextcust, 1).Value = Nextcust
Worksheets("Table2").Cells(2 + Nextcust, 4).Value = TimeNextEvent(FinishedServer)
Worksheets("Table2").Cells(2 + Nextcust, 3).Value = starttime
Worksheets("Table2").Cells(2 + Nextcust, 5).Value = "server " & serverno
Worksheets("Table2").Cells(2 + Nextcust, 2).Value = starttime - Delay
57
Nextcust = Nextcust + 1
serverno = FinishedServer + 1
Else
End If
' Move everyone else in line up one space
For i = 1 To NumInQ
TimeArrival(i) = TimeArrival(i + 1)
Next
End If
End Sub
Sub Report()
'ActiveWorkbook.Protect Password:="usb", structure:=False, Windows:=False
Dim i As Integer
Dim AvgDelay As Single, AvgNumInQ As Single, Util As Single
AvgDelay = TotDelays / NumCusts
AvgNumInQ = AreaNumInQ / Time
Util = AreaUtil / Time
Time = 0
For i = 0 To MaxInQ
Time = TimeInQ(i) + Time
Next
For i = 0 To MaxInQ
TimeInQ(i) = TimeInQ(i) / Time
Next
With Worksheets("Reports")
.Activate
.Range("NumCusts").Value = NumCusts
.Range("AvgDelay").Value = AvgDelay
.Range("MaxDelay").Value = MaxDelay
.Range("AvgNumInQ").Value = AvgNumInQ
.Range("MaxInQ").Value = MaxInQ
.Range("Util").Value = Util / numservers
.Range("NumLost").Value = NumLost
' TimeInQ records, for value of NumInQ (0 to MaxInQ) the percentage
' of time that many customers were waiting in the queue
.Range("NumInQ").ClearContents
.Range("TimeInQ").ClearContents
.Range("diference").ClearContents
End With
With ActiveWorkbook
.Names("NumInQ").Delete
.Names("TimeInQ").Delete
End With
Worksheets("Reports").Range("NumInQ1").Select
With Selection
For i = 0 To MaxInQ
.Offset(i, 0).Value = i
.Offset(i, 1).Value = TimeInQ(i)
Next
End With
ActiveWorkbook.Names.Add Name:="NumInQ", _
58
RefersToR1C1:=Range(Selection, Selection.End(xlDown))
Selection.Offset(0, 1).Select
ActiveWorkbook.Names.Add Name:="TimeInQ", _
RefersToR1C1:=Range(Selection, Selection.End(xlDown))
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
.CalculateBeforeSave = False
End With
End Sub
Sub UpdateAreas()
Dim TimeSinceLastEvent As Single
TimeSinceLastEvent = Time - TimeLastEvent
TimeLastEvent = Time
TimeInQ(NumInQ) = TimeInQ(NumInQ) + TimeSinceLastEvent
AreaNumInQ = AreaNumInQ + NumInQ * TimeSinceLastEvent
AvgNumInQ = AreaNumInQ / Time
AreaUtil = AreaUtil + NumBusy * TimeSinceLastEvent
End Sub
Sub buildreportsheet()
'
' buildreportsheet Macro
' Macro recorded 05/10/1999 by Shivan Mohd
'
'
Application.DisplayAlerts = False
Sheets("Reports2").Delete
Application.DisplayAlerts = True
Sheets("Table2").Select
Sheets("Table2").Copy Before:=Sheets(7)
Sheets("Table2 (2)").Select
Sheets("Table2 (2)").Name = "Reports2"
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Columns("F:F").Select
Selection.Cut Destination:=Columns("D:D")
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
ActiveWindow.SmallScroll ToRight:=1
Columns("N:N").Select
Selection.Cut Destination:=Columns("G:G")
Columns("N:N").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll ToRight:=-7
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = "Interarrival Time"
With ActiveCell.Characters(Start:=1, Length:=17).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
59
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
End With
Columns("B:B").Select
Selection.ColumnWidth = 10.71
Selection.NumberFormat = "0.0000"
Range("B3").Select
ActiveCell.FormulaR1C1 = "=RC[1]"
Dim stepdown As Single
stepdown = 0
Do Until stepdown = NumCusts - 1
Worksheets("Reports2").Cells(4 + stepdown, 2).Value = Worksheets("Reports2").Cells(4 + stepdown,
3).Value - Worksheets("Reports2").Cells(4 - 1 + stepdown, 3).Value
stepdown = stepdown + 1
Loop
Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Range("F2").Select
ActiveCell.FormulaR1C1 = "Duration Of Service"
With ActiveCell.Characters(Start:=1, Length:=19).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
End With
stepdown = 0
Do Until stepdown = NumCusts - 1
Worksheets("Reports2").Cells(3 + stepdown, 6).Value = Worksheets("Reports2").Cells(3 + stepdown,
7).Value - Worksheets("Reports2").Cells(3 + stepdown, 4).Value
stepdown = stepdown + 1
Loop
Sheets("Summary").Select
Range("B3").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(Reports2!RC[4]:R[3333]C[4])"
Range("B2:B6").Select
Selection.NumberFormat = "0.0000"
End Sub
Sub queuelength()
Worksheets("Table2").Select
Dim q, stepup, stepdown As Single
q=1
60
stepup = 1
stepdown = 0
Worksheets("Table2").Cells(3, 2).Select
Do Until Worksheets("Table2").Cells(3 + stepdown, 1).Value = Nextcust - 1
If Worksheets("Table2").Cells(3 + stepdown, 2).Value = Worksheets("Table2").Cells(3 + stepdown, 3).Value
Then
q=0
Worksheets("Table2").Cells(3 + stepdown, 13).Value = q
Else
stepup = 1
If Worksheets("Table2").Cells(3 + stepdown, 2).Value > Worksheets("Table2").Cells(3 + stepdown stepup, 3).Value Then
q=1
Worksheets("Table2").Cells(3 + stepdown, 13).Value = q
Else
stepup = 1
Do Until Worksheets("Table2").Cells(3 + stepdown, 2).Value > Worksheets("Table2").Cells(3 +
stepdown - stepup, 3).Value
q=q+1
stepup = stepup + 1
Loop
Worksheets("Table2").Cells(3 + stepdown, 13).Value = q
q=1
End If
End If
stepdown = stepdown + 1
Loop
End Sub
Sub restorescreen()
Dim x As Single
Toolbars(1).Visible = True
Toolbars(2).Visible = True
With Application
.DisplayFormulaBar = True
.DisplayStatusBar = True
End With
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayHeadings = True
.DisplayWorkbookTabs = True
End With
Application.DisplayFullScreen = False
End Sub
61
Sub Auto_Close()
MsgBox ("Thank You for using the Simulation Package. Enjoy your day.")
Dim x As Single
Toolbars(1).Visible = True
Toolbars(2).Visible = True
With Application
.DisplayFormulaBar = True
.DisplayStatusBar = True
End With
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayHeadings = True
.DisplayWorkbookTabs = True
.DisplayHeadings = True
End With
Application.DisplayFullScreen = False
End Sub
Sub Auto_Open()
Worksheets("Welcome").Activate
Range("A1").Activate
Application.DisplayFullScreen = True
With Application
.DisplayFormulaBar = False
.DisplayStatusBar = False
End With
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayHeadings = False
.DisplayWorkbookTabs = False
.DisplayHeadings = False
End With
Dim x As Single
Worksheets("Welcome").Select
numberoftoolbars = Application.Toolbars.count
For x = 1 To numberoftoolbars
Toolbars(x).Visible = False
Next
End Sub
Sub hidescreenset()
Application.DisplayFullScreen = True
With Application
.DisplayFormulaBar = False
.DisplayStatusBar = False
End With
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayHeadings = False
62
.DisplayWorkbookTabs = False
End With
Dim x As Single
Worksheets("Welcome").Select
numberoftoolbars = Application.Toolbars.count
For x = 1 To numberoftoolbars
Toolbars(x).Visible = False
Next
End Sub
Sub GoToReport()
Worksheets("Reports").Activate
Range("A1").Select
End Sub
Sub CreateChart()
' Create a chart of TimeInQ versus NumInQ. (Actually, delete the old
' chart and create a new one)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("QChart").Delete
Application.DisplayAlerts = True
Charts.Add
ActiveChart.ChartWizard Source:=Sheets("Reports").Range( _
"NumInQ,TimeInQ"), Gallery:=xlColumn, format:=1, PlotBy:= _
xlColumns, CategoryLabels:=1, SeriesLabels:=0, HasLegend:=2, _
Title:="Distribution of Number in Queue", CategoryTitle:= _
"Number in Queue", ValueTitle:="Percentage of Time"
With ActiveChart
.PlotArea.ClearFormats
.ChartTitle.Font.Size = 16
.ChartGroups(1).GapWidth = 0
With .Axes(xlValue)
.AxisTitle.Font.Size = 14
.TickLabels.NumberFormat = "0%"
.TickLabels.Font.Size = 12
End With
With .Axes(xlCategory)
.AxisTitle.Font.Size = 14
.TickLabels.Font.Size = 12
End With
.Name = "QChart"
End With
' Add a button to the chart sheet (to return to the Report)
ActiveChart.Buttons.Add(376.5625, 81.25, 200, 43.75).Select
With Selection
.OnAction = "GoToNavigateBar"
.Characters.Text = "Control Central"
.Characters(Start:=1, Length:=18).Font.Size = 14
End With
ActiveChart.Deselect
End Sub
Sub GoToInputs()
Worksheets("Inputs").Activate
End Sub
Sub GeneralInputs()
63
' get general inputs
Worksheets("Inputs").Range("MaxTime").Value = (DialogSheets("QGeneral
Inputs").EditBoxes("NoOfUnits").Text)
Worksheets("Inputs").Range("NumServers").Value = (DialogSheets("QGeneral
Inputs").EditBoxes("NumService").Text)
Worksheets("Inputs").Range("MaxInSys").Value = (DialogSheets("QGeneral
Inputs").EditBoxes("MaxInQueue").Text)
If Worksheets("Inputs").Range("MaxInSys").Value > 1000 Then
Worksheets("Inputs").Range("MaxInSys").Value = 1000
End If
End Sub
Sub ArrivalInputs()
Dim arrivedist1, tunit, mynum, mynum2, mynum3 As Single
Worksheets("Inputs").Select
ActiveSheet.Unprotect
Rows("12:16").Select
Selection.EntireRow.Hidden = True
arrivedist1 = Worksheets("Inputs").Range("ArivDist").Value
tunit = Worksheets("Inputs").Range("TimeUnit").Value
Select Case arrivedist1
Case 1, 2
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 3
mynum = Application.InputBox("Enter the Standard Deviation in " & tunit & "s for the average time
between arrivals")
Worksheets("Inputs").Range("StdDevArrive").Value = mynum
Rows("12:12").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 4
mynum = Application.InputBox("Enter a the Minimum Value in " & tunit & "s for the average time
between arrivals")
mynum2 = Application.InputBox("Enter a the Most Likely Value in " & tunit & "s for the average time
between arrivals")
mynum3 = Application.InputBox("Enter a the Maximum Value in " & tunit & "s for the average time
between arrivals")
Worksheets("Inputs").Range("MinArriveValue").Value = mynum
Worksheets("Inputs").Range("MostLikArrive").Value = mynum2
Worksheets("Inputs").Range("MaxValueArrive").Value = mynum3
Rows("13:16").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 5
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("Observed Prob").Select
Worksheets("Observed Prob").Cells(1, 1).Select
Case Else
End Select
Worksheets("Inputs").Range("ArriveTime").Value = (DialogSheets("QArrival
Inputs").EditBoxes("AvgCustArrive").Text)
End Sub
Sub cont()
End Sub
Sub ServiceInputs()
64
Worksheets("Inputs").Select
ActiveSheet.Unprotect
Rows("22:26").Select
Selection.EntireRow.Hidden = True
Dim servdist1 As Single, tunit As String, mynum As Single, mynum2 As Single, mynum3 As Single
servdist1 = Worksheets("Inputs").Range("servdist").Value
tunit = Worksheets("Inputs").Range("TimeUnit").Value
Select Case servdist1
Case 1, 2
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 3
mynum = Application.InputBox("Enter the Standard Deviation in " & tunit & "s for the average time per
server")
Worksheets("Inputs").Range("StdDevService").Value = mynum
Rows("22:22").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 4
mynum = Application.InputBox("Enter a the Minimum Value in " & tunit & "s for the average time per
server")
mynum2 = Application.InputBox("Enter a the Most Likely Value in " & tunit & "s for the average time
per server")
mynum3 = Application.InputBox("Enter a the Maximum Value in " & tunit & "s for the average time per
server")
Worksheets("Inputs").Range("MinServiceValue").Value = mynum
Worksheets("Inputs").Range("MostLikService").Value = mynum2
Worksheets("Inputs").Range("MaxValueService").Value = mynum3
Rows("23:26").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Case 5
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("Observed Prob").Select
Worksheets("Observed Prob").Cells(1, 1).Select
Case Else
End Select
Worksheets("Inputs").Range("ServeTime").Value = (DialogSheets("QService
Inputs").EditBoxes("AvgCustService").Text)
End Sub
Sub MaxInQueue_AfterUpdate()
MsgBox ("1) Enter the time unit you would like to use eg Day to work with days etc. 2) Enter the number of
time units the simulation will last eg. 2 will equal two days Note: At the end of this time, no arrivals will be
allowed, but customers already in the system will be served. 3) Enter the number of servers available 4) Enter the
number of customers allowed in the queue.")
End Sub
Sub GoToCharts()
Worksheets("Graphic Reports").Activate
End Sub
Sub GoToHistory()
Worksheets("QHistory").Activate
End Sub
65
Sub GoToNavigateBar()
DialogSheets("Navigation Bar").Show
End Sub
Sub GotoWelcome()
Worksheets("Welcome").Activate
End Sub
Sub GoToProb()
Sheets("QChart").Activate
End Sub
Sub GoToProbTable()
Sheets("Observed Prob").Activate
End Sub
Sub GoToDetail()
Sheets("Reports2").Activate
End Sub
Sub GoToAnalyticalModel()
Sheets("Analytical Model").Activate
End Sub
Sub GoToSummaryT()
Sheets("Summary").Activate
End Sub
Sub ClearHistory()
Worksheets("QHistory").Range("RunNo").Value = 1
Worksheets("QHistory").Range("HistoryData").Value = 0
DialogSheets("Navigation Bar").EditBoxes("NoOfRunsLeft").Text = 5
End Sub
Sub AddToHistory()
Dim RunNo As Single
RunNo = Worksheets("QHistory").Range("RunNo").Value
Select Case RunNo
Case 1 To 5
DialogSheets("Navigation Bar").EditBoxes("NoOfRunsLeft").Text = 5 - RunNo
Case Else
DialogSheets("Navigation Bar").EditBoxes("NoOfRunsLeft").Text = 0
End Select
Select Case RunNo
Case Is = 1
Worksheets("QHistory").Range("Run1").Value = Worksheets("Reports").Range("CurrentData").Value
Worksheets("QHistory").Range("RunNo").Value = 2
Case Is = 2
Worksheets("QHistory").Range("Run2").Value = Worksheets("Reports").Range("CurrentData").Value
Worksheets("QHistory").Range("RunNo").Value = 3
Case Is = 3
Worksheets("QHistory").Range("Run3").Value = Worksheets("Reports").Range("CurrentData").Value
Worksheets("QHistory").Range("RunNo").Value = 4
Case Is = 4
Worksheets("QHistory").Range("Run4").Value = Worksheets("Reports").Range("CurrentData").Value
Worksheets("QHistory").Range("RunNo").Value = 5
Case Is = 5
Worksheets("QHistory").Range("Run5").Value = Worksheets("Reports").Range("CurrentData").Value
Worksheets("QHistory").Range("RunNo").Value = 6
66
Case Else
MsgBox ("You are only allowed 5 History Files to find an Average. Thank You")
End Select
End Sub
Sub SetNoOfRuns()
Dim RunNo As Single
RunNo = Worksheets("QHistory").Range("RunNo").Value
Select Case RunNo
Case 2 To 5
Case Else
DialogSheets("Navigation Bar").EditBoxes("NoOfRunsLeft").Text = 0
End Select
End Sub
Sub ExitSimulation()
'
' ExitSimulation Macro
' Macro recorded 03/03/99 by Shivan Mohd
'
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "The Workbook will now Close and Save all changes!Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Exit Simulation" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Thank You for using this Package." ' Perform some action.
Workbooks("Queuing Simulation.xls").Close Savechanges:=True
Else ' User chose No.
MyString = "No" ' Perform some action.
End If
End Sub
Sub About()
'
' About Macro
' Macro recorded 11-11-98 by Shivan Mohd
'
DialogSheets("About").Show
End Sub
Sub PrintInputs()
'
' PrintSelection Macro
' Macro recorded 04/03/99 by Shivan Mohd
'
'
67
Application.Goto Reference:="Inputs"
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True
Worksheets("Inputs").Range("A1").Select
End Sub
Sub Printreports()
'
' PrintSelection Macro
' Macro recorded 04/03/99 by Shivan Mohd
'
'
Application.Goto Reference:="Reports"
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True
Worksheets("Reports").Range("A1").Select
End Sub
Sub PrintProbTables()
'
' PrintSelection Macro
' Macro recorded 04/03/99 by Shivan Mohd
'
'
Application.Goto Reference:="ProbTables"
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True
Worksheets("Observed Prob").Range("A1").Select
End Sub
Sub PrintHistory()
'
' PrintSelection Macro
' Macro recorded 04/03/99 by Shivan Mohd
'
Application.Goto Reference:="History"
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True
Worksheets("QHistory").Range("A1").Select
End Sub
Sub PrintGraphs()
'
' PrintSelection Macro
' Macro recorded 04/03/99 by Shivan Mohd
'
'
Application.Goto Reference:="Graphs"
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True
Worksheets("Graphic reports").Range("A1").Select
End Sub
Sub Resettables()
'
' Resettables Macro
68
' Macro recorded 20/10/1999 by Shivan Mohd
Range("B3:C13,F3:G13").Select
Range("F3").Activate
Selection.ClearContents
Range("B3").Select
ActiveCell.FormulaR1C1 = "0"
Range("C3").Select
ActiveCell.FormulaR1C1 = "0"
Range("F3").Select
ActiveCell.FormulaR1C1 = "0"
Range("G3").Select
ActiveCell.FormulaR1C1 = "0"
Range("B3:C3").Select
Selection.AutoFill Destination:=Range("B3:C13"), Type:=xlFillDefault
Range("B3:C13").Select
Range("F3:G3").Select
Selection.AutoFill Destination:=Range("F3:G13"), Type:=xlFillDefault
Range("F3:G13").Select
End Sub
Sub hide()
'
' hide Macro
' Macro recorded 01/07/99 by Shivan Mohd
'
Rows("12:12").Select
Selection.EntireRow.Hidden = True
Rows("12:12").Select
Selection.EntireRow.Hidden = False
End Sub