In a discrete-event simulation engine, an entity is usually a single execution thread: a sequential flow that advances, blocks, and resumes according to the model.
This works, but it does not fully match real behavior in many situations.
A person waiting at a bus stop does not just wait: they breathe, check their phone, think, get distracted, and may change their mind.
A moving vehicle also acts in parallel: it consumes energy, wears down, receives signals, and adjusts its route.
Modeling all of this with a single linear flow is an excessive simplification.
Component entities: simultaneity inside the entity
We therefore extend the way we think about an entity so that it can have several functions running in parallel.
A component entity is a virtual entity that executes a function on behalf of another main entity. Its existence depends on the main entity, but it has its own execution flow.
This allows a main entity to have multiple active behaviors simultaneously, each represented by an independent component entity.
Key characteristics:
- The component entity is created when the main entity is created.
- It runs its logic in parallel, without blocking the main flow.
- It can read and modify attributes of the main entity.
- It can wake it, change its state, or trigger decisions.
- It automatically ends when the main entity ceases to exist.
It is not a “child” in an OOP sense, nor an object or a property. It is a living behavior, modeled as an entity.
The event queue remains strictly sequential, but the entity is no longer monolithic: it no longer represents a single flow, but a small system composed of several cooperating entities that model the main entity more deeply.
This makes it possible to model natural simultaneity phenomena without threads, semaphores, or external programming.
Lifecycle of a component entity:
1. The main entity is created.
2. A component entity is immediately created, receiving the main entity’s identifier.
3. The component entity runs its logic in a WHILE loop as long as D$(EXIST, mainEntityId) == 1.
4. It may influence the main entity by assigning values, modifying state, or waking it.
5. When the main entity disappears, the component entity automatically terminates.
In the example, people arrive at a simplified bus stop. When more than six accumulate, everyone leaves while they are resting outside the event queue. Meanwhile, the entities are also checking their phones, and some may decide to leave urgently.
When a component entity decides the queue must be abandoned, it executes the required actions while the main entity is still sleeping in the RESTROOM.
Example
/*
Component
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
;SYSTEM {TYPE:OPTIONS,Speed:8}
Restroom {NAME:Restroom_bus,X:333,Y:282}
POSITION {NAME:URGENT_EXIT,X:335,Y:119}
POSITION {NAME:EXIT,X:615,Y:286,type:terminate,title:end}
Graphic {NAME:textAgent,Type:TEXT,X:494,Y:336,Text:"Group"}
Graphic {NAME:Text2,Type:TEXT,X:331,Y:76,Text:"Urgency"}
START 500
;*****************************************************
PROCEDURE PRE_RUN
timeout check_queue,1
TERMINATE_VE
ENDPROCEDURE
;*****************************************************
GENERATE 10,0,0,0 {NAME:GEN1,X:61,Y:288}
ASSIGN urgentExit,0
timeout component_check_phone,0,D$N
ADVANCE 20,0 {TO:Restroom_bus}
REST Restroom_bus
if (P$urgentExit == 1)
ADVANCE 20,10 {TO:URGENT_EXIT}
else
ADVANCE 20,10 {TO:EXIT}
endif
ENDGENERATE 1
;*******************************
procedure check_queue
while (1==1)
advance 5
if (R$(Restroom_bus,OCCUPIED) > 5)
move {name:textAgent,text:"Releasing [AC1: AC1$]"}
WAKE Restroom_bus ; all leave
endif
endwhile
endprocedure
;**********************************
procedure component_check_phone
assign myEntity,P$PARAM_A
while (D$(EXIST,P$myEntity)==1)
advance 5
if (R$(Restroom_bus,IS_OCCUPIED_BY,P$myEntity) == 1 && RANDOM < 0.02)
move {name:Text2,text:"Releasing entity P$myEntity [AC1: AC1$]"}
assign urgentExit,1,P$myEntity
mod {number:P$myEntity, color:red}
WAKE Restroom_bus,-1,P$myEntity ; only this entity leaves
endif
endwhile
terminate_ve
endprocedure
;**********************************