CSC 153 Grinnell College Spring, 2005 Computer Science Fundamentals Laboratory Exercise

# Multiple Clerks in a Store: An Example of Object-Oriented Design

## Goals

This program examines an object-oriented, Scheme-based solution to the following:

### Problem:

Consider a commercial environment where multiple clerks are available to serve customers. There are at least two models for such service:

1. Grocery Store Model: There is a queue for each clerk. When the customer is ready for service, the customer selects the shortest queue and stays in that queue until being served.

2. Airport Model: There is only one queue, which all customers enter. When a clerk becomes available, the customer at the head of the queue goes to that clerk for service.

Suppose also that we know the average number of customers that can be expected in a given time interval (e.g., customers per hour) and the average time required for a clerk to serve a customers (e.g., minutes per customer).

Run a simulation to compare the effectiveness of the two models -- specifically determining the relative waiting times of customers in each model.

## A Scheme-based Solution

The Grocery-Store and Airport Models for this problem are illustrated schematically in the following diagram.

Program /home/walker/oop/clerks/clerks-oo.ss provides an object-oriented solution to this problem in Scheme.

The basic idea of this program is to simulate the flow of customers through clerks over a specified length of time (in hours). The overall simulation time is divided into small intervals (in seconds). For each interval, a random number generator is used to determine whether or not a customer enters a queue, based on an overall arrival rate (given in customers per hour). Also, for each interval, if a clerk is working with a customer, the random number generator determines whether or not the clerk finishes for that customer, again based on an average service time (given in minutes per customer).

The first several lines of this program set the parameters for the simulation. In addition to the above measures (overall simulation length, interval length, customers arriving per hour, etc.), three variables allow the user to specify how much information is printed during a simulation.

### Using Program clerks-oo.ss

1. Copy program /home/walker/oop/clerks/clerks-oo.ss to your account, open it within an editor, and load it within a Scheme environment.

2. Run the program several times, and note the output printed. How does the output seem to relate to the initial program constants?

3. Change a trace variable to true (#t), and explain the output obtained:

1. set trace? to #t
2. set full-trace? to #t (with the other trace variables false)
3. set single-step? to #t (with the other trace variables false)

In each case, examine the output, and try to explain the output produced.

4. Setting the tracing variables back to false (#f), try running the simulation for several arrival levels (cust-per-hr) and several service times (min-per-cust) for the single-queue model (5 clerks, 1 queue).

5. Using the same arrival levels and service times from part 4, run the simulation for the multi-queue model (5 clerks, 5 queues).

6. Based on the data collected, is one model better than the other: for all cases? for some cases? Briefly explain your conclusions.

## Program Analysis

Examine the program clerks-oo.ss to answer the following questions related to object-oriented design and problem solving.

1. Describe the objects in this program.
Using tabular or outline form, indicate:

1. the objects present for this simulation
2. the methods associated with each object
2. As the program executes, draw a diagram that indicates what messages are sent from one object to another during the simulation. That is, draw one or more flow diagrams for processing in this program, following the model of flow diagrams given in the solution for the Eliza program from the previous lab.

3. clarify how statistics are recorded for this simulation.

4. Explain the role of the main procedure simulate in this program; how does processing proceed for the simulation?

This document is available on the World Wide Web as

```http://www.cs.grinnell.edu/~walker/courses/153.sp05/labs/lab-oo-multi-clerks.shtml
```