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

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

   RESOURCES INCLUDE BARBER AND CASHIER

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

   DEFINE NUM.BALKS, NUM.BARBERS, NUM.CASHIERS, AND NUM.CHAIRS AS
      INTEGER VARIABLES

   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  

   TALLY MAX.CHECKOUT.DELAY AS THE MAXIMUM AND MEAN.CHECKOUT.DELAY 
      AS THE MEAN OF CHECKOUT.DELAY

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

   ACCUMULATE AVG.CASHIER.QUEUE.SIZE AS THE AVERAGE AND 
      MAX.CASHIER.QUEUE.SIZE AS THE MAXIMUM OF N.Q.CASHIER

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

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

END ''PREAMBLE
MAIN    use 1 for input
   
   write as  /, "Test LAW102 - Embellished Barbershop model", /
   CALL READ.DATA
   CALL INITIALIZE

   START SIMULATION

   CALL REPORT
   write as  /, /, "End of Test LAW102", /

END ''MAIN
ROUTINE READ.DATA

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

   PRINT 6 LINES THUS



 BARBER SHOP MODEL -- INPUT PARAMETERS
 -------------------------------------

   SKIP 3 LINES

   PRINT 15 LINES WITH NUM.BARBERS, NUM.CASHIERS, NUM.CHAIRS,
      MEAN.INTERARRIVAL.TIME, MIN.SERVICE.TIME, MAX.SERVICE.TIME, 
      MIN.CHECKOUT.TIME, MAX.CHECKOUT.TIME, AND DAY.LENGTH THUS

 NUMBER OF BARBERS   **

 NUMBER OF CASHIERS  **

 NUMBER OF CHAIRS    **

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

 CHECKOUT 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

   CREATE EVERY CASHIER(1)
   LET U.CASHIER(1) = NUM.CASHIERS

   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 CHECKOUT.TIME, HAIRCUT.FINISH.TIME, SERVICE.TIME, AND
      TIME.OF.ARRIVAL AS REAL VARIABLES

   LET SERVICE.TIME = UNIFORM.F(MIN.SERVICE.TIME,MAX.SERVICE.TIME,2) 
   LET CHECKOUT.TIME = UNIFORM.F(MIN.CHECKOUT.TIME,MAX.CHECKOUT.TIME,3)
   
   IF N.Q.BARBER(1) < NUM.CHAIRS

      LET TIME.OF.ARRIVAL = TIME.V
      REQUEST 1 BARBER(1)
      LET DELAY.IN.QUEUE = TIME.V - TIME.OF.ARRIVAL
      WORK SERVICE.TIME .MINUTES
      RELINQUISH 1 BARBER(1)

      LET HAIRCUT.FINISH.TIME = TIME.V
      REQUEST 1 CASHIER(1)
      LET CHECKOUT.DELAY = TIME.V - HAIRCUT.FINISH.TIME
      WORK CHECKOUT.TIME .MINUTES 
      RELINQUISH 1 CASHIER(1)

   ELSE

      ADD 1 TO NUM.BALKS

   ALWAYS

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 5 LINES WITH TIME.V AND NUM.BALKS THUS

 SIMULATION ENDED AT ****.**

 NUMBER OF BALKS  ***

   SKIP 4 LINES

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

 BARBER:
 -------



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

   SKIP 1 LINE

   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
 -----------     ------------------     ------------------ 

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

   SKIP 3 LINES

   PRINT 12 LINES WITH MEAN.CHECKOUT.DELAY AND MAX.CHECKOUT.DELAY THUS

 CASHIER:
 --------



 MEAN TIME     MAX TIME
 IN QUEUE      IN QUEUE
 ---------     --------
            
  *****.**     *****.**

   SKIP 1 LINE

   PRINT 7 LINES WITH UTIL.CASHIER(1)/NUM.CASHIERS, 
      AVG.CASHIER.QUEUE.SIZE(1), AND MAX.CASHIER.QUEUE.SIZE(1) THUS

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

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

END ''REPORT
