In: Computer Science
Write a FORTRAN program to simulate the daily activity at a gas station. Assuming that one customer is served every six minutes, what is the average waiting time per customer?
SOLUTION :
This is a problem in discrete simulation. A random number
generator is used in the program to model the arrival of customers.
Since the gas station attendant cannot know if the stream of
customers will be continuous, randomness of arrivals is
assumed.
To calculate the average waiting time, the program should compute
the waiting time of each individual car, add the times, and divide
that sum by the total number of cars. The first arrival incurs no
waiting time, but all subsequent arrivals must wait six minutes for
each car in front of them. To obtain an average the service time
remaining for each car, the total waiting time for all the cars,
and the number of cars that are lined up must be found.
For each simulated minute, the program must reduce the service time
SERV by one and check to see if another car has arrived. If so, the
waiting time for that last car is given by SERV. WAIT - the total
waiting time, is increased by adding SERV to it, while the number
of cars, CARTOT, is Increased by one, and SERV is increased by six
minutes. The parameter N is the number of minutes to be simulated
(N cannot contain more than 6 digits).
Another assumption made is that customers arrive each minute with a
probability of 0.1. To simplify the problem, it is assumed that
there is only one gas pump at this station.
Note, that several values of N can be entered in the DATA section.
The program procedure will be done for each of those time
intervals. In order to end the program, enter N ≤ 0 as the last
value.
C GASOLINE LINE SIMULATION
INTEGER WAIT, SERV, CARTOT, TIME
5 READ (5,1)N
1 FORMATE (I6)
C DO WHILE N GREATER THAN ZERO
IF (N. LE. 0) GO TO 99
SERV = 0
WAIT = 0
CARTOT = 0
DO 10 TIME = 1,N
SERV = MAX (SERV − 1,0)
22 2 CALL RAND (X)
IF (X.GT.0.1) GO TO 22
CARTOT = CARTOT + 1
WAIT = WAIT + SERV
SERV = SERV + 6
10 CONTINUE
AVWAIT = FLOAT (WAIT)/FLOAT (CARTOT)
WRITE (6,101) CARTOT,AVWAIT
101 FORMAT (IX,'AVERAGE WAIT FOR EACH OF THE',
16,'CUSTOMERS IS', F6.2,'MINUTES.')
GO TO 5
C END DO-WHILE
99 STOP
END