fr.lifl.jedi.controllersCore.simulationRun
Class SimulationCore

java.lang.Object
  extended by java.util.Observable
      extended by fr.lifl.jedi.controllersCore.util.EventNotified
          extended by fr.lifl.jedi.controllersCore.simulationRun.SimulationCore
All Implemented Interfaces:
java.util.Observer

public abstract class SimulationCore
extends EventNotified

The core of a simulation.

This class defines how the simulation is initialized, and proposes a mechanism to run it.

In JEDI, simulations run in discrete sequential time. Time is a discrete set of integers (a discrete set of time steps). During each time step, every agent has the opportunity to intiate interactions once. The order agents initiate interactions is defined by the AgentOrderingPolicy attribute of the simulations core constructor. By default, the ordering policy is a random one.

Running a simulation requires the definition of different methods for this class :

Adding to that, optional methods can be defined :

After each simulation step, the simulation core sends an FromSimulationCoreEvent containing its new state SimulationCoreStates.WAITING_FOR_GUI_AFTER_A_STEP_STATE to every controller that observes the simulation core. It tells them to update the GUI they control. The simulation will perform its next step only when all GUI finished their update.

At the end of the simulation, the simulation core sends an FromSimulationCoreEvent containing its new state SimulationCoreStates.WAITING_FOR_GUI_AFTER_SIMULATION_END_STATE to every controller that observes the simulation core. It tells them to perform some processing at the end of a simulation. The simulation can be initialized again only when all GUI finished their processing.

When the simulation is aborted, the simulation core sends an FromSimulationCoreEvent containing its new state SimulationCoreStates.WAITING_FOR_GUI_AFTER_SIMULATION_ABORTION_STATE to every controller that observes the simulation core. It tells them to perform some processing when the simulation is aborted. The simulation can be initialized again only when all GUI finished their processing.

When the exit of the program is requested, the simulation core sends an FromSimulationCoreEvent containing its new state SimulationCoreStates.WAITING_FOR_GUI_BEFORE_CLOSING_STATE to every controller that observes the simulation core. The program exits only when all GUI finished their processing.

