Continuation of John Murphy’s RePast Tutorial Steps 10-18 Charlie Gieseler 8-9-04.
-
Upload
ronald-fletcher -
Category
Documents
-
view
220 -
download
0
description
Transcript of Continuation of John Murphy’s RePast Tutorial Steps 10-18 Charlie Gieseler 8-9-04.
Continuation of John Continuation of John Murphy’s RePast TutorialMurphy’s RePast Tutorial
Steps 10-18Steps 10-18Charlie GieselerCharlie Gieseler
8-9-048-9-04
Review from last timeReview from last timeStart to fill out the CarryDropSpace classStart to fill out the CarryDropSpace class
Constructor to build a space of a given sizeConstructor to build a space of a given sizeAdded CarryDropSpace variable to the Added CarryDropSpace variable to the
modelmodelAdded preparation line in Setup()Added preparation line in Setup()Added creation line in buildModel()Added creation line in buildModel()
Step 10 - Initializing the Space Step 10 - Initializing the Space ObjectObject
• We need to disperse money in the space.• Define spreadMoney() method in CarryDropSpace.
• Call spreadMoney() while building the model in CarryDropModel.
Step 11 - Extracting reusuable Step 11 - Extracting reusuable codecode
We have now have We have now have code to check how code to check how much money is at a much money is at a location.location.
This could be useful This could be useful outside of outside of spreadMoney() or spreadMoney() or CarryDropSpaceCarryDropSpace
Define a new method: Define a new method: getMoney(int x, int y)getMoney(int x, int y)
Tapping RePast’s visualization Tapping RePast’s visualization resourcesresources
We are now at the point We are now at the point we can start to visualize we can start to visualize our modelour model
Initial visualization Initial visualization objectivesobjectives See our 2-D grid spaceSee our 2-D grid space White backgroundWhite background Visible money, which Visible money, which
squares have cashsquares have cash Amount of cash indicated Amount of cash indicated
by color shadeby color shade
RePast provides classes RePast provides classes to build displaysto build displays DisplaySurfaceDisplaySurface – basically – basically
a windowa window ColorMapColorMap – links – links
numerical values to colorsnumerical values to colors Value2DDisplayValue2DDisplay – links – links
value sources from the value sources from the model to colors according model to colors according to the color map. Displays to the color map. Displays colors for each source in colors for each source in window when added to a window when added to a DisplaySurface.DisplaySurface.
Step 12 – Using the DisplaySurfaceStep 12 – Using the DisplaySurface
Import the classImport the class Create the variableCreate the variable ““Tear down” Tear down” InstantiateInstantiate
Pass in the modelPass in the model Give it a nameGive it a name
Register the objectRegister the object
Step 13 – A splash of colorStep 13 – A splash of color
• Import the needed classes• Color is a standard Java class to represent color values
• Will need access to the 2D grid of values • Add access method to CarryDropSpace
Step 13 cont. Step 13 cont. Create and initialize
ColorMap in CarryDropModel
- Use loop to map values to shades of red
- Value of 0 (default) maps to white
• Create Value2DDisplay object, displayMoney, using in 2D grid of values and our ColorMap• Add displayMoney to the window, displaySurf. • displayMoney will tell the display window what color (white or a shade of red) to put at each location in a 2D grid. It does this according to what value cdSpace currently has for each location in its grid.
Step 14 – Generating the DisplayStep 14 – Generating the Display
• Simply add this line to in the begin() method in CarryDropModel
• Now run compile everything andrun CarryDropModel in your favorite IDE.
• When RePast starts, hit the “Initialize” button.
Step 15 – The AgentsStep 15 – The Agents Start with 4 attributesStart with 4 attributes
MoneyMoney X positionX position Y positionY position Lifespan (stepsToLive)Lifespan (stepsToLive)
Step 15 cont. – Modifying Step 15 cont. – Modifying CarryDropModel for AgentsCarryDropModel for Agents
• Bounding Agent lifespans• Define default values• Define parameter variables
• Add parameter names to allow users to edit values through RePast• Add access methods for parameter vriables
Step 16 – Adding Agents to the Step 16 – Adding Agents to the modelmodel
Make a container to Make a container to for all the Agents: for all the Agents: ArrayListArrayList
Initialize the agentList Initialize the agentList in setup()in setup()
Step 16 cont.Step 16 cont. Define new method in Define new method in
CarryDropModel for CarryDropModel for adding Agents to the listadding Agents to the list
In buildModel(), In buildModel(), make the desired make the desired number of calls to number of calls to addNewAgent() to add addNewAgent() to add Agents to the listAgents to the list
Step 17 – A Space for AgentsStep 17 – A Space for Agents Want to add agents to Want to add agents to
CarryDropSpace.CarryDropSpace. Space containing agents Space containing agents
will be an Object2DGrid like will be an Object2DGrid like moneySpace.moneySpace.
• We need:We need:•Agents to track their locationAgents to track their location• Some way to tell if a cell is occupiedSome way to tell if a cell is occupied•Some way to add an Agent to the spaceSome way to add an Agent to the space
Step 17 cont.Step 17 cont. IsCellOccupied() checks if an Agent is already in a given IsCellOccupied() checks if an Agent is already in a given
cell in the agentSpace object.cell in the agentSpace object. addAgent() attempts to add an Agent in a random cell.addAgent() attempts to add an Agent in a random cell.
Step 18 – Adding Agents to the Step 18 – Adding Agents to the spacespace
Add a line in addNewAgent() in the Add a line in addNewAgent() in the CarryDropModel to add a agent to the CarryDropModel to add a agent to the CarryDropSpace.CarryDropSpace.
Now whenever the model adds a new agent to Now whenever the model adds a new agent to the list, it will also attempt to add it to the the list, it will also attempt to add it to the simulation space.simulation space.