Class SimuAgent
SimuLauncher
, or transitively by another
agent launched by a SimuLauncher. This is necessary for the SimuAgent to be linked to a
SimuLauncher
.
This ensures that the agent has access to the simulation model, environment, scheduler,
and other simulation-specific components.
Essentially, this ensures that all the agents of one simulation instance share the same
pseudo-random number generator and simulation time.
If the agent is not launched by a SimuLauncher, it will throw an
IllegalStateException
when attempting to access these components.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class madkit.kernel.Agent
Agent.ReturnCode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSimuGroup
(String group) Deprecated, for removal: This API element is subject to removal in a future version.Returns the community associated with the simulation.Returns the engine group associated with the simulation.<E extends SimuEnvironment>
ERetrieves the environment associated with the simulation.Retrieves the simulation engine associated with this agent.<M extends SimuModel>
MgetModel()
Retrieves the simulation model associated with this agent.Returns the model group associated with the simulation.Method which is used by discrete-event simulation activators for doing fine-grained simulations.<S extends Scheduler<?>>
SRetrieves the scheduler associated with the simulation engine.<T extends SimuTimer<?>>
TReturns theSimuTimer
of the current simulation.Retrieves the list of viewer agents associated with the simulation.launchAgent
(Agent agent, int timeout) Launches a new agent.Leaves a specified role in the model group of the simulation.leaveSimuGroup
(String group) Deprecated, for removal: This API element is subject to removal in a future version.leaveSimuRole
(String group, String role) Deprecated, for removal: This API element is subject to removal in a future version.void
Method to be called on simulation startup.Plays a role within the model group of the simulation.prng()
Retrieves the pseudo-random number generator used in the simulation model.requestSimuRole
(String group, String role) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class madkit.kernel.Agent
activate, broadcast, broadcastWithRole, broadcastWithRoleWaitForReplies, checkAgentAddress, createGroup, createGroup, createGroup, end, equals, executeThisAgent, executeThisAgent, exitOnKill, getAgentsWithRole, getAgentWithRole, getKernelAddress, getKernelConfig, getLogger, getMailbox, getName, getNetworkID, getOrganization, getReplyTo, handleRequestActionMessage, hashCode, isAlive, killAgent, killAgent, launchAgent, launchAgent, leaveGroup, leaveRole, live, nextMessage, onActivation, onEnd, onLive, pause, receiveMessage, reload, reply, replyWithRole, requestRole, requestRole, send, send, sendWaitReply, sendWaitReply, sendWithRole, sendWithRole, sendWithRoleWaitReply, sendWithRoleWaitReply, setupDefaultGUI, toString, waitAnswer, waitAnswer, waitNextMessage, waitNextMessage
-
Constructor Details
-
SimuAgent
public SimuAgent()
-
-
Method Details
-
getLauncher
Retrieves the simulation engine associated with this agent.- Returns:
- the
SimuLauncher
instance. - Throws:
IllegalStateException
- if the agent has not been launched or was not launched by aSimuAgent
.
-
launchAgent
Launches a new agent. If the agent being launched is also aSimuAgent
, it will inherit the simulation engine from this agent.- Overrides:
launchAgent
in classAgent
- Parameters:
agent
- the agent to be launched.timeout
- the maximum time to wait for the agent to launch.- Returns:
- the result of the launch operation as a
Agent.ReturnCode
.
-
getCommunity
Returns the community associated with the simulation.- Returns:
- the name of the simulation community.
-
getEngineGroup
Returns the engine group associated with the simulation.- Returns:
- the name of the engine group.
-
getModelGroup
Returns the model group associated with the simulation.- Returns:
- the name of the model group.
-
getScheduler
Retrieves the scheduler associated with the simulation engine.- Type Parameters:
S
- the type of the scheduler.- Returns:
- the scheduler instance.
-
getModel
Retrieves the simulation model associated with this agent.- Type Parameters:
M
- the type of the simulation model.- Returns:
- the simulation model instance.
-
getEnvironment
Retrieves the environment associated with the simulation.- Type Parameters:
E
- the type of the environment.- Returns:
- the environment instance.
-
prng
Retrieves the pseudo-random number generator used in the simulation model.- Overrides:
prng
in classAgent
- Returns:
- the
RandomGenerator
instance.
-
getViewers
-
onSimulationStart
public void onSimulationStart()Method to be called on simulation startup. This can be overridden by subclasses to perform initialization tasks. This method is the latest method called by the launcher on all the engine agents before giving to the scheduler the control of the simulation. This provided that, at this point of the launching process, the simulation is ready to start, i.e.: all the agents participating in the simulation have been launched, and already have theirAgent.onActivation()
method called.More precisely, this call is done on the engine agents, by the launcher, in the following order: (1) the
Scheduler
, (2) theSimuModel
, (3) theSimuEnvironment
, and (4) on all the Viewer agents.It is worth noting that, by default, this method is not called on the simulated agents, because the default implementation of
SimuLauncher
does not have access to them. Still it is easy to specialize the launcher to achieve this, or by using aProbe
in any of the engine agents.So, it can be overridden to perform any action that could be useful before the simulation starts.
By default, this method does nothing, except for the
SimuLauncher
which will start the simulation. -
requestSimuRole
@Deprecated(since="6.0.1", forRemoval=true) public Agent.ReturnCode requestSimuRole(String group, String role) Deprecated, for removal: This API element is subject to removal in a future version.Requests a role within the simulation community.Deprecated since 6.0.1. It is considered as just overloading the API for no good reason. Use
Agent.requestRole(String, String, String)
or playRole(String)} instead.- Parameters:
group
- the group within which the role is requested.role
- the role to be requested.- Returns:
- the result of the role request as a
Agent.ReturnCode
.
-
playRole
Plays a role within the model group of the simulation.This method is equivalent to calling
It is provided as a convenience method for agents that need to play roles within the simulation model.requestRole(getCommunity(), getModelGroup(), role)
.- Parameters:
role
- the role- Returns:
- the return code
-
createSimuGroup
Deprecated, for removal: This API element is subject to removal in a future version.Creates a simulation group with the specified name in the simulation community.Deprecated since 6.0.1. It is considered as just overloading the API for no good reason. Use
Agent.createGroup(String, String)
instead.- Parameters:
group
- the name of the group to be created- Returns:
- a ReturnCode indicating the result of the group creation
-
leaveSimuRole
@Deprecated(since="6.0.1", forRemoval=true) public Agent.ReturnCode leaveSimuRole(String group, String role) Deprecated, for removal: This API element is subject to removal in a future version.Leaves a specified role in the given simulation group.Deprecated since 6.0.1. It is considered as just overloading the API for no good reason. Use
Agent.leaveRole(String, String, String)
orleaveRole(String)
instead.- Parameters:
group
- the name of the group from which to leave the rolerole
- the name of the role to be left- Returns:
- a ReturnCode indicating the result of leaving the role
-
leaveRole
Leaves a specified role in the model group of the simulation.This method is equivalent to calling
leaveRole(getCommunity(), getModelGroup(), role)
.- Parameters:
role
- the name of the role to be left- Returns:
- a ReturnCode indicating the result of leaving the role
-
leaveSimuGroup
Deprecated, for removal: This API element is subject to removal in a future version.Leaves the specified simulation group.Deprecated since 6.0.1. It is considered as just overloading the API for no good reason. Use
Agent.leaveGroup(String, String)
instead.- Parameters:
group
- the name of the group to be left- Returns:
- a ReturnCode indicating the result of leaving the group
-
getSimuTimer
Returns theSimuTimer
of the current simulation. This is automatically initialized when the agent is associated with an activator for the first time. So it staysnull
if the agent is not related to a simulation- Returns:
- the simulationTime of the simulation in which the agent participates
- Throws:
NullPointerException
- if this agent is not part of a simulation
-
getNextEventDate
Method which is used by discrete-event simulation activators for doing fine-grained simulations. By default, this method returns an event which is one second ahead of the current date of the simulation. So, this method can be overridden to fulfill the simulation requirement- Returns:
- the date of the next event for this agent.
- Throws:
ClassCastException
- if the agent is not part a simulation whose scheduling is based on aDateBasedTimer
- See Also:
-