Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop.

Similar presentations


Presentation on theme: "Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop."— Presentation transcript:

1 Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop

2 Elements of a RePast Model 1.Model Object—acts as the model itself 2.Space Object—controls the environment 3.Agent Object

3 The (Sim)Model Object Model object will extend RePast’s SimModelImpl object. It will react to the RePast control toolbar.

4 The SimModel Object—getName() getName() replaces ‘RePast’ with the name of the project on the control toolbar. import uchicago.src.sim.engine.SimModelImpl; public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; }

5 The SimModel Object—begin() begin() initializes the model. import uchicago.src.sim.engine.SimModelImpl; public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; } public void begin(){ }

6 The SimModel Object—tradition RePast models traditionally have a consistent ‘map’ to their model classes. We will divide the begin() method into three other methods. Thus, we will add the following code. public void begin(){ buildModel(); buildSchedule(); buildDisplay(); } public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ }

7 The SimModel Object—current code import uchicago.src.sim.engine.SimModelImpl; public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; } public void begin(){ buildModel(); buildSchedule(); buildDisplay(); } public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ } }

8 The SimModel Object—setup() The setup() function returns the model to the initial condition. public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; } public void setup(){ } public void begin(){ […]

9 The SimModel Object—Schedule Schedule manages the execution of BasicAction according to the simulation clock. Each tick is completed at the end of all BasicAction executions. Actions scheduled on a Schedule will be executed in random order.

10 The SimObject Model--Schedule import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.engine.Schedule; public class MyFirstRePastModel extends SimModelImpl { private Schedule schedule; public String getName(){ return “My First RePast Model”; } public void begin(){ buildModel(); buildSchedule(); buildDisplay(); } public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ } public Schedule getSchedule(){ return schedule; } }

11 The SimModel Object--getInitParam getInitParam returns an array of String variables (e.g., N agents) This will change Ns by using the ‘setup’ and ‘initialize’ buttons. Two important factors: You must supply RePast with a list of the parameters you want to vary, in this case ‘NumAgents.’ You must create ‘get’ and ‘set’ methods for each parameter in the list.

12 The SimModel Object--numAgents First, lets insert the variable into our code. import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.engine.Schedule; public class MyFirstRePastModel extends SimModelImpl { private Schedule schedule; private int numAgents; public String getName(){ return “My First Repast Model”; } […]

13 The SimModel Object--numAgents Next, RePast structure requires us to provide ‘get’ and ‘set’. public Schedule getSchedule(){ return schedule; } public int getNumAgents(){ return numAgents; } public void setNumAgents (int na){ numAgents=na; }

14 The SimModel Object--numAgents Next, RePast structure requires us to provide ‘get’ and ‘set’. public Schedule getSchedule(){ return schedule; } public String[] getInitParam(){ String[] initParams = {“NumAgents”}; return initParams; } public int getNumAgents(){ return numAgents; }

15 The CarryDrop Model--Introduction We want to create a model with the following characteristics. Agents move around a gridded landscape Each cell may contain money. Agents always move in a straight line in one of the eight neighborhood directions. When an agents moves into another agent’s square, the moving agent gives money to the other. Agents have a different lifespan between max. and min. values. When it dies, the money is spread randomly and is replaced.

16 The CarryDrop model To accomplish this, we will need three files The class that instantiates the SimModel object CarryDropModel A class specifying the agents CarryDropAgent A class describing the space CarryDropSpace [To be continues at http://www.u.arizona.edu/~jtmurphy/H2R/HowTo03.htm]


Download ppt "Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop."

Similar presentations


Ads by Google