BASIC COMPONENT Queue2

DECLARATION OF ELEMENTS

STATE VARIABLES
DISCRETE
   NQueue1   (INTEGER) := 0,                 # Number of customers in Queue 1
   NQueue2   (INTEGER) := 0,                 # Number of customers in Queue 2
   NServer1  (INTEGER) := 0,                 # Number of customers in Service 1
   NServer2  (INTEGER) := 0,                 # Number of customers in Service 2
   TArrive   (REAL)    := 0,                 # Time of next arrival
   TService1 (REAL)    := 0,                 # Time of next service completion 1
   TService2 (REAL)    := 0

RANDOM VARIABLES
   IArrive  (REAL) : EXPO (Mean := 11.0),   # Inter-arrival times
   IService (REAL) : EXPO (Mean := 10.0)    # Service times


DYNAMIC BEHAVIOUR

# Event 1,2: Customer arrives at bank and choses the shorter queue

WHENEVER (T >= TArrive) AND (NQueue2 < NQueue1)
DO
   NQueue2^  := NQueue2 + 1;
   TArrive^ := T + IArrive;
   DISPLAY ("T= %f Customer arrives and enters queue 2\n",T);
END

WHENEVER (T >= TArrive) AND (NQueue2 >= NQueue1)
DO
   NQueue1^  := NQueue1 + 1;
   TArrive^ := T + IArrive;
   DISPLAY ("T= %f Customer arrives and enters queue 1\n",T);
END

# Event 3,4: Customer moves up to service

WHENEVER (NServer1 = 0) AND (NQueue1 > 0)
DO
   NQueue1^   := NQueue1 - 1;
   NServer1^  := NServer1 + 1;
   TService1^ := T + IService;
   DISPLAY ("T= %f Customer enters service 1\n",T);
END

WHENEVER (NServer2 = 0) AND (NQueue2 > 0)
DO
   NQueue2^   := NQueue2 - 1;
   NServer2^  := NServer2 + 1;
   TService2^ := T + IService;
   DISPLAY ("T= %f Customer enters service 2\n",T);
END

# Event 5,6: Service complete

WHENEVER (T >= TService1) AND (NServer1 = 1)
DO
   NServer1^ := 0;
   DISPLAY ("T= %f Customer leaves service 1\n",T);
END

WHENEVER (T >= TService2) AND (NServer2 = 1)
DO
   NServer2^ := 0;
   DISPLAY ("T= %f Customer leaves service 2\n",T);
END

END OF Queue2
