Sometimes we want to test different configurations to find the most suitable one.
For example, we may want to determine the minimum number of operators required to keep production running.
This search can be performed sequentially or using more advanced strategies, depending on the number of variables involved.
Regardless of the algorithm used, in GPSS-Plus this type of experiment relies on a persistent SAVEVALUE called TRIAL_STATE and on the RESTART block.
In this context, TRIAL_STATE has the property of retaining its value between runs, even when a RESTART occurs.
This allows the model to preserve information between attempts and modify its parameters in each new run.
In the following example, we want to determine the minimum capacity of several FACILITY resources such that the queue never exceeds two entities.
Since TRIAL_STATE does not exist during the first run, we initialize the capacity to 1:
INITIAL capacity,( (X$(TRIAL_STATE.capacity.EXIST)==1) ? X$(TRIAL_STATE.capacity) : 1)
During the simulation, we monitor the queue length.
If the established limit is exceeded at any point, we consider the trial invalid and launch a new attempt with increased capacity:
IF (R$(Fac1,QUEUE) > 2)
SAVEVALUE TRIAL_STATE.capacity1 , X$(TRIAL_STATE.capacity1) + 1
CALL next_trial
ENDIF
If the simulation reaches 100 entities without exceeding the limit, the current capacity is considered valid.
Example
; *******************************************************************
; EXPERIMENT: Find minimum capacity without queue overflow
; We increase capacity until the queue never exceeds 2
; *******************************************************************
SYSTEM {TYPE:OPTIONS,TIME_DECIMALS:0,SPEED:7};
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
INITIAL capacity1,( (X$(TRIAL_STATE.capacity1.EXIST)==1) ? X$(TRIAL_STATE.capacity1) : 1)
INITIAL capacity2,( (X$(TRIAL_STATE.capacity2.EXIST)==1) ? X$(TRIAL_STATE.capacity2) : 1)
INITIAL capacity3,( (X$(TRIAL_STATE.capacity3.EXIST)==1) ? X$(TRIAL_STATE.capacity3) : 1)
FACILITY {name:Fac1, CAPACITY:X$capacity1, X:255,Y:431, on_queue:check_queue1}
FACILITY {name:Fac2, CAPACITY:X$capacity2, X:412,Y:318, on_queue:check_queue2}
FACILITY {name:Fac3, CAPACITY:X$capacity3, X:605,Y:430, on_queue:check_queue3}
POSITION {NAME:POSEND,X:727,Y:352}
FUNCTION {NAME:funFac1,TYPE:TRIANGULAR,MIN:25,MAX:60,MODE:45,INTERVALS:500}
FUNCTION {NAME:funFac2,TYPE:TRIANGULAR,MIN:25,MAX:260,MODE:45,INTERVALS:500}
FUNCTION {NAME:funFac3,TYPE:TRIANGULAR,MIN:25,MAX:160,MODE:45,INTERVALS:500}
GRAPHIC {name:Tprocess,type:TEXT,X:403,Y:190,
text:"Trial X$(TRIAL_STATE.count)\n Capacity1 X$(capacity1) \nCapacity2 X$(capacity2) \nCapacity3 X$(capacity3) \n"}
START 100
PROCEDURE PRE_RUN
IF (X$(TRIAL_STATE.count,EXIST)==0)
SAVEVALUE TRIAL_STATE,{
count:0,
capacity1:1,
capacity2:1,
capacity3:1
}
ENDIF
TERMINATE_VE
ENDPROCEDURE
;----------------------------------------------------------
GENERATE 9,0 {NAME:GEN1,X:82,Y:356}
ASSIGN Estado, 0
ADVANCE 10,0 {TO:Fac1,flow:1}
SEIZE Fac1
ADVANCE FN$funFac1
RELEASE Fac1
ADVANCE 10,0 {TO:Fac2,flow:1}
SEIZE Fac2
ADVANCE FN$funFac2
RELEASE Fac2
ADVANCE 10,0 {TO:Fac3,flow:1}
SEIZE Fac3
ADVANCE FN$funFac3
RELEASE Fac3
ADVANCE 10,0 {TO:POSEND,flow:1}
ENDGENERATE 1
;----------------------------------------------------------
; Queue control: if queue exceeds limit → fail trial
;----------------------------------------------------------
PROCEDURE check_queue1
IF (R$(Fac1,QUEUE) > 2)
SAVEVALUE TRIAL_STATE.capacity1 , X$(TRIAL_STATE.capacity1) + 1
CALL next_trial
ENDIF
TERMINATE_VE
ENDPROCEDURE
PROCEDURE check_queue2
IF (R$(Fac2,QUEUE) > 2)
SAVEVALUE TRIAL_STATE.capacity2 , X$(TRIAL_STATE.capacity2) + 1
CALL next_trial
ENDIF
TERMINATE_VE
ENDPROCEDURE
PROCEDURE check_queue3
IF (R$(Fac3,QUEUE) > 2)
SAVEVALUE TRIAL_STATE.capacity3 , X$(TRIAL_STATE.capacity3) + 1
CALL next_trial
ENDIF
TERMINATE_VE
ENDPROCEDURE
;----------------------------------------------------------
; Experiment control: increase capacity and retry
;----------------------------------------------------------
PROCEDURE next_trial
SAVEVALUE TRIAL_STATE.count , X$(TRIAL_STATE.count) + 1
IF (X$(TRIAL_STATE.count) < 30)
RESTART
ELSE
STOP
ENDIF
TERMINATE_VE
ENDPROCEDURE