Continuation of John Murphy - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Continuation of John Murphy

Description:

Continuation of John Murphy s RePast Tutorial Steps 10-18 Charlie Gieseler 8-9-04 Review from last time Start to fill out the CarryDropSpace class Constructor to ... – PowerPoint PPT presentation

Number of Views:98
Avg rating:3.0/5.0
Slides: 17
Provided by: na106
Category:

less

Transcript and Presenter's Notes

Title: Continuation of John Murphy


1
Continuation of John Murphys RePast Tutorial
  • Steps 10-18
  • Charlie Gieseler
  • 8-9-04

2
Review from last time
  • Start to fill out the CarryDropSpace class
  • Constructor to build a space of a given size
  • Added CarryDropSpace variable to the model
  • Added preparation line in Setup()
  • 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.
  • This could be useful outside of spreadMoney() or
    CarryDropSpace
  • Define a new method getMoney(int x, int y)

5
Tapping RePasts visualization resources
  • We are now at the point we can start to visualize
    our model
  • Initial visualization objectives
  • See our 2-D grid space
  • White background
  • Visible money, which squares have cash
  • Amount of cash indicated by color shade
  • 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
  • Create the variable
  • Tear down
  • Instantiate
  • Pass in the model
  • Give it a name
  • 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
  • Money
  • X position
  • Y position
  • 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
  • Initialize the agentList in setup()

13
Step 16 cont.
  • 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

14
Step 17 A Space for Agents
  • Want to add agents to CarryDropSpace.
  • Space containing agents will be an Object2DGrid
    like moneySpace.
  • We need
  • Agents to track their location
  • Some way to tell if a cell is occupied
  • Some 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.
  • 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.
  • Now whenever the model adds a new agent to the
    list, it will also attempt to add it to the
    simulation space.
Write a Comment
User Comments (0)
About PowerShow.com