In this example, entities must decide which of three paths to take, each one associated with a counter that has its own queue (FACILITY with different capacity). The decision is made in DECIDE.SELECT, which iterates a list containing the path names and the current size of their queues (QUEUE). The result is the name of the path with the least load.
That value is a STRING returned with ENDPROCEDURE and is automatically stored in the variable P$SELECT, which is then used directly as a call: CALL P$SELECT. This mechanism enables dynamic selection without conditionals or multiple explicit calls.
The .decide structures are used to directly return the name of the procedure to execute, saving the programmer from having to write a SWITCH or a cascade of IF.
This greatly simplifies the decision logic, because simply:
CALL DECIDE.SELECT CALL P$SELECT
replaces:
CALL DECIDE.SELECT
SWITCH P$SELECT
CASE ==, "PATH1"
CALL PATH1
CASE ==, "PATH2"
CALL PATH2
...
ENDSWITCH
Example
/*
Rerouting queues
*/
FACILITY {NAME:COUNTER1,X:320,Y:450,capacity:3}
FACILITY {NAME:COUNTER2,X:320,Y:300,capacity:1}
FACILITY {NAME:COUNTER3,X:320,Y:150,capacity:2}
POSITION {NAME:POS1,X:152,Y:300}
POSITION {NAME:POS2,X:497,Y:300}
Graphic {NAME:Text1,Type:TEXT,X:100,Y:100}
START 200
;*************************************************************************
GENERATE 6,0 {NAME:GEN1,X:54,Y:300}
ADVANCE 20,0 {TO:POS1,flow:1}
CALL DECIDE.SELECT ; returns strings: "PATH1", "PATH2" or "PATH3", creating an ASSIGN named P$SELECT
CALL P$SELECT
ADVANCE 20 {TO:POS2,flow:1,merge:"path"}
ENDGENERATE 1
;*************************************************************************
PROCEDURE DECIDE.SELECT
assign myMap, [
{queue:"PATH1",inQueue: R$(COUNTER1,QUEUE)},
{queue:"PATH2",inQueue: R$(COUNTER2,QUEUE)},
{queue:"PATH3",inQueue: R$(COUNTER3,QUEUE)}
]
ASSIGN MINKEY,"PATH1"; initialize selected KEY
ASSIGN MINVAL,100000 ; initialize the minimum value for comparisons
FOREACH tmp,IN,V$myMap
IF (P$(tmp.inQueue) < P$MINVAL)
ASSIGN MINKEY,"P$(tmp.queue)"
ASSIGN MINVAL,P$(tmp.inQueue)
move {name:Text1,Text:"Decision: P$(MINKEY) Queue: P$(MINVAL)"}
ENDIF
ENDFOREACH
ENDPROCEDURE "P$MINKEY" ; will return, for example, "PATH1"
;**************************************************************************
PROCEDURE PATH1
ADVANCE 20 {TO:COUNTER1,flow:1,decision:"path"}
SEIZE COUNTER1
ADVANCE 25,10
RELEASE COUNTER1
ENDPROCEDURE
PROCEDURE PATH2
ADVANCE 20 {TO:COUNTER2,flow:1,decision:"path"}
SEIZE COUNTER2
ADVANCE 80,70
RELEASE COUNTER2
ENDPROCEDURE
PROCEDURE PATH3
ADVANCE 20 {TO:COUNTER3,flow:1,decision:"path"}
SEIZE COUNTER3
ADVANCE 30,20
RELEASE COUNTER3
ENDPROCEDURE
;***************************************************************