Model Interface

Last updated on 16th July 2024

The Model is the main abstraction in the Simudyne SDK. It incorporates all the elements required to build and run a simulation from setup to teardown.

The Model Interface below outlines three stages. Let's describe them as well as the model flow in more detail.

General Flow

Model#step: defining computations and operations at each step

One iteration in your simulation involves a set of steps. At this stage, you need to specify calculations in your model to form a step. These are then run in order to complete one iteration of your simulation.

Defining a step (Java)

public class MyModel implements Model {
  @Variable int myVariable = 1;

  @Override
  public void step() {
    myVariable *= 1.1;
  }
}

Model#setup(): defining pre-simulation calculations and operations

Each model requires a setup phase. In the Model Interface diagram this occurs at setup() between the console and the model.

Nothing happens in this setup phase by default but you can trigger a specific setup by defining calculations and operations at Model#setup().

Specifying a setup (Java)

public class MyModel implements Model {
  @Variable int myVariable;

  @Override
  public void setup() {
    SeededRandom ran = new SeededRandom();
    myVariable = ran.uniform(-1,1).sample();
  }

  @Override
  public void step() {
    myVariable *= 1.1;
  }
}

Model#dispose(): specifying a tear-down

On completion of your simulation, you may want to save results as a file or to perform specific tear-down operations. This can be done by defining dispose() in your model.

Model#getConfig(): getting access to the simulation configuration

From the model, you can get access to the ModelConfig. This ModelConfig contains the set of values for the parameters of the model. These specific settings within your simulation are important especially when it comes to distributing your model.

More on Model Config

Introducing the Agent Based flavour

To create Agent Based Models, extend AgentBasedModel.

AgentBasedModels (Java)

public class MyModel extends AgentBasedModel<GlobalState> {
  @Variable int myVariable;

  @Override
  public void setup() {
    SeededRandom ran = new SeededRandom();
    myVariable = ran.uniform(-1,1).sample();
  }

  @Override
  public void step() {
    myVariable += 1;
  }
}

Several setup operations are required for AgentBasedModel at the first stage of building the simulation model. These have to be defined at setup().

More on Agent Based Models