You are on page 1of 77

QUEUEING SIMULATION USING EXCEL 2000

A Mini-Study Project presented to the Graduate School of


Business of the University of Stellenbosch in partial
fulfilment of the requirements for the degree of

Masters Degree in Business Administration (MBA)

by
Shivan Mohd

Study Leader

: Professor WR Gevers

Degree of Confidentiality

: Grade A

Date

: October 1999

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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

CHAPTER 2. QUEUING THEORY: A QUICK OVERVIEW

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

CHAPTER 3. THE LOGIC OF THE MODEL PRESENTED

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

CHAPTER 4. VERIFICATION OF MODEL

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

Stellenbosch University http://scholar.sun.ac.za

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

CHAPTER 6. SUMMARY AND RECOMMENDATIONS

29

6.1 SUMMARY
6.2 RECOMMENDATIONS

29
29

LIST OF SOURCES

30

APPENDIX A :LIST OF ROUTINES AND THIER FUNCTIONS

31

APPENDIX B: LIST OF SCREENS

33

APPENDIX C: VISUAL BASIC CODE

43

Stellenbosch University http://scholar.sun.ac.za

viii
LIST OF TABLES
Table 2.1: Examples of queues

Table 3.1: Sequence of events

11

Table 4.1: Inputs for comparison

14

Table 4.2: Comparison of results

14

Table 4.3: A sample of the details table

15

Table 4.4: Input time versus simulated time

16

Table 4.5: Statistical comparison

16

Stellenbosch University http://scholar.sun.ac.za

ix
LIST OF FIGURES
Figure 5.1: Welcome Screen

19

Figure 5.2: Control Centre

20

Figure 5.3: Input Screen

21

Figure 5.4: Inter-arrival Input Box

23

Figure 5.5: Service Inputs

24

Figure 5.6: Probability Table

25

Figure 5.7: History Screen

26

Stellenbosch University http://scholar.sun.ac.za

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?

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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

2.2.1 The customers and their source


Customers are defined as those in need of service. Customers can be people, aeroplanes,
machines or raw materials. The customers are generated from a population (calling population)
or a source. The population source may be from an infinite or a finite source. For example, a
hospitals population would be residents in the surrounding community and the customers would
be those sick people in the population requiring hospitalisation.
2.2.2 The arrival process
The manner in which customers show up at the service facility is called the arrival process. The
distributions of the inter-arrival time may be exponential, constant etc. The average service time
per server is different from the average inter-arrival time, as the two processes are independent
of each other. When describing a waiting system, the manner in which customers or the waiting
units, are arranged for service, must be defined. Waiting line formulas generally require an
arrival rate, or the number of units per period (such as 10 units per hour). The time between
arrivals is the inter-arrival time (such as an average of one every six minutes) or, the reciprocal
of the arrival rate.

Stellenbosch University http://scholar.sun.ac.za

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.

2.2.3 The service facility and service process


