← back to the schedule


CAR WASH DESIGN CASE STUDY
By Autumn C. Spaulding with Alyce Brady Edited by Sandino Vargas-Pérez




PROBLEM DESCRIPTION

See the Car Wash Design Exercise for a description of the Car Wash Simulation we wish to develop.

The design exercise identified the following list of items that might be relevant for the simulation.

Integers: length of day current time arrival time
average waiting time total waiting time number of cars
Objects: simulation car waiting line (queue)
car wash bay

What do we know about the responsibilities of the objects listed in our table? In each minute the simulation is responsible for determining whether a car arrives, whether it has to wait on line, whether a car can leave the line, and, if so, how long it waited. To determine this it needs to know the car's arrival time and the current time. This constitutes a single step of the simulation. The simulation must run for as many minutes as the car wash is open. (Actually, the simulation should usually run longer -- what happens if there are cars waiting in line or in the wash bay when the car wash officially closes?) When done, the simulation must calculate the average waiting time.

The waiting line is easy. It is a first-in/first-out (FIFO) data structure of cars and, as mentioned in the problem description, can be modeled as a queue.

What do we need to know about cars? We care about their arrival times and their waiting times. We also care about how long a car spends being washed, but we could argue that that is really a function of the car wash bay rather than of the car since all cars entering the bay will take the same amount of time to be washed. The waiting time can be calculated by the simulation, so the only thing the car really needs to keep track of is its arrival time. In fact, we could eliminate cars altogether in this simulation, and just keep a queue of arrival times. Providing a car abstraction more closely models the problem domain, however, and might be useful in the future if the problem is extended.

Finally, what are the responsibilities of a car wash bay? It should be able to tell the simulation whether it is empty or not, and, if it is not empty, it should keep track of the time until it becomes empty.

At this point, we could restate our understanding of the behavior we plan to simulate using pseudo-code:

for each minute of the simulation

   if a car arrives
        increment the number of cars that have arrived
        note the arrival time of the car (store this with the car)
        add the car to the queue

    if the car wash bay is empty and there is a car waiting to be washed
        move the car from the queue to the car wash bay
        determine how long that car was waiting and add to total wait time
        start washing the car (bay will be occupied for next 2 minutes)

    otherwise, if there is a car already being washed
        decrease the amount of time left before the bay is available
Question: is there a case missing here that requires any action?

(For suggestions on implementing this simulation, see the Car Wash Simulation Project).


Acknowledgments: The behavior of the car wash simulation in this project is based on a project description by Todd Ollendyke.


← back to the schedule