A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)
Now let's look at some trivia. You will notice when the model is run that the values in the GUI are all zeros. This is an unlikely way to start the model, and so you would like to provide default values. The technique we will employ is to create default values as separate variables; we will choose 100 for NumAgents, and 40 for X and Y world size.
// CarryDropModel
package demo;
import uchicago.src.sim.engine.Schedule;
import uchicago.src.sim.engine.SimInit;
import uchicago.src.sim.engine.SimModelImpl;
public class CarryDropModel extends SimModelImpl {
// Default Values
private static final int NUMAGENTS = 100;
private static final int WORLDXSIZE = 40;
private static final int WORLDYSIZE = 40;
private int numAgents = NUMAGENTS;
private int worldXSize = WORLDXSIZE;
private int worldYSize = WORLDYSIZE;
private Schedule schedule;
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" , "WorldXSize", "WorldYSize" };
return initParams;
}
public int getNumAgents(){
return numAgents;
}
public void setNumAgents(int na){
numAgents = na;
}
public int getWorldXSize(){
return worldXSize;
}
public void setWorldXSize(int wxs){
worldXSize = wxs;
}
public int getWorldYSize(){
return worldYSize;
}
public void setWorldYSize(int wys){
worldYSize = wys;
}
public static void main(String[] args) {
SimInit init = new SimInit();
CarryDropModel model = new CarryDropModel();
init.loadModel(model, "", false);
}
}
// CarryDropAgent
package demo;
public class CarryDropAgent {
}
// CarryDropSpace
package demo;
public class CarryDropSpace {
}
So far this is meaningless overhead, but it is good coding practice to have default values defined as constant variables.
Previous: Compiling and Running the Basic Model
Go to Table of Contents
A RePast Tutorial by John T. Murphy, University of Arizona & Arizona State University (contact)