This example shows the basic use of a STORAGE resource, useful to model inventories, warehouses, or capacity-limited areas. Entities consume a random number of units from the resource, representing a variable load.
The interesting part of the example is how to obtain the resource contents in real time using two different methods:
-
Sum of individual data: using
FOREACH, you iterate over each entity occupying the resource and add up its associated values (in this case, the number of units it took). -
Direct query: with
R$(WAREHOUSE1,LEFT)you get the number of free units, so the total occupied isCAPACITY - LEFT.
Both approaches let you cross-check and validate the information, and can be applied to statistical calculations, inventory control, or saturation alerts.
The TIMER periodically updates the on-screen information, providing a continuous view of the resource state.
Example
/*
Accessing and measuring a resource
*/
STORAGE {NAME: WAREHOUSE1, CAPACITY:40, X:316,Y:401}
SYSTEM {TYPE:ON_TIMER,INTERVAL:50,TRIGGER:PROCTIMER}
GRAPHIC {NAME:BANNER1,TYPE:TEXT,X:184,Y:343,TEXT:RANDOM.}
GRAPHIC {NAME:BANNER2,TYPE:TEXT,X:305,Y:283,TEXT:SUM}
GRAPHIC {NAME:BANNER3,TYPE:TEXT,X:306,Y:241,TEXT:DIRECT}
POSITION {NAME:POS1,X:176,Y:296}
POSITION {NAME:POS2,X:452,Y:300}
POSITION {NAME:POS3,X:559,Y:299}
START 100
;******************************************************
GENERATE 30,10 {NAME:GEN1,X:61,Y:297}
ASSIGN RANDOM,FLOOR(RANDOM * 9 + 1) {debug:1}
MOVE {NAME:BANNER1,TEXT:"RANDOM: P$RANDOM"}
ADVANCE 20 {TO:POS1}
ADVANCE 20 {TO:WAREHOUSE1}
ENTER WAREHOUSE1 ,P$RANDOM
ADVANCE 110,90
LEAVE WAREHOUSE1
ADVANCE 20 {TO:POS2}
ADVANCE 20,0 {TO:POS3}
ENDGENERATE 1
;*****************************************************
PROCEDURE PROCTIMER
ASSIGN SUM,0
FOREACH NUMBER,IN_RESOURCE,WAREHOUSE1
ASSIGN SUM,(P$(RANDOM,P$NUMBER) + P$SUM)
ENDFOREACH
MOVE {NAME:BANNER2,TEXT:"SUM OF RANDOMS: P$SUM"}
ASSIGN DIRECT,40-R$(WAREHOUSE1,LEFT)
MOVE {NAME:BANNER3,TEXT:"DIRECT: P$DIRECT"}
TERMINATE_VE
ENDPROCEDURE
;*****************************************************