Version:
JEDI V 2.2
Created the 2nd april 2009
Modified the 5th may 2009
Author:
Yoann Kubera
SMAC Team (Systèmes Multi-Agents et Comportement)
LIFL (Laboratoire d'Informatique Fondamentale de Lille)
University of Lille, France

Field Summary
protected  SimulationCoreStates currentState
          The current state of the simulation core.
protected  Environment environment
          The environment where the simulation will take place.
protected  SimulationThread runnable
          The runnable instance used to run the simulation.
 
Constructor Summary
SimulationCore(AbstractControlGUIController<?> guiControl, AgentOrderingPolicy policy, Environment env)
          Constructor of the simulation core.
SimulationCore(AbstractControlGUIController<?> guiControl, Environment env)
          Constructor of the simulation core, which execution is controlled by buttons.
SimulationCore(AgentOrderingPolicy policy, Environment env)
          Constructor of the simulation core, which execution is controlled by buttons.
SimulationCore(Environment env)
          Constructor of the simulation core, which execution is controlled by buttons.
 
Method Summary
 void afterRun()
          Does some post-processing, after the end of the simulation.
 void afterStep()
          Does some post-processing after every simulation time steps.
 void beforeRun()
          Does some pre-processing, before starting the simulation.
 void beforeStep()
          Does some pre-processing before every simulation time steps.
 AgentOrderingPolicy getAgentOrderingPolicy()
          Gets the agent ordering policy.
 int getCurrentSimulationStep()
          Gets the current simulation step of the thread that runs the simulation.
 SimulationCoreStates getCurrentState()
          Gets the current state of the simulation.
 Environment getEnvironment()
          Gets the environment where the simulation occurs.
abstract  boolean hasToStop()
          Checks if the simulation has to end.
abstract  void initialize()
          Initializes the simulation.
 void processEvent(java.util.Observable o, java.lang.Object event)
          A method that processes a particular event.
protected  void processEventFromControlGUI(SimulationCoreStates state, ToSimulationCoreControlEvents event)
          Performs the adequate processing depending on which control event was received.
 void registerGUIControler(AbstractGUIController<?> guiCtrl)
          Registers a GUI controller to this simulation core.
 
Methods inherited from class fr.lifl.jedi.controllersCore.util.EventNotified
update
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentState

protected SimulationCoreStates currentState
The current state of the simulation core.


runnable

protected SimulationThread runnable
The runnable instance used to run the simulation.


environment

protected Environment environment
The environment where the simulation will take place.

Constructor Detail

SimulationCore

public SimulationCore(AbstractControlGUIController<?> guiControl,
                      AgentOrderingPolicy policy,
                      Environment env)
Constructor of the simulation core.

Parameters:
guiControl - The controler associated with the gui element that rules simulations execution.
policy - The ordering policy used to reorder agents at the beginning of every time step.
env - The environment where the simulation takes place.

SimulationCore

public SimulationCore(AbstractControlGUIController<?> guiControl,
                      Environment env)
Constructor of the simulation core, which execution is controlled by buttons.

Parameters:
guiControl - The controller associated with the gui element that rules simulations execution.
env - The environment where the simulation takes place.

SimulationCore

public SimulationCore(AgentOrderingPolicy policy,
                      Environment env)
Constructor of the simulation core, which execution is controlled by buttons.

Parameters:
policy - The ordering policy used to reorder agents at the beginning of every time step.
env - The environment where the simulation takes place.

SimulationCore

public SimulationCore(Environment env)
Constructor of the simulation core, which execution is controlled by buttons.

Parameters:
env - The environment where the simulation takes place.
Method Detail

getEnvironment

public Environment getEnvironment()
Gets the environment where the simulation occurs.

Returns:
the environment where the simulation occurs.

getAgentOrderingPolicy

public AgentOrderingPolicy getAgentOrderingPolicy()
Gets the agent ordering policy.

This policy is used to reorder agents at the beginning of every time step.

Returns:
the agent ordering policy.

getCurrentSimulationStep

public int getCurrentSimulationStep()
Gets the current simulation step of the thread that runs the simulation.

Returns:
the current simulation step of the thread that runs the simulation. If no simulation is currently initialized or running, then it returns -1.

registerGUIControler

public void registerGUIControler(AbstractGUIController<?> guiCtrl)
Registers a GUI controller to this simulation core.

When a GUI has to display informations about the simulation, it will observe the simulation thanks to a call to this method.

Parameters:
guiCtrl - the GUI controller to register.

getCurrentState

public SimulationCoreStates getCurrentState()
Gets the current state of the simulation.

Returns:
the current state of the simulation.

initialize

public abstract void initialize()
Initializes the simulation.

This method creates all agent instances used in the simulation, and put them in the environment thanks to the Environment.putAgent(Agent, double, double) method.


beforeRun

public void beforeRun()
Does some pre-processing, before starting the simulation. By default, this method is empty.


afterRun

public void afterRun()
Does some post-processing, after the end of the simulation. By default, this method is empty.


beforeStep

public void beforeStep()
Does some pre-processing before every simulation time steps. By default, this method is empty.


afterStep

public void afterStep()
Does some post-processing after every simulation time steps. By default, this method is empty.


hasToStop

public abstract boolean hasToStop()
Checks if the simulation has to end.

If true, the simulation will stop.

Returns:
true if the simulation has to end.

processEvent

public void processEvent(java.util.Observable o,
                         java.lang.Object event)
Description copied from class: EventNotified
A method that processes a particular event.

Specified by:
processEvent in class EventNotified
Parameters:
o - The observer that sent the event.
event - The event to process
See Also:
EventNotified.processEvent(java.util.Observable, java.lang.Object)

processEventFromControlGUI

protected void processEventFromControlGUI(SimulationCoreStates state,
                                          ToSimulationCoreControlEvents event)
Performs the adequate processing depending on which control event was received.

Parameters:
state - The current state of the simulation core.
event - The event that was thrown by the controller of the control GUI.