The service is provided by a service facility (or facilities). The service facility may be a person
(bank teller, a barber, machine (elevator, gasoline pump), or space (airport runway, parking lot,
hospital bed), to mention just a few. A service facility may include one person or several people
operating as a team.
Facilities may be fixed (Loading dock) or movable (service technician). The service time may
also follow various distribution patterns, exponential etc.
In elementary models, the exponential distribution is assumed.
2.2.4 The Queue
Whenever an arriving customer finds that the service facility is busy, a queue or waiting line is
formed. Examples of Systems, Queues formed and the Service provided may be found in Table
2.1.

Stellenbosch University http://scholar.sun.ac.za

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

2.2.5 Degree of patience


A patient client is one who waits as long as necessary until the service facility is ready to serve
him or her. (Even if clients grumble and behave impatiently, the fact that the customers wait is
sufficient to label them as patient clients for purposes of waiting line theory.)
There are two classes of impatient clients. Members of the first class arrive, survey both the
service facility and the length of the line, and then decide to leave. Those in the second class
arrive, view the situation, join the waiting line, and then, after some period of time, depart.
The behaviour of the first type is termed balking, while the second is termed reneging.
The program does not cater for impatient behaviour.
2.3 SUMMARY
The understanding of queuing theory is fundamental, when trying to apply the concepts to
simulate an environment. Understanding waiting lines or queues and learning how to manage it,
is one of the most important areas in operations management. Simulation will aid management
in this understanding. It is basic to creating schedules, job design, inventory models and so on. In
a service economy people wait in line every day, from driving to work to checking out at the
supermarket. Management can reduce the amount of time spent in a queue by applying the
concepts of queuing theory.

Stellenbosch University http://scholar.sun.ac.za

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

3.2.1 Unit of time


The unit of time may be Minutes, Hours or Days. Once the user uses either one of these options,
the program will use that unit of time for both the arrival and the service calculations.

3.2.2 The duration of the simulation


The duration of the simulation pertains to the length of time the simulation should run. For
example: 25 will equal 25 Days if the Unit of time is days. The longer it is set the longer the
simulation will take to run. Normally a longer run will give an answer closer to that of the
analytical models. If, for example, the simulation run time is set for 10 min and the arrival rate is
one per minute, the program will return approximately 10 observations.

3.2.3 The number of servers


The number of servers that are used or that will be used is required. The option allows the user
to change from a single server environment to a multi-server environment with all servers
rendering an identical service.

Stellenbosch University http://scholar.sun.ac.za

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.

3.2.5 The arrival rate


The average arrival rate will be in the form of e.g. seven per time of unit. It means that if the
customers arrive at a rate of 7 every hour (time unit) then the inter-arrival time will be 1/7 =
0.143 hours between arrivals, and this is the number placed in the input box. The average interarrival time is automatically converted to an arrival rate, which is reported to the Input Screen.
The inter-arrival time 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 inter-arrival probabilities table. The inter-arrival time is then used in the simulation process.

The distribution pattern of the inter-arrival times may be:


Exponential
Constant
Normal
Triangular
Or Observed probabilities

Stellenbosch University http://scholar.sun.ac.za

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:

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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

Description of what it does

Gathers the users input parameters from


the Inputs worksheet.

Starts the Initialize Routine

RunSimulation
RunSimulation

Start a loop until the simulation time has


expired as per the users input.
Starts the Timing Routine

Start the UnpdateAreas Routine


Check to see if this time is an arrival
event or a departure event.
If it is an arrival event then run the Arrive
Routine
Starts the Arrive Routine

Sub Routine

Description of what it does

Initialize

Re sets the simulation parameters to Zero.


Sets the worksheet parameters to Zero
Calculates the First Arrival based on the users input
e.g. Exponential, Normal etc

Timing

UpdateAreas

Determine whether the time is an arrival or a


departure event.
Update the Clock to the time of the next event

Arrive

RunSimulation

If the Event was a departure event then

Update statistical accumulators and writes results to


the reports worksheet

Checks the input sheet for which distribution pattern


to use
Once found, it calculates the random time of the next
event
Check to see if the number in queue is within the
maximum allowed in the queue. If above the amount
of customers allowed then the programme records
the arrival as a lost customer.
Check if all servers are busy, and if so, put the time
at the end of the queue. If not, then put the
customers directly into service.
Before it can place a customer in service, it searches
for the first available server by starting from server
number one and progressing upwards towards the
last server.
Once in service it now calculates a random service
time
Write the information to the detailed report sheet.

Stellenbosch University http://scholar.sun.ac.za

12
run the depart routine.

Depart

RunSimulation

RunSimulation
RunSimulation

RunSimulation

RunSimulation

Loop until the simulation reaches the


end of the time stipulated.
Run the Check Routine
Run the finishoff Routine
Run the Averages Routine

Run the Queuelength Routine

Run the Buildreport Routine

RunSimulation

Run the Report Routine

RunSimulation

Run the CreateChart Routine

RunSimulation

Select the Reports worksheet


Close the Control panel dialog box.

Check

Update the number of customers who finished


Check if any customers are in queue, if not, then
make the server available else take the customer
into service
If taken into service, schedule a departure for the
customer, based on the chosen service distribution
pattern.
Move everyone else up in the queue.

Fills any blanks with zeros within the worksheets.

Averages

Queuelength

Calculates the number of customers waiting in line


at a particular point in time.

Buildreport

Copies the details sheet


Renames the copy
Adds data from other sheets
Format the copy into a presentable format

Report

Builds the report sheet

CreateChart

Creates a chart based on the percentages reported


in the report sheet

Finishoff

Format the sheets to make it look presentable


Based on the previously generated information the
average times are calculated and presented in form
of a summary

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.

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

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

Average Service time per


server
Number of servers
Traffic intensity
Units
Duration of run

Run2

Run3

Run5
0.27

Table 4.2: Comparison of results


Outputs

Run1

Run2

Run3

Run4

Run5

Average Time in Queue


Analytical

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

Average Number in Queue

11.277

Stellenbosch University http://scholar.sun.ac.za

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

Inter-Arrival Clock Time Of


Time
Arrival

Clock Time Server Number To


Perform The
Service Starts

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.

Stellenbosch University http://scholar.sun.ac.za

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.

Table 4.5: Statistical comparison


Description

Average Time
Sample Size
Standard Deviation
Significance Level
Confidence Interval
High
Low

Inter-Arrival Time Service Time

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

Stellenbosch University http://scholar.sun.ac.za

17
seems to be simulated correctly.

An alternative statistical test would have been to do a

goodness-of-fit test on the observed simulated times.

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.

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

19
5.3 CONTROL CENTRE

Figure 5.1: Welcome Screen


Press the button to activate the central control menu.
After clicking the Central Control Menu button the following Figure 5.2 appears:

Stellenbosch University http://scholar.sun.ac.za

20

Figure 5.2: Control Centre


The control centre screen is divided up into two main sections:
Action buttons: These buttons are used to start a process
Navigation buttons: These buttons are used to navigate from screen to screen.
On the Control Panel a indicator box called Number of History Space Left shows the number
of spaces the user has left to record simulated results. For example, if the box displays the
number 3, it means that the user may save three more models out of a total of five saves.

Stellenbosch University http://scholar.sun.ac.za

21
5.4 ACTIONS BUTTONS

5.4.1 Change Inputs Button


The Change Inputs Button is used when the user wants to edit the current data used by
the program to run the simulation. After the change inputs button is pressed, Figure 5.3
appears on the screen.
The information button presents information as to what is required by the input boxes.

Figure 5.3: Input Screen


The input screen requires the following information:
a) The unit of Time
The unit of time option allows the user to select the time unit he/she would prefer to use when
running the simulation.
The options are:
Minute
Hour

