A special type of virtual entity is one that does not die at the end of its procedure.
These VEs that remain active throughout the entire simulation (or part of it) are called agents.
- They are like background processes that never terminate.
- They are usually launched from
PRE_RUNvia aTIMEOUT. - They store their entity number (D$N) in a
SAVEVALUE, so they can be interacted with or their state can be queried.
Later on, we will see that these agents handle control tasks, monitoring, or coordination between resources.
In short, an agent is a VE that does not terminate and stays alive in a loop. This allows it to remain attentive—waiting or watching the environment.
Example
/* Agents: Permanent Virtual Entities
Resource monitoring with an infinite loop.
*/
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}
GRAPHIC {NAME:Text_agent,Type:TEXT,X:229,Y:305}
START 40
GENERATE 30,0 {NAME:GEN1,X:110,Y:510,ECOLOR:#FF3333,ERADIO:8}
ADVANCE 30,2 {TO:POS1,flow:1}
ADVANCE 30,2 {TO:Facility1,flow:1}
SEIZE Facility1
ADVANCE 30,30
RELEASE Facility1
ADVANCE 30,2 {TO:POS2,flow:1}
ENDGENERATE 1
;******************************************
PROCEDURE PRE_RUN
TIMEOUT AGENT.INIT,0
TERMINATE_VE
ENDPROCEDURE
;---------------------------------
PROCEDURE AGENT.INIT
SAVEVALUE agentId,D$N
WHILE (1==1)
MOVE {NAME:Text_agent,TEXT:"I am agent [D$N].\nTime AC1$\nEntities in Facility1: R$(Facility1,IN)\nEntities in queue: R$(Facility1,QUEUE)"}
ADVANCE 10
ENDWHILE
TERMINATE_VE
ENDPROCEDURE