COSC 1030: Assignment #3

Simulation Using Queues

Due: 5pm on January 31, 2001



This assignment requires you to develop a simulation program to help determine how many tellers a bank should have.  An incomplete version of the program has already been developed for you.  It can be found in /cs/course/1030/a3/BankSim.java on Ariel.  You must complete the development of this program.

The main class of the program is BankSim. It provides a constructor BankSim(int nTellers, double expectedServiceTime, double expectedInterArrivalTime) that initializes the parameters of the simulation, i.e. sets the number of tellers the bank has, the expected time for serving a customer, and the expected time between customer arrivals.  The service times and inter-arrival times will be generated randomly from a negative exponential distribution having the given expected values.  The methods generateServiceTime() and generateInterArrivalTime() are supplied for this. It assumed that customers that arrive when all tellers are busy will be put in a FIFO queue and wait for their turn (maintain a single queue for all tellers).

The BankSim class also provides a method void run(double stopTime, boolean tracingEvents, boolean tracingStats) for running the simulation and printing statistics. Its parameters determine the time at which the simulation should stop,  whether a trace of all events should be output, and whether a trace of the statistics kept should be output.  The class also includes a main method that can be used to input the parameters and perform a simulation.  It can be used as a test driver.

Here is an example of the output that the program should generate with tracingEvents turned on:

zebra 76 % java BankSim
Number of tellers? 2
Expected service time? 1.5
Expected inter-arrival time? 1.0
Stop simulation at time? 100
Trace events (y/n)? y
Trace statistics (y/n)? n
At time 0.00 customer 1 arrives & service started.
At time 0.80 customer 1 leaves.
At time 1.12 customer 2 arrives & service started.
At time 1.58 customer 2 leaves.
At time 3.54 customer 3 arrives & service started.
At time 3.55 customer 3 leaves.
At time 4.75 customer 4 arrives & service started.
At time 5.59 customer 5 arrives & service started.
At time 5.64 customer 6 arrives & is queued.
At time 5.82 customer 7 arrives & is queued.
At time 6.27 customer 8 arrives & is queued.
At time 6.55 customer 9 arrives & is queued.
At time 6.92 customer 5 leaves.
At time 6.92 customer 6 dequed & service started
...
At time 94.16 customer 86 leaves.
At time 94.16 customer 89 dequed & service started
At time 94.28 customer 88 leaves.
At time 94.28 customer 90 dequed & service started
At time 94.90 customer 89 leaves.
At time 95.83 customer 91 arrives & service started.
At time 96.49 customer 90 leaves.
At time 96.66 customer 92 arrives & service started.
At time 96.99 customer 93 arrives & is queued.
At time 97.04 customer 91 leaves.
At time 97.04 customer 93 dequed & service started
At time 97.47 customer 92 leaves.
At time 98.81 customer 94 arrives & service started.
At time 98.83 customer 95 arrives & is queued.
At time 99.47 customer 94 leaves.
At time 99.47 customer 95 dequed & service started
At time 99.98 customer 95 leaves.
Time: 100.92, CustServed: 94, CustWaiting: 0, AvgWait: 1.11, TellerLoad: 62

Here is a second example of the output that the program should generate with tracingStats turned on:

zebra 120 % java BankSim
Number of tellers? 2
Expected service time? 1.5
Expected inter-arrival time? 1.0
Stop simulation at time? 1000
Trace events (y/n)? n
Trace statistics (y/n)? y
Time: 2.04, CustServed: 1, CustWaiting: 5, AvgWait: 0.00, TellerLoad: 43
Time: 3.43, CustServed: 2, CustWaiting: 5, AvgWait: 0.65, TellerLoad: 46
Time: 3.61, CustServed: 3, CustWaiting: 4, AvgWait: 1.23, TellerLoad: 46
Time: 4.20, CustServed: 4, CustWaiting: 4, AvgWait: 1.53, TellerLoad: 47
Time: 5.12, CustServed: 5, CustWaiting: 4, AvgWait: 1.83, TellerLoad: 47
Time: 6.90, CustServed: 6, CustWaiting: 7, AvgWait: 2.13, TellerLoad: 48
Time: 7.54, CustServed: 7, CustWaiting: 7, AvgWait: 2.34, TellerLoad: 94
Time: 8.45, CustServed: 8, CustWaiting: 6, AvgWait: 2.48, TellerLoad: 89
Time: 8.66, CustServed: 9, CustWaiting: 6, AvgWait: 2.59, TellerLoad: 97
Time: 10.19, CustServed: 10, CustWaiting: 7, AvgWait: 2.65, TellerLoad: 91
...
Time: 986.46, CustServed: 971, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 986.85, CustServed: 972, CustWaiting: 2, AvgWait: 1.37, TellerLoad: 74
Time: 987.23, CustServed: 973, CustWaiting: 2, AvgWait: 1.37, TellerLoad: 74
Time: 987.89, CustServed: 974, CustWaiting: 1, AvgWait: 1.37, TellerLoad: 74
Time: 988.64, CustServed: 975, CustWaiting: 0, AvgWait: 1.37, TellerLoad: 74
Time: 990.42, CustServed: 976, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 993.61, CustServed: 977, CustWaiting: 6, AvgWait: 1.37, TellerLoad: 74
Time: 993.74, CustServed: 978, CustWaiting: 5, AvgWait: 1.37, TellerLoad: 74
Time: 993.86, CustServed: 979, CustWaiting: 4, AvgWait: 1.37, TellerLoad: 74
Time: 994.62, CustServed: 980, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 994.91, CustServed: 981, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 996.33, CustServed: 982, CustWaiting: 4, AvgWait: 1.37, TellerLoad: 74
Time: 996.49, CustServed: 983, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 996.94, CustServed: 984, CustWaiting: 3, AvgWait: 1.37, TellerLoad: 74
Time: 999.39, CustServed: 985, CustWaiting: 5, AvgWait: 1.38, TellerLoad: 74
Time: 999.87, CustServed: 986, CustWaiting: 4, AvgWait: 1.38, TellerLoad: 74
Time: 1000.32, CustServed: 986, CustWaiting: 3, AvgWait: 1.38, TellerLoad: 74

This mode is useful to see whether the simulation has been run long enough for the statistics to stabilize.

The statistics printed by the program are:

  1. CustServed: the total number of customers whose service has been completed,
  2. CustWaiting: the number of customers that are waiting for service in the queue,
  3. AvgWait: the average time served customers have waited before being serviced,
  4. TellerLoad: the average percentage of time that the tellers are busy serving a customer.
The program should do what is called event-driven simulation.  This means that it keeps track of the events that are scheduled to happen.  The system operates by repeatedly getting the next scheduled event, advancing the clock to the time of the event, and updating the state of  the system to reflect the effects of the event.  In the bank simulation, there will be two kinds of events: the arrival of a customer, and the departure of a customer after it has been served.  A class Event has already been defined to represent these kinds of events.  The program should store the scheduled events in a priority queue to make it easy to retrieve the next (earliest) scheduled event.  To help you implement the run method, an algorithm in pseudocode has been provided; see BankSim.java. To implement your priority queue and FIFO queue, use the classes provided in /cs/course/1030/a3/.

In addition to basic testing, you should perform some experiments with your program.  Suppose that the expected inter-arrival time between customers is 1.0 minute and that the expected service time for a customer is 3.5 minutes.  Simulate the system with 4 tellers and 5 tellers.  How many tellers do you think is best?  What if the expected service time for a customer is increased to 3.75 minutes?  What if it is decreased to 3.0 minutes?  Display the statistics you collect for all these situations in a table.

Note that assignments are supposed to represent your own individual work. Do not misrepresent another's work as your own; it will be considered academic dishonesty if you do. If you have any questions about this please ask your course instructor.

Remember to include a copy of the marking sheet supplied as the cover page of your report.


Revised: Nov. 3, 2000