Stellenbosch University http://scholar.sun.ac.za

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).

Stellenbosch University http://scholar.sun.ac.za

23

Figure 5.4: Inter-arrival Input Box


The screen above is the Inter-arrival Input Screen. In the Figure 5.4, the following must be
updated.
e) Input the inter-arrival time
If customers arrive at a rate of 12 per hour, then find the reciprocal of 12 to get the inter-arrival
time i.e. 1/12 =0.0833 hours or 5 minutes, is the number entered in the box. The time is used to
simulate the environment specified by the user.
f) Select a distribution pattern.
Different distribution patterns are selected for the inter-arrival times. The following options are
available:
Exponential
Constant
Normal
Triangular
Observed Probability
The Observed Probability option is important as the program will check this parameter and do
the calculations based on the distribution pattern specified.
Once the relevant data has been entered, click the continue key and the following service inputs
screen will appear (Figure 5.5):

Stellenbosch University http://scholar.sun.ac.za

24

Figure 5.5: Service Inputs


In the Service Inputs screen the user will select the following
g) Input the average service time per server
If customers are serviced at a rate of 6 per hour, then find the reciprocal of 6 to get the service
time per server i.e. 1/6 = 0.166 hours or 10 minutes, is the number entered in the box. Time is
used to simulate the environment specified by the user.
h) Select a distribution pattern.
Different distribution patterns for the average service time per server are the same as the options
for the inter-arrival rate (see point f). Once the appropriate distribution pattern has been
selected, press the "Continue"-button. The input screens for changing or adding data are now
complete. The user will be returned to the last screen he/she was viewing.
5.4.2 Run Simulation Button
The "Run Simulation"-button initiates the simulation process. The program will effectively
calculate all relevant information and post it to the different sheets. (See Program Logic).

