- Description
- Nested Class Summary
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- onActivation()
- onCreateRandomGenerator()
- setPRNGSeedIndex(int)
- getPRNGSeedIndex()
- onInitializeSimulationSeedIndex()
- onSimulationStart()
- onLaunchModel()
- onLaunchEnvironment()
- onLaunchScheduler()
- onLaunchViewers()
- onLaunchSimulatedAgents()
- startSimulation()
- getScheduler()
- getEnvironment()
- getModel()
- getEngineAgentsArgsFrom(Class)
- getModelGroup()
- getCommunity()
- getEngineGroup()
- getViewers()
- prng()
- setRandomGnerator(RandomGenerator)
Class SimuLauncher
This class is intended to be extended by the user to define the simulation engine, if
the default setup should customized. The user can define the simulation environment,
model, and scheduler classes by overriding the onLaunchEnvironment()
,
onLaunchModel()
, and onLaunchScheduler()
methods, respectively. The
user can also define the simulation agents and viewers by overriding the
onLaunchSimulatedAgents()
and onLaunchViewers()
methods,
respectively. The user can also define the simulation startup behavior by overriding
the onSimulationStart()
method.
Crucially, this class is also responsible for initializing the pseudo random number
generator (PRNG) that has to be used by the simulation agents for ensuring the
reproducibility of the simulation. The PRNG is initialized with a seed that can be set
by the user. The seed is a long integer that can be set by the user by overriding the
onInitializeSimulationSeedIndex()
method. By default, the seed index is 0.
See onInitializeSimulationSeedIndex()
method.
-
Nested Class Summary
Nested classes/interfaces inherited from class madkit.kernel.Agent
Agent.ReturnCode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the name of the simulation community.getEngineAgentsArgsFrom
(Class<?> target) Gets the engine agents args from.Returns the engine group associated with the simulation.<E extends SimuEnvironment>
EGets the environment.<M extends SimuModel>
MgetModel()
Gets the model.Returns the model group associated with the simulation.long
Returns the seed used to create the PRNG.<S extends Scheduler<?>>
SGets the scheduler.Returns the the viewers that are actually running.protected void
This method is called when the simulation engine is activated.Creates the pseudo random number generator that has to be used by the simulation.void
Initializes the simulation seed index.protected <E extends SimuEnvironment>
ELaunches the simulation environment agent and logs the event.protected <M extends SimuModel>
MReturns the seed used to create the PRNG.protected <S extends Scheduler<?>>
SLaunches the simulation scheduler agent and logs the event.protected abstract void
Launches the simulation agents.protected void
Launches the simulation viewers agents and logs their launch.void
Called before the simulation starts.prng()
Returns the pseudo random number generator that has to be used by the simulation agents.void
setPRNGSeedIndex
(int seedIndex) Sets the seed which is used to create a PRNG.void
setRandomGnerator
(RandomGenerator randomGenerator) Sets the pseudo random number generator that has to be used by the simulation.protected void
Start simulation.Methods inherited from class madkit.kernel.Watcher
addProbe, getProbes, onEnd, removeAllProbes, removeProbe, toString
Methods inherited from class madkit.simulation.SimuAgent
createSimuGroup, getLauncher, getNextEventDate, getSimuTimer, launchAgent, leaveRole, leaveSimuGroup, leaveSimuRole, playRole, requestSimuRole
Methods inherited from class madkit.kernel.Agent
activate, broadcast, broadcastWithRole, broadcastWithRoleWaitForReplies, checkAgentAddress, createGroup, createGroup, createGroup, end, executeThisAgent, executeThisAgent, exitOnKill, getAgentsWithRole, getAgentWithRole, getKernelAddress, getKernelConfig, getLogger, getMailbox, getName, getNetworkID, getOrganization, getReplyTo, handleRequestActionMessage, hashCode, isAlive, killAgent, killAgent, launchAgent, launchAgent, leaveGroup, leaveRole, live, nextMessage, onLive, pause, receiveMessage, reload, reply, replyWithRole, requestRole, requestRole, send, send, sendWaitReply, sendWithRole, sendWithRole, sendWithRoleWaitReply, sendWithRoleWaitReply, setupDefaultGUI, waitAnswer, waitAnswer, waitNextMessage, waitNextMessage
-
Constructor Details
-
Method Details
-
onActivation
protected void onActivation()This method is called when the simulation engine is activated. It initializes the simulation community, creates the engine and model groups, and requests the roleSimuOrganization.LAUNCHER_ROLE
in the groupSimuOrganization.ENGINE_GROUP
. Then, it initiates the simulation by first creating the pseudo random number generator by calling theonCreateRandomGenerator()
. Then, it launches the simulation model, environment, scheduler, and viewers by calling in order theonLaunchModel()
,onLaunchEnvironment()
,onLaunchScheduler()
,onLaunchViewers()
, andonLaunchSimulatedAgents()
methods. Finally, it calls theonSimulationStart()
method. If the start parameter is set totrue
, it starts the simulation by calling thestartSimulation()
By default the logger level is set to
Level.INFO
.- Overrides:
onActivation
in classWatcher
-
onCreateRandomGenerator
Creates the pseudo random number generator that has to be used by the simulation. The seed index is taken from the kernel configuration. If the seed index is not set, the default value is 0.- Returns:
- the pseudo random number generator that will be used by the simulation
-
setPRNGSeedIndex
public void setPRNGSeedIndex(int seedIndex) Sets the seed which is used to create a PRNG. The actual seed that will be used will be computed by adding seedIndex to the built-in long (0xFEDCBA0987654321L), which is used as initial seed. This is done so that the obtained long respects the many seed bits characteristic. Moreover it is known that a good practice, considering how seeds should be chosen, is to take them in sequence. See this blog: Random number generator seed mistakes So a simulation suite can be obtained by using this method with a consecutive list of int: 1, 2, 3...- Parameters:
seedIndex
- the seed index to set. Privilege the use of sequence of integers such as 0, 1, 2...
-
getPRNGSeedIndex
public long getPRNGSeedIndex()Returns the seed used to create the PRNG.- Returns:
- the seed used to create the PRNG
-
onInitializeSimulationSeedIndex
public void onInitializeSimulationSeedIndex()Initializes the simulation seed index. By default, the seed index is taken from the kernel configuration, and if not set the seed index is set 0. -
onSimulationStart
public void onSimulationStart()Called before the simulation starts. By default, it calls theScheduler.onSimulationStart()
,SimuAgent.onSimulationStart()
,SimuAgent.onSimulationStart()
, andSimuAgent.onSimulationStart()
methods for each viewer.This method can be overridden by the user to define fine tuning of the simulation initialization.
- Overrides:
onSimulationStart
in classSimuAgent
-
onLaunchModel
Returns the seed used to create the PRNG.- Type Parameters:
M
- the type of the model- Returns:
- the model agent for this simulation
-
onLaunchEnvironment
Launches the simulation environment agent and logs the event.- Type Parameters:
E
- the type of the environment- Returns:
- the environment agent for this simulation
-
onLaunchScheduler
Launches the simulation scheduler agent and logs the event.- Type Parameters:
S
- the type of the scheduler- Returns:
- the scheduler agent for this simulation
-
onLaunchViewers
protected void onLaunchViewers()Launches the simulation viewers agents and logs their launch. -
onLaunchSimulatedAgents
protected abstract void onLaunchSimulatedAgents()Launches the simulation agents. -
startSimulation
protected void startSimulation()Start simulation. -
getScheduler
Gets the scheduler.- Overrides:
getScheduler
in classSimuAgent
- Type Parameters:
S
- the generic type- Returns:
- the scheduler
-
getEnvironment
Gets the environment.- Overrides:
getEnvironment
in classSimuAgent
- Type Parameters:
E
- the element type- Returns:
- the environment
-
getModel
-
getEngineAgentsArgsFrom
public static final List<String> getEngineAgentsArgsFrom(Class<?> target) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException Gets the engine agents args from.- Parameters:
target
- the target- Returns:
- the engine agents args from
- Throws:
IllegalAccessException
- the illegal access exceptionInvocationTargetException
- the invocation target exceptionNoSuchMethodException
- the no such method exceptionSecurityException
- the security exception
-
getModelGroup
Returns the model group associated with the simulation.- Overrides:
getModelGroup
in classSimuAgent
- Returns:
- the model group
-
getCommunity
Returns the name of the simulation community.- Overrides:
getCommunity
in classSimuAgent
- Returns:
- the community
-
getEngineGroup
Returns the engine group associated with the simulation.- Overrides:
getEngineGroup
in classSimuAgent
- Returns:
- the name of the engine group
-
getViewers
Returns the the viewers that are actually running.- Overrides:
getViewers
in classSimuAgent
- Returns:
- the running viewers
-
prng
Returns the pseudo random number generator that has to be used by the simulation agents. -
setRandomGnerator
Sets the pseudo random number generator that has to be used by the simulation.- Parameters:
randomGenerator
- the randomGenerator to set
-