How to Build a Repast Model - 2

Contents

This document describes how to build Repast models using the SimModelImpl class. Such models are more complicated to code, but can take fuller advantage of Repast's capabilities. This document is intended for users whose models require such capabilities or who have some experience in writing agent-based simulations. Other users should see How to Build a Repast Model - 1 if you have not already.

Note: This how to is best read together with the source code from the sample simulations.

Overview
The kinds of simulations that can be written using Repast fall into two broad categories: batch-run, and non-batch run. A batch run simulation reads in a specially formatted parameter file detailing the starting and ending values of a model's parameters, how to increment these parameters and the number of runs to complete. The simulation then begins to run without user interference.

A non-batch run requires a user to start and stop a run through a graphical user interface, and allows the user to graphically set starting parameters. In addition a non-batch simulation allows a user to graphically display and manipulate (i.e. probe) an agent's state during the course of a run, as well as the models.

What follows explains the basics of how to write both these kinds of simulations, paying special attention to what must done for a model to set the initial parameters from a parameter file, to allow a user to graphically set starting parameters, and to allow probing to occur.

The Agent
Both batch and non-batch run simulations are largely similar. A typical simulation of either kind written with Repast will have at least two classes written by the user, the agent class and the model class. (See the source code to the sample simulations for detailed examples). The agent class will be largely simulation specific, although Repast does provide some minimal (at this time) support for cooperation type agents, through the GameAgent interface and the Game abstract class. If the agent is to be displayed, it should implement one of the Drawable interfaces (see How To Create Displays for more). If a user wishes an agent to be probeable, that is, have its state graphically displayable and manipulable, the agent must be coded using the Accessor method pattern.

The Model
A model, such as SugarModel.java or EnnModel.java (in repast/demos/sugarscape/src/src/uchicago/src/sim/sugarScape and repastdemos/enn/src/src/uchicago/src/sim/enn respectively) sets up and controls both the representational and infrastructure parts of a Repast simulation. All Repast simulation models must implement the
SimModel interface. Repast provides an abstract class SimModelImpl that partialy implements this interface and it is expected that most if not all models will extend this class.

Assuming then that a user is writing his or her own model that extends SimModelImpl , a typical model class should have the following parts:

Both batch and non-batch models should follow this general structure, although in the case of a batch model the buildDisplay method is not necessary.

Batch Parameters
The get/set method pattern is used differently by a batch model. Just as a non-batch model's initial parameters can be displayed and manipulated through its get and set methods, a non-batch model uses the same methods to set its initial parameters from a parameter file. See
How To Use Parameters and Parameter Files for more information.