Stellenbosch University http://scholar.sun.ac.za

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.

Figure 5.6: Probability Table


Probability: Add the relevant probability in relation to the average Inter-arrival or Service time.
Specific Inter-arrival / Service time: Add the inter-arrival or service time to the corresponding
probability.
Note: the cumulative probability must add to the value one. If not, the program will not run.
The program checks the cumulative probability of both the Arrival and Service times. If either of
the two probabilities of times do not add to one, the program stops and returns to the Probability
Table screen (Figure 5.4), so that the user may make the appropriate amendments. If a value is
entered in the average inter-arrival time box (Paragraph 5.4.1, point e), the program will ignore
the value and replace it with the average of the inter-arrival times, which is shown in the arrival
probability table in Figure 5.6. The average will be shown in Input Screen, however it will not be
used in the simulation program. Only inter-arrival times calculated by generating random
numbers, and finding the corresponding time, in the probability table, will be used.

Stellenbosch University http://scholar.sun.ac.za

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.

Figure 5.7: History Screen


5.4.5 Clear History Button
The Clear History button is used to clear all the data on the history screen.
5.4.6 Restore and Hide Buttons
The Restore and Hide buttons are used to hide or show all the toolbars, statuss bars etc. The
restore/hide feature allows the user to have access to the model, so that changes can be made to
the model.

Stellenbosch University http://scholar.sun.ac.za

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.

b) The Input Screen


The Input screen shows all the relevant inputs used for the simulation program except for the
observed probabilities.

c) The Report Screen


The Report screen shows the following information:
User statistics
System orientated statistics
Probability distribution of number in queue.
d) The History Screen
The History screen shows a list of up to five saved simulated runs.

e) The Chart Screen


The Chart screen shows the results in form of charts

f) The Probability Chart Screen


The Probability Chart screen shows one chart that represents the probability distribution of the
number of customers in the queue.

Stellenbosch University http://scholar.sun.ac.za

28
g) The Detailed Results Screen
The Detailed Results screen shows information about each customer and each server.

h) The Summary Screen.


The Summary screen shows a summary of the server idle time and the average customer waiting
time.

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.

Stellenbosch University http://scholar.sun.ac.za

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.

The model allows a user to run many variations of an

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!

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

31

APPENDIX A: LIST OF ROUTINES AND THEIR FUNCTIONS

Stellenbosch University http://scholar.sun.ac.za

32

LIST OF ROUTINES AND THEIR FUNCTIONS

Visual Basic Routine


ServDist_Change

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

The routing calls up the input boxes for the program


