Structure: IF, CALL, PROCEDURE

Updated: 2025-10-08

In this example, we simulate a system where each entity randomly chooses one of three service counters to be served. Each counter has its own queue, and the flow is unevenly distributed depending on the service time.

The decision logic is resolved exclusively through structured procedures.

FACILITY {NAME:VENTANILLA1,X:320,Y:450}
FACILITY {NAME:VENTANILLA2,X:320,Y:300}
FACILITY {NAME:VENTANILLA3,X:320,Y:150}

POSITION {NAME:POS1,X:160,Y:300}
POSITION {NAME:POS2,X:497,Y:300}

START 30 ; Executes until 30 entities are completed

GENERATE 10,0 {NAME:GEN1,X:60,Y:300}
ADVANCE 20,0 {TO:POS1}
ASSIGN ALEATORIO,RANDOM
IF (P$ALEATORIO < 0.3)
    CALL CAMINO1
    ELSE 
       IF (P$ALEATORIO < 0.6)
          CALL CAMINO2
          ELSE
          CALL CAMINO3
       ENDIF
ENDIF
ADVANCE 20 {TO:POS2}
TERMINATE 1

;---------------------------------------------

PROCEDURE CAMINO1
ADVANCE 20  {TO:VENTANILLA1}
SEIZE VENTANILLA1
ADVANCE 25,10
RELEASE VENTANILLA1
ENDPROCEDURE 

PROCEDURE CAMINO2
ADVANCE 20 {TO:VENTANILLA2}
SEIZE VENTANILLA2
ADVANCE 10,2
RELEASE VENTANILLA2
ENDPROCEDURE 

PROCEDURE CAMINO3
ADVANCE 20 {TO:VENTANILLA3}
SEIZE VENTANILLA3
ADVANCE 10,2
RELEASE VENTANILLA3
ENDPROCEDURE

Compared to the previous example, only a few new BLOCKS are introduced:

ASSIGN ALEATORIO,RANDOM

This block creates a local variable in the entity (called ALEATORIO) and assigns it a random number between 0 and 1, using the RANDOM function.

These local variables are also called parameters and are accessed using the SNA notation:

P$ALEATORIO
  • "P" because it is a parameter,
  • "$" is the standard separator,
  • "ALEATORIO" is its name.
IF (P$ALEATORIO < 0.3)

This is an "IF" control-structure block.

As can be seen, it is an "if" just like in any other language: a variable is compared against a value.

This other control-structure block also needs little introduction. It calls a PROCEDURE:

CALL CAMINO1

Finally:

PROCEDURE CAMINO1
...
ENDPROCEDURE 100 ; would produce an ASSIGN in the calling entity named CAMINO1 with value 100

Which also requires little explanation. PROCEDURE blocks encapsulate a set of actions.

ENDPROCEDURE may include a value in parameter A, which is returned in the same way as if an ASSIGN instruction had been generated. It can be retrieved as P$ProcedureName (e.g., P$CAMINO1). In this case, it is not used.