Dynamic resource creation 2

Updated: 2026-01-07

Now that we know resources can be created at runtime, let’s look at their most obvious use: creating many of them using an iterator. We only need to keep track of the names assigned in order to use them later. In GPSS-Plus, resource names are real strings, which means they can be dynamically constructed and directly used in SEIZE, RELEASE, R$(), and similar commands.

Example

SYSTEM {TYPE:OPTIONS, SPEED:5}
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
Position {NAME:POS1,X:147,Y:311}
Position {NAME:POS2,X:542,Y:327}
Position {NAME:POS3,X:756,Y:322}


Graphic {NAME:Text1,Type:TEXT,X:305,Y:571,Text:"Hello"}

; --- Facility defined in the classic way ---
FACILITY {NAME:f_static, CAPACITY:4, X:657, Y:325,color:blue}

START 200

PROCEDURE PRE_RUN
    ; Create a second dynamic facility at startup
	assign t,0
    
    while (P$t < 5) 
        assign t,P$t+1
        assign pos_y,(P$t * 80 + 20)
        assign nombre,"f_dynamic_P$t"
        NEWFACILITY {NAME:P$nombre, CAPACITY:1, X:300, Y:(P$pos_y)}
        NEWPOSITION {NAME:pos_P$nombre, X:200, Y:(P$pos_y)}
    endwhile
   
    TERMINATE_VE
ENDPROCEDURE

;------------------------------------------------------
; --- Entity flow ---
GENERATE 6,0 {NAME:GEN1,x:58,y:310} 

advance 15,0 {to:POS1,flow:1}

ASSIGN MINKEY,0 
ASSIGN MINVAL,100000

assign t,0
while (P$t < 5) 
    assign t,P$t+1
    assign nombre,"f_dynamic_P$t"
    if (R$(P$nombre,QUEUE) < P$MINVAL)
        ASSIGN MINKEY,P$t 
		ASSIGN MINVAL,R$(P$nombre,QUEUE)
    endif
endwhile

assign siguiente_recurso,"f_dynamic_P$MINKEY"

move {name:Text1,text:"Entity D$N query: P$(siguiente_recurso) Queue: R$(P$siguiente_recurso,QUEUE)"}




advance 15,0 {to:"pos_P$siguiente_recurso",flow:1,DECISION:"inicio"}
advance 15,0 {to:"P$siguiente_recurso",flow:1}


SEIZE P$siguiente_recurso   
ADVANCE 25,15   
RELEASE P$siguiente_recurso

advance 15 {to:POS2,flow:1,MERGE:"salida"}

advance 15 {to:f_static,flow:1}

SEIZE f_static  
ADVANCE 7,8        
RELEASE f_static

advance 15 {to:POS3,flow:1}

TERMINATE 1