'' @(#) law101.sim 2/25/86
''Simple barbershop model
''An Introduction to Simulation Using SIMSCRIPT II.5, Chapter 2
PREAMBLE

   PROCESSES INCLUDE ARRIVAL.GENERATOR, CLOSE.DOORS, AND CUSTOMER

   RESOURCES INCLUDE BARBER

   DEFINE DAY.LENGTH, DELAY.IN.QUEUE, MAX.SERVICE.TIME,
      MEAN.INTERARRIVAL.TIME, AND MIN.SERVICE.TIME AS REAL VARIABLES

   DEFINE NUM.BARBERS AS AN INTEGER VARIABLE

   DEFINE .MINUTES TO MEAN UNITS

   TALLY MAX.DELAY.IN.QUEUE AS THE MAXIMUM, MEAN.DELAY.IN.QUEUE
      AS THE MEAN, AND NUM.SERVED AS THE NUMBER OF DELAY.IN.QUEUE  

   ACCUMULATE AVG.NUMBER.IN.QUEUE AS THE AVERAGE AND MAX.NUMBER.IN.QUEUE
      AS THE MAXIMUM OF N.Q.BARBER

   ACCUMULATE UTIL.BARBER AS THE AVERAGE OF N.X.BARBER

END ''PREAMBLE
MAIN    use 1 for input

   write as  /, "Test LAW101 - Simple Barbershop model", /
   
   CALL READ.DATA
   CALL INITIALIZE

   START SIMULATION

   CALL REPORT

   write as  /, /, "End of Test LAW101", /

END ''MAIN
ROUTINE READ.DATA

   READ DAY.LENGTH, MEAN.INTERARRIVAL.TIME, MIN.SERVICE.TIME, 
      MAX.SERVICE.TIME, AND NUM.BARBERS

   PRINT 6 LINES THUS



 BARBERSHOP MODEL -- INPUT PARAMETERS
 ------------------------------------

   SKIP 3 LINES

   PRINT 9 LINES WITH NUM.BARBERS, MEAN.INTERARRIVAL.TIME,
      MIN.SERVICE.TIME, MAX.SERVICE.TIME, AND DAY.LENGTH THUS

 NUMBER OF BARBERS  **

 INTERARRIVAL TIMES ARE EXPONENTIAL WITH MEAN ***.* MINUTES
 
 SERVICE TIMES ARE UNIFORM ON THE INTERVAL (***.*,***.*) MINUTES

 DOORS CLOSE AFTER ****.* MINUTES

   START NEW PAGE

END ''READ.DATA
ROUTINE INITIALIZE

   CREATE EVERY BARBER(1)
   LET U.BARBER(1) = NUM.BARBERS

   ACTIVATE AN ARRIVAL.GENERATOR NOW
   ACTIVATE A CLOSE.DOORS IN DAY.LENGTH .MINUTES

END ''INITIALIZE
PROCESS ARRIVAL.GENERATOR

   WHILE TIME.V < DAY.LENGTH
   DO 
      WAIT EXPONENTIAL.F(MEAN.INTERARRIVAL.TIME,1) .MINUTES
      ACTIVATE A CUSTOMER NOW
   LOOP

END ''ARRIVAL.GENERATOR
PROCESS CUSTOMER

   DEFINE TIME.OF.ARRIVAL AS A REAL VARIABLE
   
   LET TIME.OF.ARRIVAL = TIME.V
   REQUEST 1 BARBER(1)
   LET DELAY.IN.QUEUE = TIME.V - TIME.OF.ARRIVAL
   WORK UNIFORM.F(MIN.SERVICE.TIME,MAX.SERVICE.TIME,2) .MINUTES
   RELINQUISH 1 BARBER(1)

END ''CUSTOMER
PROCESS CLOSE.DOORS

   INTERRUPT ARRIVAL.GENERATOR

END ''CLOSE.DOORS
ROUTINE REPORT

   PRINT 6 LINES THUS



 SIMULATION RESULTS (ALL TIMES ARE IN MINUTES)
 --------------------------------------------

   SKIP 3 LINES

   PRINT 3 LINES WITH TIME.V THUS

 SIMULATION ENDED AT  ****.**

   SKIP 3 LINES

   PRINT 7 LINES WITH NUM.SERVED, MEAN.DELAY.IN.QUEUE, AND
      MAX.DELAY.IN.QUEUE THUS

 TOTAL NUMBER OF      MEAN TIME     MAX TIME
 CUSTOMERS SERVED     IN QUEUE      IN QUEUE
 ----------------     ---------     --------
            
            *****      *****.**     *****.**

   SKIP 3 LINES

   PRINT 7 LINES WITH UTIL.BARBER(1)/NUM.BARBERS, AVG.NUMBER.IN.QUEUE(1),
      AND MAX.NUMBER.IN.QUEUE(1) THUS

 BARBER          AVERAGE NUMBER OF      MAXIMUM NUMBER OF
 UTILIZATION     CUSTOMERS IN QUEUE     CUSTOMERS IN QUEUE
 -----------     ------------------     ------------------ 

      ***.**               *****.**                 *****.

END ''REPORT