It is the main routine that will run the simulation and call other routines to
accomplish the end result
Finishoff
The routine does some formatting for presentation
Averages
It creates the averages for the work stations in form of a pivot table in the
summary sheet
Check
Checks for blanks and fills it with Zeros
Initialize
Resets the sub routine parameters to zero start a new simulation
Timing
Finds the most imminent event and record the server that has just finished
Arrive
Calculates the Arrival time
Depart
Calculates the Departure Time
Report
Creates the Report Sheet
UpdateAreas
Updates the report sheet
Buildreportsheet
Creates the final details report sheet
Queuelength
Determines the queue length and inserts it in the appropriate spread sheet
Auto_Close
Runs when Excel closes. It restores the Excel sheets
Auto_Open
Runs when Excel Opens. It removes toolbars starts sets the environment
GoToReport
Takes the user to the Report sheet
CreateChart
Creates the probability chart
GoToInputs
Takes the user to the Inputs sheet
GeneralInputs
Inserts the users inputs into the sheets
ArrivalInputs
Inserts the arrival inputs
ServiceInputs
Inserts the Service inputs
MaxInQueue_AfterUpdate Calls an information box
GoToCharts
Takes user to the chart sheet
GoToHistory
Takes user to the History sheet
ClearHistory
It clears the history sheet to enable new data to be inputted
AddToHistory
It adds data that has been recently run to the history sheet
SetNoOfRuns
Sets the number of runs in the history sheet
PrintInputs
Prints the Inputs spread sheet
PrintReports
Prints the Reports spread sheet
PrintProbtables
Prints the Probability table spread sheet
PrintHistory
Prints the History spread sheet
PrintGraphs
Prints the Graphs spread sheet
ArrDist_Change
Shows or hides information which is appropriate or not appropriate at the time
of running the simulation

Stellenbosch University http://scholar.sun.ac.za

33

APPENDIX B: LIST OF SCREENS

Stellenbosch University http://scholar.sun.ac.za

34

LIST OF SCREENS
B.1 WELCOME SCREEN

Figure B.1: Welcome Screen


a) The Purpose of this screen
The Welcome Screen is the default introductory screen, which serves as an introduction screen.
By clicking on the Central Control Menu Button, the user may navigate to any other screen
within the application.
b) How to interpret the information on the screen
The Welcome Screen has no use, other than informing the user of:
The title of the package
The program used
The writer of the program.

Stellenbosch University http://scholar.sun.ac.za

35
B.2 INPUTS SCREEN

Figure B.2: Inputs Screen

a) The Purpose of this screen


The Inputs Screen shows the inputs that will be used by the program for simulation purposes.
b) How to interpret the information on the screen
The user can use the screen for:
To check that the information used is as per the environment simulated.

Stellenbosch University http://scholar.sun.ac.za

36
B.3 REPORTS SCREEN

Figure B.3: Reports Screen


a) The Purpose of this screen
The Reports Screen shows some of the outputs generated by the program.
b) How to interpret the information on the screen
Under the sub headings of the screen the following information can be used:
User Statistics
The user statistics information pertains to the individual i.e. the customer (See 2.2.1). It will help
in determining how the queuing environment affects the customer. All these results must be
minimised if possible.
Queue orientated statistics
The queue orientated statistics information pertains to the queue that is formed within the
environment. That the information supplied is concerning the queue and not the entire system.

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

38

B.4 MULTI-GRAPH SCREEN

Figure B.4: Graphical representation of Results


a) The Purpose of this screen
The Graphical representation of Results screen shows some of the outputs generated by the
program in graphical format.
b) How to interpret the information on the screen
The Graphical representation of Results screen is useful for those users who like a quick
overview (feel) of the results. In the example above (Figure B.4, top, right graph), the vast
difference between the maximum customers in the queue and the average number in the queue
can be seen. It will help in formulating the size of the area, which should be provided for the
queue.

Stellenbosch University http://scholar.sun.ac.za

39
B.5 GRAPHICAL DISTRI BUTION SCREEN

Figure B.5: Graph of Distribution Pattern


a) The Purpose of this screen
The Graph of Distribution Pattern screen shows some of the outputs generated by the program in
graphical format.
b) How to interpret the information on the screen
The Graph of Distribution Pattern screen is useful for those users who like a quick overview
(feel) of the results. In this example, just over 60% of the people will not have to queue in this
particular environment.

Stellenbosch University http://scholar.sun.ac.za

40
B6. DETAILS SCREEN

Figure B.6: Detail Screen


