We have already seen what a virtual entity is: an entity that does not move on the screen but still executes instructions and participates in the simulation engine.
Now we will see how these virtual entities are created and who can create them.
Who creates a VE?
Virtual entities are not born from a GENERATE block like normal entities. Instead, they can be created by four different mechanisms:
- The system, using:
PRE_RUN– at the beginning of the simulation, once.TIMER– at fixed intervals defined byINTERVAL.
- An entity, using:
TIMEOUT– schedules the execution of a VE X time units in the future.
- A resource, using
ON_*events such as:ON_SEIZE,ON_RELEASE,ON_LEAVE, etc.
What do they all have in common?
All virtual entities execute a PROCEDURE, which may be specified as a TRIGGER or as a procedure name. That PROCEDURE is the “code” executed by the VE. It must end with TERMINATE or TERMINATE_VE, just like any normal entity.
About parameters
When using NEW, TIMEOUT, or CALL, we can pass additional parameters. These will be available inside the procedure as P$PARAM_A, P$PARAM_B, etc., just as we have already seen with CALL.
This allows a VE to “know” who invoked it or why.
In the example:
PRE_RUNcreates an entity at the start (magenta color).TIMER1creates one every 53 time units (blue color).TIMEOUTfires just before entering the resource and leaves a message.ON_RELEASEfires whenFACILITY1is released.
Each time one of these virtual entities is created, a message appears on screen showing its identifier and what it is doing.
Example
/* Creation of virtual entities */
SYSTEM {TYPE:ON_TIMER, TRIGGER:TIMER1, INTERVAL:53}
SYSTEM {TYPE:PRE_RUN, TRIGGER:PRE_RUN}
POSITION {NAME:POS1,X:311,Y:497}
POSITION {NAME:POS2,X:571,Y:147,TYPE:TERMINATE,TITLE:END}
FACILITY {NAME:Facility1,X:573,Y:483,ON_RELEASE:on_RELEASE_Facility1}
GRAPHIC {NAME:Text_Pre_run,Type:TEXT,X:253,Y:196}
GRAPHIC {NAME:Text_TIMER1,Type:TEXT,X:253,Y:158}
GRAPHIC {NAME:Text_Timeout1,Type:TEXT,X:254,Y:252}
GRAPHIC {NAME:Text_on_release,Type:TEXT,X:575,Y:544}
START 40
GENERATE 30,0 {NAME:GEN1,X:110,Y:510,ECOLOR:#FF3333,ERADIO:8}
IF ("P$PARAM_A"=="PRE_RUN")
MOD {COLOR:magenta,SUBTITLE:pre_run}
ENDIF
IF ("P$PARAM_A"=="TIMER1")
MOD {COLOR:blue,SUBTITLE:timer1}
ENDIF
ADVANCE 30,2 {TO:POS1,flow:1}
ADVANCE 30,2 {TO:Facility1,flow:1}
TIMEOUT Timeout1,0,D$N ; pass the entity number as a parameter
SEIZE Facility1
ADVANCE 30,30
RELEASE Facility1
ADVANCE 30,2 {TO:POS2,flow:1}
ENDGENERATE 1
;******************************************
PROCEDURE PRE_RUN
MOVE {NAME:Text_Pre_run,TEXT:"I am [D$N] PRE_RUN.\nI create a new entity."}
NEW GEN1,0,"pre_run"
TERMINATE_VE
ENDPROCEDURE
;---------------------------------
PROCEDURE TIMER1
MOVE {NAME:Text_TIMER1,TEXT:"I am [D$N] TIMER1.\nI create a new entity."}
NEW GEN1,0,"timer1" ; Generate, time, PARAM_A, PARAM_B...
TERMINATE_VE
ENDPROCEDURE
;---------------------------------
PROCEDURE Timeout1
MOVE {NAME:Text_Timeout1,TEXT:"I am [D$N] Timeout1.\nEntity [P$PARAM_A] is about to enter"}
TERMINATE_VE
ENDPROCEDURE
PROCEDURE on_RELEASE_Facility1
MOVE {NAME:Text_on_release,TEXT:"I am [D$N] on_RELEASE.\nEntity [P$ENTITYNUMBER] leaves Facility1"}
TERMINATE_VE
ENDPROCEDURE
;******************************************