Download presentation
Presentation is loading. Please wait.
Published byRonald Fletcher Modified over 9 years ago
1
Continuation of John Murphy’s RePast Tutorial Steps 10-18 Charlie Gieseler 8-9-04
2
Review from last time Start to fill out the CarryDropSpace class Start to fill out the CarryDropSpace class Constructor to build a space of a given size Constructor to build a space of a given size Added CarryDropSpace variable to the model Added CarryDropSpace variable to the model Added preparation line in Setup() Added preparation line in Setup() Added creation line in buildModel() Added creation line in buildModel()
3
Step 10 - Initializing the Space Object We need to disperse money in the space. Define spreadMoney() method in CarryDropSpace. Call spreadMoney() while building the model in CarryDropModel.
4
Step 11 - Extracting reusuable code We have now have code to check how much money is at a location. We have now have code to check how much money is at a location. This could be useful outside of spreadMoney() or CarryDropSpace This could be useful outside of spreadMoney() or CarryDropSpace Define a new method: getMoney(int x, int y) Define a new method: getMoney(int x, int y)
5
Tapping RePast’s visualization resources We are now at the point we can start to visualize our model We are now at the point we can start to visualize our model Initial visualization objectives Initial visualization objectives See our 2-D grid space See our 2-D grid space White background White background Visible money, which squares have cash Visible money, which squares have cash Amount of cash indicated by color shade Amount of cash indicated by color shade RePast provides classes to build displays RePast provides classes to build displays DisplaySurface – basically a window ColorMap – links numerical values to colors Value2DDisplay – links value sources from the model to colors according to the color map. Displays colors for each source in window when added to a DisplaySurface.
6
Step 12 – Using the DisplaySurface Import the class Import the class Create the variable Create the variable “Tear down” “Tear down” Instantiate Instantiate Pass in the model Pass in the model Give it a name Give it a name Register the object Register the object
7
Step 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
8
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.
9
Step 14 – Generating the Display Simply add this line to in the begin() method in CarryDropModel Now run compile everything and run CarryDropModel in your favorite IDE. When RePast starts, hit the “Initialize” button.
10
Step 15 – The Agents Start with 4 attributes Start with 4 attributes Money Money X position X position Y position Y position Lifespan (stepsToLive) Lifespan (stepsToLive)
11
Step 15 cont. – Modifying CarryDropModel 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
12
Step 16 – Adding Agents to the model Make a container to for all the Agents: ArrayList Make a container to for all the Agents: ArrayList Initialize the agentList in setup() Initialize the agentList in setup()
13
Step 16 cont. Define new method in CarryDropModel for adding Agents to the list Define new method in CarryDropModel for adding Agents to the list In buildModel(), make the desired number of calls to addNewAgent() to add Agents to the list In buildModel(), make the desired number of calls to addNewAgent() to add Agents to the list
14
Step 17 – A Space for Agents Want to add agents to CarryDropSpace. Want to add agents to CarryDropSpace. Space containing agents will be an Object2DGrid like moneySpace. Space containing agents will be an Object2DGrid like moneySpace. We need: We need: Agents to track their locationAgents to track their location Some way to tell if a cell is occupied Some 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
15
Step 17 cont. IsCellOccupied() checks if an Agent is already in a given cell in the agentSpace object. IsCellOccupied() checks if an Agent is already in a given 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.
16
Step 18 – Adding Agents to the space Add a line in addNewAgent() in the CarryDropModel to add a agent to the CarryDropSpace. Add a line in addNewAgent() in the CarryDropModel to add a agent to the CarryDropSpace. Now whenever the model adds a new agent to the list, it will also attempt to add it to the simulation space. Now whenever the model adds a new agent to the list, it will also attempt to add it to the simulation space.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.