Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-02 - 43,50242/market.bli
There are no other files named market.bli in the archive.
00100	BEGIN
00200	
00300	%<THE PROGRAM SIMULATES THE CHECKOUT - SECTION OF A SUPERMARKET.
00400	  CUSTOMERS ARRIVE AT THE FRONT OF THE MARKET AND WAIT
00500	  IN THE SHORTEST QUEUE, UNTIL THEY CAN BE SERVED.
00600	  STATISTICS ARE GATHERED ON HOW LONG CUSTOMERS HAVE TO WAIT IN
00700	  LINES.
00800	>%
00900	
01000	!   N IS NO. OF CLERKS, Q ARE THE QUEUES, WTIME THE WAITING TIME
01100	!   HISTOGRAM, CLERK CONTAINS PROCESS DESCRIPTORS FOR CLERKS.
01200	!   U,V ARE RANDOM NUMBER STREAMS, COUNT IS CUSTOMERCOUNT.
01300	!   GLOBALS ARE ACCESSIBLE BY NAME FROM DDT,  THAT'S WHY.
01400	
01500	MACRO N = 3$;
01600	GLOBAL Q[N], WTIME[21],  CLERK[N];
01700	EXTERNAL NEGEXP,NORMAL;
01800	OWN U,V,COUNT;
01900	
02000	     
02100	GLOBAL ROUTINE INITIO =
02200	!   ROUTINE TO INITIALIZE NON-TTY I/O.  DUMMY IN THIS CASE.
02300	();
02400	
02500	ROUTINE CUSTOMER(TELL)=
02600	!   THIS IS THE CLASS CUSTOMER.
02700	BEGIN
02800	  LOCAL T;
02900	  OWN K,J,LEN;
03000	
03100	!   NOW CREATE NEXT CUSTOMER AND SCHEDULE HIS ARRIVAL.
03200	  ACTIVATE(NEW(CUSTOMER(TELL+1),100),LASTAT,.TIME FADR 
03300	    (NEGEXP(0.50,V<0,0>)));
03400	
03500	  T_.TIME;
03600	
03700	!   FIND SHORTEST QUEUE
03800	  K_0;
03900	  LEN_CARDINAL(.Q[.K]);
04000	  INCR II FROM 1 TO N-1 DO
04100	    IF CARDINAL(.Q[.II]) LSS .LEN THEN
04200	      BEGIN K_.II;   LEN_ CARDINAL(.Q[.K]) END;
04300	
04400	!   NOW ENTER THE SHORTEST QUEUE, BUT FIRST ACTIVATE ITS CHECK-
04500	!   OUT CLERK IN CASE HE WAS IDLE.
04600	  ACTIVATE(.CLERK[.K],AFTER,.CURRENT);
04700	  WAIT(.Q[.K]);
04800	
04900	!   REACTIVATION POINT SET HERE.  CUSTOMER IS ACTIVATED AGAIN BY
05000	!   CLERK WHEN HE HAS BEEN SERVED.
05100	
05200	!   COMPUTE TIME SPENT IN QUEUE
05300	  T_(.TIME FSBR .T); J_FIX .T;
05400	
05500	
05600	!   INCREMENT APPROPRIATE ENTRY IN WAITING-TIME HISTOGRAM.
05700	  IF .J LSS 20 THEN WTIME[.J]_.WTIME[.J]+1
05800	    ELSE WTIME[20]_.WTIME[20]+1;
05900	
06000	!   IF ENOUGH CUSTOMERS SERVED TO GET GOOD STATISTICS, FINISH.
06100	  COUNT_.COUNT+1;
06200	  IF .COUNT GTR 1000 THEN
06300	    ACTIVATE(.MAINPROG,AFTER,.CURRENT);
06400	
06500	!   THIS CUSTOMER IS NOW FINISHED.  RETURN HIM TO THE FREE LIST.
06600	  KILL(.CURRENT)
06700	END;      ! END OF CUSTOMER.
06800	      
06900	
07000	ROUTINE SERVICE(I)=
07100	!   THIS ROUTINE DESCRIBES THE CLASS OF CLERKS.
07200	BEGIN
07300	  WHILE 1 DO
07400	  BEGIN 
07500	
07600	!     IS THERE A CUSTOMER IN THE QUEUE?
07700	    WHILE NOT EMPTY(.Q[.I]) DO
07800	    (
07900	      ! YES. SERVE HIM, THEN ACTIVATE HIM.
08000	      HOLD(NORMAL(5.3,1.0,U<0,0>));
08100	      ACTIVATE(FIRST(.Q[.I]),AFTER,.CURRENT);
08200	      REMOVE(FIRST(.Q[.I]))
08300	    );
08400	!     NO.  REST UNTIL ONE ARRIVES.  HE'LL ACTIVATE ME.
08500	    CANCEL(.CURRENT)
08600	  END;    ! END OF CLERK LOOP
08700	
08800	END;     ! END OF SERVICE.
08900	
09000	
09100	!   INITIALIZE RANDOM NUMBER STREAMS, COUNTER, HISTOGRAM,
09200	!   QUEUES AND CLERKS.
09300	
09400	U_11;
09500	V_7;
09600	COUNT_0;
09700	INCR II FROM 0 TO 20 DO WTIME[.II]_0;
09800	INCR II FROM 0 TO N-1 DO Q[.II]_MAKELIST();
09900	INCR II FROM 0 TO N-1 DO CLERK[.II]_NEW(SERVICE(.II),80);
10000	
10100	!   INITIALIZE FIRST CUSTOMER, HE'LL TAKE CARE OF THE REST.
10200	ACTIVATE(NEW(CUSTOMER(10),100),AFTER,.CURRENT);
10300	
10400	!   WAIT TILL STATISTICS IS GATHERED.
10500	CANCEL(.CURRENT);
10600	
10700	! OUTPUT STATISTICS.
10800	TYPE('HISTO',0);  TYPE('GRAM ',0);  TYPE('OF WA',0);
10900	TYPE('ITING',0);  TYPE(' TIME',0);  TYPE('S:',1);
11000	INCR II FROM 0 TO 20 DO
11100	  (TYPDEC(.II,0);TYPE('	',0);TYPDEC(.WTIME[.II],1));
11200	
11300	END      !   CORRESPONDS TO BEGIN IN THIS PROGRAM.
11400	
11500	END      !   CORRESPONDS TO BEGIN FIRST IN POOMAS.BLI
11600	
11700	ELUDOM