*                 Simulation of a telephone system (basic).
*                 G. Gordon. Figure 12-7/10-5
 
 POISS FUNCTION   RN1,C24                      ; Function for inter arrival time interval (Poisson)
0.0,0.0/0.1,0.104/0.2,0.222/0.3,0.355/0.4,0.509/0.5,0.69/
0.6,0.915/0.7,1.2/0.75,1.38/0.8,1.6/0.84,1.83/0.88,2.12/  
0.9,2.3/0.92,2.52/0.94,2.81/0.95,2.99/0.96,3.2/0.97,3.5/
0.98,3.9/0.99,4.6/0.995,5.3/0.998,6.2/0.999,7.0/0.9997,8.0


*      The phone call process

       GENERATE   12,FN$POISS                  ; Interarrival time of calls (Poisson distributed)
       TEST G     V$FL,2,ABND                  ; Test if system is full (all lines in use).
 ASN1  ASSIGN     ORIGIN,V$LINE                ; Determine origin line. Store in param named ORIGIN.
       GATE LR    P$ORIGIN,ASN1                ; Test whether origin is busy
 ASN2  ASSIGN     DEST,V$LINE                  ; Pick a destination line. Store in parameter named DEST.
       TEST NE    P$ORIGIN,P$DEST,ASN2         ; Retry if ORIGIN == DEST for this call
       LOGIC S    P$ORIGIN                     ; Set the origin line busy
       TRANSFER   BOTH,,BLKD                   ; Try to obtain a link
 GETL  ENTER      LINKS                        ; Get link
       GATE LR    P$DEST,BUSY                  ; Test for destination busy
       LOGIC S    P$DEST                       ; Make destination busy
       MARK                                    ; Reset transit timer
       ADVANCE    120,FN$POISS                 ; Talk
       TABULATE   TTIME                        ; Tabulate talk time
       LOGIC R    P$DEST                       ; Destination hangs up
       LOGIC R    P$ORIGIN                     ; Origin hangs up
       LEAVE      LINKS                        ; Free link
 TERM  TERMINATE                               ; Normal end of a succesful call.

 ABND  TERMINATE                               ; Abandon call

 BLKD  LOGIC R    P$ORIGIN                     ; Origin hangs up
       TERMINATE                               ; Blocked calls
 
 BUSY  LEAVE      LINKS                        ; Free link
       LOGIC R    P$ORIGIN                     ; Origin hangs up
       TERMINATE                               
              
*      The clock process

 CLOCK GENERATE   60                           ; One clock tick every minute
       TERMINATE  1    

*      Declarations
                        
 LINKS STORAGE    10                           ; Number of links

 FL    VARIABLE   X$LINES-2#S$LINKS            ; Number of free lines
 LINE  VARIABLE   X$LINES#RN1/1000+1           ; Randomly chosen line

 TTIME TABLE      M1,10,10,100                 ; Talk time distribution

*      The experiment: GPSS control statements

       INITIAL    X$LINES,50                   ; Set the total number of lines

       START      10,NP                        ; Warmpup (10 minutes), don't print report
       RESET                                   ; Wipe out transient statistics
       START      6000                         ; Main run (100 hours)