RESTROOM
Models a holding resource.
Entities enter and are automatically held, waiting until another entity releases them.
Internally it manages a single list: occupying entities.
This resource is especially useful to “sleep” agents or keep entities in passive (non-active) waiting.
Associated blocks:
- REST resourceName ; The entity is held.
- WAKE resourceName[,number of entities to release][,entity number to release]; Releases the specified entities if provided (0 or -1 if it is by entity number) or releases only the given entity number if specified.
Available events: ON_REST, ON_WAKE
Restroom {NAME:Agents, X:100, Y:100, ON_REST:Restroom1_onrest, E_BIN_START:0,E_BIN_SIZE:1,E_BIN_COUNT:40 }
;------------------------
REST Agents ; the agent becomes inactive
;------------------------
WAKE Agents ; wakes all agents
WAKE Agents,0,X$nAgent ; wakes one specific agent
Example
/*
Resources. Restroom
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
;SYSTEM {TYPE:OPTIONS,Speed:8}
Restroom {NAME:Restroom_agents,X:100,Y:100}
POSITION {NAME:POS1,X:237,Y:449}
POSITION {NAME:POS2,X:269,Y:334}
POSITION {NAME:POS3,X:272,Y:202,type:terminate,title:end}
Graphic {NAME:textAgent,Type:TEXT,X:430,Y:471,Text:"Agent"}
Graphic {NAME:Text2,Type:TEXT,X:431,Y:523,Text:"Entity"}
initial count,0
initial nAgent,0
START 500
;*****************************************************
PROCEDURE PRE_RUN
timeout agent.main,1
TERMINATE_VE
ENDPROCEDURE
;*****************************************************
GENERATE 10,0,0,0 {NAME:GEN1,X:43,Y:300}
ADVANCE 20,0 {TO:POS1}
if (D$N%4==2)
signalnow agent.Add,X$nAgent
signalnow agent.Subtract,X$nAgent
savevalue result,P$(agentData,X$nAgent)
move {name:Text2,text:"I am Entity D$N : result X$result"}
endif
ADVANCE 20,0 {TO:POS2}
ADVANCE 20,0 {TO:POS3}
ENDGENERATE 1
;*******************************
procedure agent.main
savevalue nAgent,D$N
assign agentData,10
while (1==1)
move {name:textAgent,text:"I am Agent X$nAgent [AC1: AC1$]"}
REST Restroom_agents
endwhile
endprocedure
;**********************************
procedure agent.Add
ASSIGN agentData,P$agentData + 2
return_restore
endprocedure
;**********************************
procedure agent.Subtract
ASSIGN agentData,P$agentData - 1
return_restore
endprocedure