Model Context

Last updated on 6th May 2024

The Context of a model is the wrapper holding information about it.

Accessing the Context of a model

In the Context, you can find the seed of the model (its pseudo random number generator), the tick of the simulation and its configuration. More on Model Config

To get the Context, you can use the getContext() method. This method can be called on any AgentBasedModel, SystemDynamicsModel and AgentSystem.

public class Housing implements AgentBasedModel<GlobalState> {

  public int function(){
     return getContext().getTick(); 
  }  
}

Once you have the Context you have the ability to get a variety of information such as:

  • The getPRNG() method will return the SeededRandom object associated with your model.
  • The getTick() method will return the tick number your simulation is on when you call it.
  • The getKickOff() method will return the tick number specified by usage of the kickoff annotation in @ModelSettings
  • The getEnd() method will return the tick number specified by usage of the end annotation in @ModelSettings
  • The getSessionID() method will return the UUID of the simulation which may be useful for outputting to other processess.
  • Finally, you can also get the Configuration from the Context by calling getConfig().
public class Housing implements AgentBasedModel<GlobalState> {

  public void function(){
     getContext().getTick(); // getting the current Tick of the Simulation
     getContext().getPRNG(); // getting the prng of the model
     getContext().getConfig(); // accessing the configuration of the Model
  }  
}