CS 22

Clab 22: Clock-Driven Simulation


In his rush for class, professor K. wrote a somewhat weak simulation program to illustrate the use of queues. It also illustrates what might be called a clock-driven simulation. The code for this is in: /home/cfk/pub/cs22/week8/gassim2.scm

Make a week8 subdirectory and copy this program to your subdirectory. Then open it up in drscheme.

It's still a little lame. Your job is to fix it up and write some variants. The documentation is so poor, the professor will have to say a few explanatory words in class.

The overall idea is this: We have a gas station with one pump. In any given minute, with probability prob, a driver comes along who wants gas. If the pump is available the car will pull in and buy gas. If the line for the pump is longer than 3 cars, the car will go to another gas station and be a customer lost. If the car wants gas and there are 3 or fewer cars in the line for the pump, the car will get in line. It is a clock-driven simulation in the sense that the do-construct ticks off each simulated minute of the simulation. The procedure nextminute simulates one minute of the life of the gas station. Inside the procedure nextminute, the parameter simtim tells the current simulated time.

Professor K's simulation is a start. Since he didn't have a function to find the length of a queue, he just added cars to the queue. Due to an oversight, when he printed statistics, he forgot to count time in the queue for customers who were still waiting at the end of the simulation time. Pretty lame!! Fix this up, please. Then add a second pump with its own queue and the same queue discipline (that is cars won't pull in if both queues longer than 3 cars). If there is time, create another version with two pumps but a single queue for both pumps that customers will pull into if it has fewer than 8 cars in line. Show me what you have before you leave. If you want some fun, generalize to n pumps with n separate queues and n pumps with a common queue.


Ask any questions you may have.