a) The Purpose of this screen
The Detail Screen shows some of the detailed outputs generated by the program. Note that the
user will have to scroll to the right to get to the Central Control Panel.
b) How to interpret the information on the screen
The Detail Screen presents the following information about the Queue:
Customer Number
It shows the customer number in the sequence of arrival.
Inter-arrival time
It shows the randomly generated inter-arrival time generated by the program
Clock time of arrival

Stellenbosch University http://scholar.sun.ac.za

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.

Stellenbosch University http://scholar.sun.ac.za

42
B.7 AVERAGES SCREEN

Figure B.7: Averages Screen


a) The Purpose of this screen
The Averages screen shows the averages of the simulated data, which was generated by the
program.
b) How to interpret the information on the screen
The user can quickly see when more servers are added, the idle time increase as the number of
servers is increased.

Stellenbosch University http://scholar.sun.ac.za

43

APPENDIX C: VISUAL BASIC CODE

Stellenbosch University http://scholar.sun.ac.za

44

VISUAL BASIC CODE


Option Explicit
Option Base 1
'Define all the variables that will be used across routines
Dim i As Integer
Dim Nextcell, numberoftoolbars As Single, Nextcust As Integer, serverno As Integer, timingcount As Single
Dim AvgDelay, AvgNumInQ, StdDevArrive, StdDevService, Randomnum, MostLikelyValue, _
MinimumValue, ServiceSeq, MaximumValue, StdCArrive, StdCService, ValA, ValB, ServDist, ArivDist As
Double
Dim MaxInQ As Integer
Dim NextEventType As Integer, NumInQ As Integer, _
NumCusts As Long, NumBusy As Integer, _
numservers As Integer, FinishedServer As Integer, _
MaxInSys As Integer, NumLost As Integer
Dim AreaNumInQ As Single, AreaUtil As Single, MaxDelay As Single, _
TimeArrival(1000) As Single, Time As Single, TimeLastEvent As Single, _
TotDelays As Single, TimeNextEvent() As Single
Dim TimeInQ(0 To 1000) As Single
Dim MeanArriveTime As Single, MeanServeTime As Single, _
MaxTime As Single
' Calculate the steady-state probability that no customers are in the
' system - this is needed for the steady-state outputs shown on the
' Report sheet
Function ProbEmpty(arrivetime As Single, servetime As Single, _
numservers As Integer) As Single
Dim Sum As Double, Product As Double, i As Integer, _
Traffic As Single
Traffic = servetime / (numservers * arrivetime)
If numservers = 1 Then
ProbEmpty = 1 - Traffic
Else
Product = 1
Sum = 1
For i = 1 To numservers - 1
Product = Product * numservers * Traffic / i
Sum = Sum + Product
Next
Product = Product * Traffic / (1 - Traffic)
Sum = Sum + Product
ProbEmpty = 1 / Sum
End If
Worksheets("reports").Range("probempty").Value = ProbEmpty
End Function
Sub GetInputs()
Dim ArriveRate As Single, arivedist, servdist, arrivedist1 As Single, ServeRate As Single
Dim MaxTime As Single, numservers As Integer
Dim MaxInSys As Integer, timeunit As String
Dim checkforo As Single
Worksheets("Inputs").Range("ArriveTime").Value = 0
Worksheets("Inputs").Range("serveTime").Value = 0
'call msg boxes
DialogSheets("QGeneral Inputs").EditBoxes("NoOfUnits").Text = 0
DialogSheets("QGeneral Inputs").EditBoxes("NumService").Text = 0
DialogSheets("QGeneral Inputs").EditBoxes("MaxInQueue").Text = 0

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

If arivedist = 5 Or servdist = 5 Then


