BU CAS CS 113
Introduction to Computer Science II with Intensive C
Fall 1997


Assignment 6: Simulations with Queues


Last Modified: Wed Nov 5 07:36:00 1997

Deadline

November 13, 1997

What to Submit

You should submit one file. Be sure the files you submit have exactly the following names: 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.

Queue Simulation

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.

Data files

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.

Input

Your program should prompt the user for the following information (in this order):

Output

Your program should display a table containing the following data.
  1. name of data file,
  2. time (start time, end time, total time),
  3. the numbers of queues used in simulation,
  4. number of customers
  5. arrival rate (number of customers/total time),
  6. the average service time for customers,
  7. the average wait for customers,
  8. the time and length of the longest wait by a customer (excluding service time), and
  9. the average queue length,
  10. the number of customers waiting in the queues when the simulation ends,
  11. percent idle time (idle cashier time/total 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.

Hints, Suggestions, Requirements

  1. Your simulator should be independent of the implementation of the queues. I should be able to link your hw6-sim.c with any implementation of queue.h and get a working program.
  2. The code from the book is different in several ways. Outline how you will make the following (and other) changes to that code before you begin programming.
  3. You do not have to write code for the queues. Be sure the line
     
         #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*.
  4. The main program should probably include a loop which ticks off the time units one by one. There is an example of this in Programming Abstractions in C [Roberts] but only for 1 queue and with slightly different statistics. You would be wise to read the text and then modify the code from the textbook, which you can get online.
  5. Finally, note that your program is really quite general. It could be used without modification to handle a wide variety of scheduling simulations, such as the effect of having various numbers of printers on your network, or toll booths on the highway, etc.

Makefile

To check that your assignment compiles correctly, use the Makefile for this assignment:
  1. Copy this Makefile into the directory where your programs are.
  2. Name it Makefile.
  3. type: make -k. (The -k means "keep going", which instructs make to build as much as it can, rather than quit after the first error.)

Academic Honesty and Collaboration

It is reasonable to discuss with others possible general approaches to problems. It is unreasonable to work together on a detailed solution, to copy a solution, or to give away a solution. If your common discussion can be detected by looking at the solutions, then there is too much collaboration. Such instances of academic dishonesty may result in a course grade of F or expulsion from Boston University.

Do not allow your work to be used by others:

Warning: If someone cheats by using your work, you will also be penalized.