A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)
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
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
package demo;
public class CarryDropAgent {
}
// CarryDropSpace
package demo;
public class CarryDropSpace {
}
Next: Adding User-Settable Parameters
Go to Table of Contents
A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)