Your are to write a bank ATM simulation program in C++. The simulation's purpose is to determine the average waiting time for customers using the ATMs. This assignment is worth 3% of your final grade.
Start by downloading the assignment files. This
zipfile contains a makefile, a test script and inputs/ground truths,
and stubs for all of the .h and .cpp files you need. Please do not
create any additional .h and .cpp files.
There are three inputs to the program:
For example, if the input is:
10 4 5 0 2 0 1 1 4 2 2 2 7Then we are simulating 4 ATMs over a 10 minute period. 5 customers arrive, at time 0 (transaction time 2), at time 0 (transaction time 1), ...
A customer who arrives in minute n chooses an ATM in minute n, and could conduct business on minute n+1. E.g. the customer who arrives in minute 0 with 2 minutes of transaction time would choose an (empty) ATM on minute 0, and work on minutes 1 and 2.
Customers must be processed in the order specified in this list (e.g. the transaction time 2 customer at time 0 should be processed before the transaction time 1 customer).
For your convenience, code is provided to read input in this format, as well as produce output in the required format.
You should not use M and N as variable names in your program, uses some other, more descriptive name starting with a lower case letter.
Different customers may spend different amounts of time at the ATM,
one customer may just want to make a quick withdrawal, while another
(always the one you get stuck behind when you are in a hurry) may want
to do his / her entire banking for the last three months.
Whenever a customer arrives he/she should be assigned to an ATM queue. We will assume the customers are rational, want to wait for as little time as possible, but don't know how long other customers are going to take. Therefore if an ATM is free (i.e. there is no one using it) a customer will go to that ATM (or one of the other available ATMs if there is more than one), otherwise the customer will go to the ATM with the smallest lineup (queue).
If there is a tie, the customer always chooses the lowest numbered ATM. E.g. if there are 3 ATMs, numbered 0-2, and ATM 0 has 2 customers waiting, and ATMs 1 and 2 have no customers waiting, ATM 1 will be chosen.
Customers do not switch queues once they have chosen one, even if
another ATM becomes available.
Treat each minute as a discrete event (i.e. minutes should not be further divided into seconds).
When the simulation reaches M minutes no more new customers should be accepted. However, the simulation should continue until all the customers who were at an ATM or waiting in an ATM queue at M minutes have completed their transactions.
For each simulation you should output the total number of customers and the average wait time. Please use the provided code for the output.
The simulation program atm_sim should return the total wait time
for all customers over the simulation. This is done in the main function
provided (in atm_sim.cpp).
The simulation control loop (which would be in, or called from, the main function) can be written as a while loop like this:
while (min < M or there are still customers to process) // Process new customers if (min < M and new customers arrive - based on list) for each new customer assign customer to shortest queue increment customer count // Process ATMs for (i = 0 to N) process each ATM (see below for more details) and increment wait time increment min output statistics
Note that the above is not written in a programming language, it is
just a pseudocode description of what I expect your main loop to be
doing.
Here are some thoughts about what data you will need to keep track and where:
The top level program needs to contain the main simulation loop (described above). It also needs variables for M and N (not called M and N). In addition you will need to record the following:
Note that you may want to use functions in the main program to break the program into easily manageable pieces
Each ATM needs to keep track of data related to it, that is:
You may also want to record some other attributes in the ATM class
You should create an ATM class with the member variables noted above, and appropriate methods to set and retrieve values for those variables. The class methods will probably include the following:
The following needs to be performed to process an ATM's customers
if (ATM is in use) decrement transaction time of its current customer by 1 if (current customer is finished) remove the customer at the front of the queue set the ATM's remaining transaction time to that customer's transaction time increase the ATM's total wait time by the time that the customer waited (current time - arrival time)
You should create a customer queue class to record data required for waiting customers. This data consists of:
Your queue must be implemented using a linked list, and the insert and remove methods must run in constant (O(1)) time.
The zipfile contains a testing script, test.py. You should run this, and other test cases, to verify correctness of your simulation.
As you are developing and testing your application you may find it
useful to print some data about the current contents of the ATMs, for
example:
You should submit your assignment online to the CourSys submission server. You should submit the following:
Please read the documentation on the submission site for further information. The assignment is due at 11:59pm on Friday February 8.