Worksheets("Observed Prob").Select
Dim checking As Single
checking = Worksheets("Observed Prob").Cells(14, 2).Value
If checking < 1 Then
If checking = 0 Then
Else
MsgBox "You have selected the 'Observed Probabilities' as your distribution, however the arrival
probability total must add up to one. Please correct any errors."
Worksheets("Observed Prob").Cells(3, 2).Select
DialogSheets("Navigation Bar").hide ' hide bar
Exit Sub
End If
Else
If checking = 1 Then
Else
MsgBox "You have selected the 'Observed Probabilities' as your distribution, however the arrival
probability total must add up to one. Please correct any errors."
Worksheets("Observed Prob").Cells(3, 2).Select
DialogSheets("Navigation Bar").hide ' hide bar
Exit Sub
End If
End If
checking = Worksheets("Observed Prob").Cells(14, 6).Value
If checking < 1 Then
If checking = 0 Then
Else
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
Else
If checking = 1 Then
Else

Stellenbosch University http://scholar.sun.ac.za

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

'get user inputs from Inputs screen


Application.ScreenUpdating = True
With Worksheets("Inputs")
MeanArriveTime = .Range("ArriveTime").Value
MeanServeTime = .Range("ServeTime").Value
numservers = .Range("NumServers").Value
MaxInSys = .Range("MaxInSys").Value
MaxTime = .Range("MaxTime").Value
End With
ReDim TimeNextEvent(numservers + 1)
Nextcell = 1
Initialize
Do
Nextcell = Nextcell + 1
Timing ' Find the time, type of next event, reset clock
UpdateAreas ' Update statistical accumulators
If NextEventType = 1 Then
Arrive ' subroutine for an arrival
Else
Depart ' subroutine for a departure (service completion)
End If
' Cut off all future arrivals if store's doors have closed
If Time > MaxTime And TimeNextEvent(1) < 100000 Then
TimeNextEvent(1) = 100000
End If
Loop Until Time > MaxTime And NumBusy = 0
check ' fill blanks with zero's
finishoff ' format table
Averages ' find averages
queuelength ' find queue length
buildreportsheet ' biuld detail table

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

49

'calculate server delay


Worksheets("table2").Select
Dim myRange As Single
myRange = 2 + NumCusts
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"Table2!R2C11:R" & myRange & "C12", TableDestination:= _
"'[Queuing simulation New.xls]Summary'!R7C1", TableName:="PivotTable"
ActiveSheet.PivotTables("PivotTable").AddFields RowFields:="Server Number"
ActiveSheet.PivotTables("PivotTable").PivotFields("Idle Time of Each Server").Orientation _
= xlDataField
ActiveSheet.PivotTables("PivotTable").ColumnGrand = False
ActiveSheet.PivotTables("PivotTable").PivotFields("sum of Idle Time of Each Server"). _
Function = xlAverage
Cells.Select
Selection.Interior.ColorIndex = 43
Columns("A:A").Select
Selection.Font.Bold = False
Selection.Font.Bold = True
Columns("B:B").Select
Selection.Font.ColorIndex = 6
Selection.Font.Bold = False
Selection.Font.Bold = True
Range("A1").Select
Columns("A:A").EntireColumn.AutoFit
Columns("A:A").Select
Selection.Font.ColorIndex = 2
Worksheets("table2").Select
Range("A1").Select

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()

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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)

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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)

If Delay > MaxDelay Then


MaxDelay = Delay
End If
TotDelays = TotDelays + Delay
AvgDelay = TotDelays / NumCusts
'Worksheets("Reports").Range("AvgDelay").Value = AvgDelay
'Worksheets("Reports").Range("MaxDelay").Value = MaxDelay
' Schedule departure for this customer with the same server who just
' finished
ServiceSeq = 2
i=2
'Determine the Service Distribution
'schedule an Service based on users input
servdist = Worksheets("Inputs").Range("ServDist").Value
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
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
meanarrivetime2 = MeanServeTime
MeanServeTime = Application.WorksheetFunction.NormInv(Randomnum, StdDevService,
MeanServeTime)

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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", _

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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()

Stellenbosch University http://scholar.sun.ac.za

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()

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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
'
'

Stellenbosch University http://scholar.sun.ac.za

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

Stellenbosch University http://scholar.sun.ac.za

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

You might also like