hw6-sim.c
.
This is largely an exercise in two things: using abstract data types
(you don't have to implement any ADTsfor this assignment), and modifying
existing code (probably the most common programming task in the "real world").
There is a long example of using queues for simulation in the textbook,
and you will probably want to download the
code from the textbook,
which you can get online.
These programs are to be electronically submitted by using the submit program on csa. The code you submit should conform with the program assignment guidelines.
There are many situations where people "queue up" (or as American usually say, "stand in line"). In some situations--like at the grocery checkout or highway tollbooth--customers may have a choice of queues to join, and then wait in that queue until they are served. Customers generally want to choose the line that will result in the shortest wait time. Unfortunately, they cannot usually tell which line will have the shortest wait, so they choose based on some other criteria (like the line with the fewest customers), hoping that it will correspond roughly to the shortest wait.
(Some) businesses and agencies are also interested in reducing the time their customers spend in line. The easiest way to do this is to provide more queues (i.e., more cashiers, more toll booth operators). Of course, if they provide too many, then they will have to pay employees who are just standing around waiting for customers to come (because they are serving an empty queue). This is sometimes referred to as idle time Since there is a trade-off between prompt service (and corresponding customer satisfaction) and the cost of providing extra queues, a business may wish to analyze the effects of various numbers of queues both on the customers and on costs.
Imagine for sake of concreteness that you are managing a grocery strore. You have up to 10 lines which you can open. You can generate data by random methods or collect data on customers at various times throughout the week. Once you have the data, you would like to analyze the effects of opening various numbers of lines. Your task is to write a program which simulates the queues and prints statistics which might be useful in such an analysis.
The data for each customer will consist of two integers corresponding to the arrival time (A) and the service time (S) (in some units) separated by a comma and followed by a semicolon. For example
5, 2;indicates a customer who came at time 5 and required 2 time units to be processed. There is no limit to how many such pairs can be on one line, but the arrival times will be in order, as in the example shown below. You can assume that the format of the input file is correct and that the last item is followed by a semicolon and then the end of file marker. Here is an example:
1, 15; 2, 13; 3, 10; 5, 12; 10, 4; 15, 10; 18, 12; 20, 16; 23, 9;
Assume that each customer selects the queue with the shortest line (least number of customers already in that queue). In the case of a tie, choose the first queue of the shortest length. You may also assume that two customers never arrive at the same time.
This information should be printed in a table of roughly the following format:
File:
number of customers: start time:
customer arrival rate: stop time:
average service time: total time:
number of queues 1 2 3 4 5
percent idle time
ave wait
longest wait
time of long wait
ave queue length
cust in queues at end
(with the values filled in, of course) The exact spacing of the table is
not important, but the columns should line up and the table should be
easy to read. If there is too much data too fit in one table, make multiple
tables (say for 1-5 queues and 6-10 queues). Perhaps you will want only
four data columns in one table if the spacing is better that way.
#include "queue.h"
appears in your file.
(I will set up the Makefile so that it compiles correctly.)
Note that the type of thing stored in a queue is void*.
Makefile.
Makefile.a6,
you will have to use the mv (short for move)
command to rename it by typing
mv Makefile.a6 Makefile
cp command to copy it by typing
cp Makefile.a6 Makefile
make -k. (The -k means "keep going", which instructs
make to build as much as it can, rather than quit after the first error.)
Do not allow your work to be used by others:
Warning: If someone cheats by using your work, you will also be penalized.