1 / 16

The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy

The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy. by Junjie Sun 8/2/2004 Department of Economics Iowa State University. Review of the Story. Agents move around a grid space Move in one of the eight directions

xadrian
Download Presentation

The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy by Junjie Sun 8/2/2004 Department of Economics Iowa State University

  2. Review of the Story • Agents move around a grid space • Move in one of the eight directions • Each cell may contain money; agents pick it up and carry it with them • Collision compensation; then the agent chooses a new direction • Agent has lifespan; when agent dies, its wealth is spread randomly onto the grid, and the dead agent is replaced with a newly born in a diff. location with a diff. lifespan

  3. Review of Model Structure • CarryDropModel - a class that instantiates the SimModel object • CarryDropAgent - a class specifying the agents • CarryDropSpace - a class describing the space

  4. What’s been done in Step 1-3 • CarryDropModel • Variables: schedule,numAgents • Methods: setup(), begin(), buildModel(), buildSchedule(), buildDisplay(), getName(), getSchedule(), getInitParam(), getNumAgents(), setNumAgents(), main() • CarryDropAgent • CarryDropSpace

  5. Add User-Settable Parameters (Step 4-1) • Number of Agents (NumAgents) • Size of World X (WorldXSize) • Size of World Y (WorldYSize)

  6. Add User-Settable Parameters (Step 4-2) • Add worldXSize & worldYSize as class variables private int worldXSize; private int worldYSize; • Add WorldXSize & WorldYSize to the getInitParam function String[ ] initParams = { "NumAgents" , "WorldXSize", "WorldYSize"}; • Add the get and set methods for these variables, for example, public int getWorldXSize(){ return worldXSize; }

  7. Compiling and Running the Basic Model (Step 5-1) • Create a new project in IDE and add in three .java files, namely, CarryDropModel.java CarryDropAgent.java CarryDropSpace.java • The model won’t do anything, but it should compile and display part of the RePast GUI

  8. Codes to be Added in main Method (Step 5-2) • Creates a new obj. of type SimInit: SimInit init = new SimInit(); • Creates a new object of type CarryDropModel: CarryDropModel model = new CarryDropModel(); • Loads the model using the loadModel method of the Init obj.: init.loadModel(model, "", false);

  9. Default Values for User-Settable Parameters (Step 6) • 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;

  10. Alerts in Subroutines (Step 7) • System.out.println("Running setup"); • System.out.println("Running BuildModel"); • System.out.println("Running BuildSchedule"); • System.out.println("Running BuildDisplay");

  11. The Space Object (Step 8-1) • Define the variable for space object using RePast’s Object2DGrid: private Object2DGrid moneySpace; • Fill moneySpace with Integer objects: public CarryDropSpace(int xSize, int ySize){ moneySpace = new Object2DGrid(xSize, ySize); for(int i = 0; i < xSize; i++){ for(int j = 0; j < ySize; j++){ moneySpace.putObjectAt(i,j,new Integer(0)); } } } }

  12. Q: How can you know the args in the methods / constructors? A: See RePast/Java API (Step 8-2) • Object2DGrid(int xSize, int ySize) Constructs a grid with the specified size. • Integer(int value) Constructs a newly allocated Integer object that represents the primitive int argument. • putObjectAt(int x, int y, Object object) Puts the specified object at (x,y)

  13. Need another parameter, the amount of money (Step 8-3) • In CarryDropModel.java, add: private static final int TOTALMONEY = 1000; private int money = TOTALMONEY; String[ ] initParams = { "NumAgents" , "WorldXSize", "WorldYSize", "Money" }; public int getMoney() { return money; } public void setMoney(int i) { money = i; }

  14. Integrate the Space Object into the Model (Step 9-1) • Allocate a variable for the space object: private CarryDropSpace cdSpace; • Create the space object in buildModel(): cdSpace = new CarryDropSpace (worldXSize, worldYSize); • Destroy the space object in setup(): cdSpace = null;

  15. Some Clarifications (Step 9-2) • The space object is actually destroyed (set to null) in setup before it is created in the buildModel • Reason is that in each simulation run, the object needs to be reset to nothing before it gets ready to be built

  16. Overview : What’s been done in Step 1-9 • CarryDropModel Variables: schedule,cdSpace,numAgents, worldXSize, worldYSize, money Methods: setup(), begin(), buildModel(), buildSchedule(), buildDisplay(), getName(), getSchedule(), getInitParam(), getNumAgents(), setNumAgents(), getWorldXSize(), setWorldXSize(), getWorldYSize(), setWorldYSize(), getMoney(), setMoney(), main() • CarryDropAgent • CarryDropSpace Variables: moneySpace Constructors: CarryDropSpace()

More Related