public abstract class

RunnableSimulation

extends Object
implements Runnable
java.lang.Object
   ↳ uk.ac.imperial.presage2.core.simulator.RunnableSimulation

Class Overview

Implements the Presage2 simulation loop. Loads a simulation either from command-line invocation or database id.

Summary

Fields
public int finishTime Maximum number of simulation timesteps.
protected int threads The number of threads to use for schedule execution.
Public Constructors
RunnableSimulation()
Default constructor.
Public Methods
void addModule(AbstractModule module)
Add a module to the simulation specification.
void addObjectClass(Class<?> clazz)
Adds a class to the simulation which is automatically instantiated via the Injector.
final void addToSchedule(Object o)
boolean finishTimeCondition(int t)
abstract void initialiseScenario(Scenario scenario)

Initialise scenario elements.

final static void main(String[] args)

Run a single simulation from commandline arguments.

void run()
Runs a full simulation from the specification provided by the overriding class implementation and provided parameters.
final static void runSimulationID(long simID, int threads)
Run a simulation from a parameter set stored in a database, and identified by a simID.
Protected Methods
void finish()
void initialise()
void loadParameters(Map<StringString> provided)
void step()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Runnable

Fields

public int finishTime

Maximum number of simulation timesteps. This field is used by the finishTimeCondition(int) to prevent unbounded simulation execution. Additional conditions can preempt simulation completion.

protected int threads

The number of threads to use for schedule execution.

Public Constructors

public RunnableSimulation ()

Default constructor. Does not initialise object until run() is called.

Public Methods

public void addModule (AbstractModule module)

Add a module to the simulation specification. May only be done during the initialisation phase of the simulation, usually in an initialiseScenario(Scenario) implementation.

Parameters
module AbstractModule to add.
Throws
RuntimeException if called after the Injector has been created, and so this module can no longer be used for the simulation.

public void addObjectClass (Class<?> clazz)

Adds a class to the simulation which is automatically instantiated via the Injector. These objects are automatically added the the scenario objects. If called before simulation initialisation objects are created at initialisation time, otherwise it is done immediately.

public final void addToSchedule (Object o)

public boolean finishTimeCondition (int t)

public abstract void initialiseScenario (Scenario scenario)

Initialise scenario elements.

Elements can be added in three ways:

  1. Adding instantiated objects and agents through the provided Scenario.
  2. Adding modules using addModule(AbstractModule).
  3. Adding object classes using addObjectClass(Class) which will be instantiated automatically by the simulator

public static final void main (String[] args)

Run a single simulation from commandline arguments. Takes the following parameters:

simulation_class_name simulation_parameter=parameter_value...

Where simulation_class_name is the fully qualified name of a class which implements RunnableSimulation and is visible to this class (i.e. public), and simulation_parameter=parameter_value are key/value pairs for simulation parameters. This pairs should correspond to Parameter annotations on fields or methods within the RunnableSimulation we are running. The key is the name assigned to each Parameter inside the annotations. These fields and methods must be public in order for use to insert the provided values in.

Throws
ClassNotFoundException
NoSuchMethodException
InvocationTargetException
InstantiationException
IllegalAccessException
UndefinedParameterException
IllegalArgumentException
IllegalAccessException
UndefinedParameterException
ClassNotFoundException
NoSuchMethodException
InvocationTargetException
InstantiationException

public void run ()

Runs a full simulation from the specification provided by the overriding class implementation and provided parameters.

public static final void runSimulationID (long simID, int threads)

Run a simulation from a parameter set stored in a database, and identified by a simID.

Parameters
simID long identifier of the parameter set in the database.
threads int number of threads to use in the simulator
Throws
Exception

Protected Methods

protected void finish ()

protected void initialise ()

protected void loadParameters (Map<StringString> provided)

Throws
IllegalArgumentException
IllegalAccessException
UndefinedParameterException

protected void step ()