A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)

The CarryDrop model

Let's assume we want to create a basic RePast model with the following characteristics:

To achieve this, we will need three files: the class that instantiates the SimModel object, a class specifying the agents, and a class describing the space. Create these three classes in a new package and name them:

Carry Drop Model will include the Main method, which will instantiate the SimModel object in a manner to be discussed. The code for the three files, using the template discussed in the previous section, is initially as follows (note that we keep the 'NumAgents' parameter):

CarryDropModel

// CarryDropModel
package demo;

import uchicago.src.sim.engine.Schedule;
import uchicago.src.sim.engine.SimModelImpl;

public class CarryDropModel extends SimModelImpl {

  private Schedule schedule;
  private int numAgents;

  public String getName(){
    return "Carry And Drop";
  }

  public void setup(){
  }

  public void begin(){
    buildModel();
    buildSchedule();
    buildDisplay();
  }

  public void buildModel(){
  }

  public void buildSchedule(){
  }

  public void buildDisplay(){
  }

  public Schedule getSchedule(){
    return schedule;
  }

  public String[] getInitParam(){
    String[] initParams = { "NumAgents" };
    return initParams;
  }

  public int getNumAgents(){
    return numAgents;
  }

  public void setNumAgents(int na){
    numAgents = na;
  }

  public static void main(String[] args) {
  }

}

CarryDropAgent

// CarryDropAgent
package demo;

public class CarryDropAgent {

}

CarryDropSpace

// CarryDropSpace
package demo;

public class CarryDropSpace {

}

Previous: The SimModel Object

Next: Adding User-Settable Parameters

Go to Table of Contents


A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)