Assignments

This page presents you with two kinds of assignments: submitted and unsubmitted. You are expected to prepare unsubmitted assignments for timely discussion. (Your active participation in our discussion list is part of your grade.) Submitted assignments are due at the end of the week for which they are assigned. Submitted assignments are graded; to receive credit must be submitted on time.

Week by Week

Week 1

Preliminaries
  • install NetLogo 5.0 on a computer you have easy access to, preferably a laptop that you carry with you.
Prepare for Discussion
Discussion Topics
  • NetLogo lanugage peculiarities
  • boolean variables; pseudo-random numbers
  • the nature of “emergence”
  • possible course projects
Submitted Assignment
  • None

Week 2

Prepare For Discussion
Discussion Topics
  • the nature of agents
  • Mushroom Hunt model: insights and reinterpretations
  • possible course projects
  • Gambler's Ruin Model: insights and limitations
Submitted Assignment
  • one paragraph proposal for course project (by 24 May 2013)
Optional
  • install Subversion and upload a file to your personal folder (if you want to do this, you will need to request a personal folder ahead of time)

Week 3

Prepare For Discussion
  • required reading
Discussion Topics
  • Gambler’s Ruin
  • Inheritance and Chance: insights and limitations
Submitted Assignment
  • two page outline of course project
  • begin: Gambler’s Ruin (due by 4 June 2013) (this assignment may take 20 hours, including preperatory readings and code experimentation)

Week 4

Prepare For Discussion
  • required reading
Submitted Assignment
  • submit: two-page summary of Course Project in ODD format (by 7 June 2013)
  • one paragraph proposal for course project
  • submit: Gambler’s Ruin (due by 4 June 2013)
  • begin: Segregation Exercise, (due by 14 June 2013)

Week 5

Prepare For Discussion
  • required reading
  • experiment with Schelling Segregation Model settings (in NetLogo’s Models Library)
Discussion Topics
  • Game of Life: reasons for interest
  • Schelling Segregation Model: insights and limitations
  • Schelling Model: possible extensions
  • experimental design: applications to ABS
Submitted Assignment

Week 6

Prepare For Discussion
  • required reading
Discussion Topics
  • Template Models: insights and limitations
  • More Template Models: insights and limitations
  • Sugarscape Models: insights and limitations
Submitted Assignment

Week 7

Prepare For Discussion
  • required reading
  • individual projects
Discussion Topics
  • More Sugarscape Models: insights and limitations
Submitted Assignment
  • Complete your term project. (Due by 27 June 2013.)

Assignment Details

Party Model

Related readings:

Party Model: Interface Tab

  • Click the Interface tab for the Party Model. Note three sliders for setting model parameters. The number slider sets the number of individuals, and the num-groups slider sets the number of groups. Set these sliders to match the setup description at http://ccl.northwestern.edu/netlogo/docs/sample.html (How many individuals? How many groups?)
  • Move the speed slider into the slower region, and set view updates chooser to continuous, so that you will be able to see what is going on.
  • After you set your model parameters with the sliders, press the setup button, and then click the go button.

Party Model: Basic Questions

  • What do you see happening as you run the Party Model? How do you explain it?
  • What does the tolerance slider do in the Party Model? What do you expect to happen if you set tolerance to a large value. Does it? What do you expect to happen if you set tolerance to a very small value. Does it?

Party Model: Questions for Discussion

  • In chapter 1, how do Railsback and Grimm define "emergence"? Based on this definition, to what extent would you characterize the model outcomes as emergent?
  • What do Railsback and Grimm say is a "common mistake of beginners"? Does the Party Model avoid that mistake? Is the resulting model useful? If so, how?
  • In chapter 1, how do Railsback and Grimm define a "full-fledged" ABM? Based on this definition, to what extent would you characterize the Party model as full-fledged? Would RG argue that this model should be full-fledged?
  • In the Party Model, party-goers attend only to the sex composition of their group. One interpretation is as follows: guys will leave if the discussion is too full of “girl talk”, and girls will leave if the discussion is too full of “guy talk”. But of course here we all are discussion agent-based simulation together, so clearly topic interest can cut across gender. How severe a limitation of the model is this, in terms of its goals? How might you address this limitation yet still pursue the goals of the model?
  • In the Party Model, party-goers join a fixed number of groups, rather like tables in a school cafeteria. How severe a limitation of the model is this, in terms of its goals? How might you address this limitation yet still pursue the goals of the model?

Party Model: Technical Questions

  • How many ways can we split 5 people into at most 2 groups? How would you determine how many ways can we split 150 people into at most 10 groups? Hint: http://en.wikipedia.org/wiki/Partition_(number_theory)
  • Use the default values of 70 individuals and 10 groups, but set the tolerance to say 12%. Now run the model a few times. (Once will probably be enough to see a very odd outcome.) Why does this happen?

Traffic Basic

Related readings:

Traffic Basic: Basic Questions

  • Recall what Railsback and Grimm say is a "common mistake of beginners". Does this model avoid that mistake? Is the resulting model useful? If so, how?
  • Note three sliders for setting model parameters. Explain the role of each of these.

Traffic Basic: Discussion Questions

  • In what sense is behavior "adaptive" in this model?
  • How sensitive are the outcomes to the acceleration settings? How sensitive are the outcomes to the deceleration settings?
  • To what extent would you characterize the model outcomes as emergent?
  • Based on the Railsback and Grimm definition of a "full-fledged" ABM, what would you like to add to make the Traffic Basic model more full-fledged?
  • What happens if you maximize acceleration and minimize deceleration. Is this a realistic outcome or a limitation of the model? Can you explain it?
  • Do you think this model has any “real-world” utility. If so, what?
  • Watch this short video: http://www.youtube.com/watch?feature=player_embedded&v=Suugn-p5C1M Does it affect your view of the usefulness of the model? Why or why not?
  • How might you link the cars to make a train? How would this affect your outcomes? Does autonomous goal seeking produce efficiency?

Traffic Basic: Technical Questions

  • Suppose you would like to characterize the response of model outcomes to the model settings. What outcome measure(s) would you use? How would you like to gather the data? What kind of chart would best display your data?

Wolf-Sheep Predation

Related readings:

Wolf-Sheep Predation: Basic Questions

  • What are the goals of this model?
  • Note seven sliders and two switches for setting model parameters. Explain the role of each of these.
  • Again, what do Railsback and Grimm say is a "common mistake of beginners"? Does this model avoid that mistake? Is the resulting model useful? If so, how?
  • In chapter 1, how do Railsback and Grimm define a "full-fledged" ABM? Based on this definition, to what extent would you characterize the model as full-fledged? Would RG argue that this model should be full-fledged?

Wolf-Sheep Predation: Discussion Questions

  • How does Wilensky define “stability” for this model? Why does adding "grass" to the model matter for the stability of outcomes?
  • How sensitive are the outcomes to the wolf-parameter settings? How sensitive are the outcomes to the sheep-parameter settings?
  • To what extent would you characterize the model outcomes as emergent?
  • Based on the Railsback and Grimm definition of a "full-fledged" ABM, what would you like to add to make the Wolf-Sheep Predation model more full-fledged?

Wolf-Sheep Predation: Technical Questions

  • Agents do not age in this model. In terms of the goals of this model, does that matter? Why or why not?

Simple Computations

  1. Go to the NetLogo dictionary. http://ccl.northwestern.edu/netlogo/docs/dictionary.html Look up let. Start NetLogo. Enter each of the following lines in the Command Center, in the order presented. (Some of these commands will not execute successfully.)

    print 2+2
    print 2 + 2
    let x -2
    show x
    let x -2 print x
    let x -2 print -x
    let x -2 print - x
    let x -2 print (- x)
    

    Summarize your “lessons learned”.

  2. Go to the NetLogo dictionary. http://ccl.northwestern.edu/netlogo/docs/dictionary.html Look up set. What is the difference between let and set?

  3. Go to the NetLogo dictionary. http://ccl.northwestern.edu/netlogo/docs/dictionary.html Look up repeat. Then enter the following in the Command Center:

    let x 0 repeat 50 [set x (x + 1)] show x
    

    What result do you expect to see? Why? (Be detailed.)

  4. Put the following in the Code tab:

    globals [ x ]
    

    Switch back to the Interface tab and enter the following (on three separate lines).

    print x
    repeat 50 [set x (x + 1)]
    show x
    

    Summarize what you have learned about global variables.

Answer Sketch

  1. Lessons learned:
    • Arithmetic operators must be surrounded by white space.
    • We introduce local variables with the let command. (We do not use the equals sign for assignment!)
    • The local variables we create with let are local to their code block. (Each line we enter in the command center executes as a separate code block.)
    • Although -2 is a literal number, we must use (- x) to produce the additive inverse of x.
  2. Use let to create a new local variable (and give it a value). Use set to change the value of a variable.
  3. Expected result: the observer will print 50. Reason: we initialized x to 0 and then added one to it 50 times.
  4. Lessons learned:
    • Global variables cannot be created in the Command Center but can be declared in the Code tab.
    • They are automatically initialized to 0.
    • We can change the value of a global variable with set, just like we can with a local variable.
    • The value of the global variable persists even when we are done using it.

Random Numbers

  1. At the Command Center, enter the following lines. In each case, if what you see differs from what you expected, explain why.

    show n-values 10 [random-float 1]
    show n-values 10 [random 1]
    show n-values 10 [random 2]
    random-seed 314
    show n-values 10 [one-of [0 1]]
    random-seed 314
    show n-values 10 [one-of [0 1]]
    

    What do you notice about the last two lists you produced. Can you explain it?

Talking to Patches

  1. Ask patch 0 0 to set its patch color to red. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ask http://ccl.northwestern.edu/netlogo/docs/dictionary.html#set http://ccl.northwestern.edu/netlogo/docs/dictionary.html#pcolor
  2. Ask all patches to turn white.
  3. Ask each patch to turn a random color, either red, white, or blue. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#one-of
  4. If you do the random color experiment a second time, will the outcome be identical? Why or why not? How could you use the random-seed command to ensure that you get the same outcome each time?
  5. Ask all patches to the left of the origin to turn red. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#with
  6. Give patches a new attribute, wealth. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches-own Set the wealth of each patch to a random integer between 0 and 100. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random
  7. Ask each patch to turn a shade of red that represents its wealth. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#scale-color
  8. How many patches are there? http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count What is their total wealth? http://ccl.northwestern.edu/netlogo/docs/dictionary.html#sum
  9. Make a list of all patches, in random order. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#self http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of
  10. Make a list of all patch wealths, in the same order as your list of patches. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#map

Talking to Turtles

  1. Give turtles a new attribute, wealth. (Note that your patches and turtles cannot have identically named attributes.) http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles-own
  2. Write an observer procedure named setup that does the following:
  3. Write an observer procedure named go that does the following:
  4. From the Command Center, call setup, and then call go 50 times. (Try this a few times.)

Answer Sketch

turtles-own [wealth]

to setup
  clear-all
  ask patches [sprout 1]
  ask turtles [set color one-of [red white blue]]
  ask turtles [set wealth random-float 100]
end

to go
  let %n (0.8 + random-float 0.4)
  ask turtles [set wealth %n * wealth]
  ask turtles [if wealth < 50 [die]]
end

NetLogo Puzzlers

  1. Produce a list of all patches in random order. Produce a list of all patches in a fixed order.

  2. Given: a list of 2-element lists (pairs), such as [[1 2] [3 4] [5 6]]. Produce a string consisting of the first element of each pair, separated by a comma. (E.g., "1,3,5".)

    Comment: such a string would be suitable for a CSV file.

    Hint: use reduce, word, map, and first.

  3. Suppose NetLogo did not have the one-of primitive. Devise a way to pick a random agent from an agentset.

    Hint: first produce a list of the agents in the agentset.

  4. Suppose you represent a bag of items by a list of objects (e.g., ["a" "b" "c"]) and a correspoding list of thei multiplicities (e.g., [ 1 2 3 ]). Show how to produce a list where each object occurs with its multiplicity (e.g., ["a" "b" "b" "c" "c" "c"]).

    Hint: you can use n-values inside foreach, but be aware that you cannot then refer back to the foreach arguments with the question-mark notation.

  5. Given an array a containing 5 zeros, what is the result of foreach n-values 5 [ ? ] [ array:set a ? ? * ? ]. Explain.

    Answer Sketch

    The result is { { array: 0 1 4 9 16 } }. We use n-values to create a list: http://ccl.northwestern.edu/netlogo/docs/dictionary.html#n-values In n-values 5 [ ? ] the ? stands for successive whole numbers, so the result is a list, [0 1 2 3 4]. So the code above turns into foreach [0 1 2 3 4] [ array:set a ? ? * ? ] (You can iterate over a list using foreach: http://ccl.northwestern.edu/netlogo/docs/dictionary.html#foreach) Now we ask anew what the ? stands for, and the answer is, that it successively stands for the elements of the list [0 1 2 3 4]. So NetLogo will first do array:set a 0 0 * 0, which sets the element at index 0` to the value ``0 * 0. And so forth.

Coin Flipping

Coin Flipping: Part I

  1. Create a new NetLogo file, named coinflip01.nlogo.

  2. In the Code window, use the globals primitive to introduce two new global variables: n-heads and n-tails. Then add a flip-coin procedure that uses ifelse and random-float to simulate the flip of a fair coin. Add one to n-heads if random-float 1 < 0.5 and otherwise add one to n-tails.

  3. Go to the Command Center and use repeat to run your flip-coin procedure one hundred times. View the result by entering show n-heads and show n-tails. Did you get 50 heads and 50 tails? Should you have?

  4. A typical NetLogo program will declare global variables, have a procedure named setup that does the preliminary model set up, and have a procedure named go that contains the schedule for one iteration of the model. Return to the Code window and add setup and go procedures to produce a complete a coin-flipping program. The setup procedure need only execute clear-all. Use the following go procedure:

    to go
      set n-heads 0
      set n-tails 0
      repeat 50 [ flip-coin ]
    end
    
  5. Return to the Command Center and run your setup procedure, then run your go procedure. Did you get the expected number of heads and tails? Run your go procedure again (without running setup). What is the outcome?

  6. To the Interface window, add a button named Setup that runs the command setup. (To add a button, you can right click on the Interface window, where you wish to place the button.) Next add a button named Go Once that runs the command go. Next add a button named Go 100 that runs the go command 100 times. Test your buttons.

  7. In the Code tab, append the update-plots command to your go procedure. To the Interface window, add a plot with the pen update command plot n-heads. Click your Setup and Go 100 buttons. Discuss the resulting plot.

  8. What happens if you click the Setup button once and then the Go 100 button two times in a row?

Answer Sketch

globals [ n-heads n-tails ]

to setup
  clear-all
end

to go
  set n-heads 0
  set n-tails 0
  repeat 50 [ flip-coin ]
  update-plots
end

to flip-coin
  ifelse (random-float 1 < 0.5)
    [ set n-heads (n-heads + 1) ]
    [ set n-tails (n-tails + 1) ]
end


Coin Flipping: Part II

  1. First, make sure you have saved your file coinflip01.nlogo from Part I. Next, copy this file to coinflip02.nlogo, a new NetLogo file. We are going to make some changes in this new file.
  2. Read about the patches-own keyword in the NetLogo Dictionary. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches-own In the Code window, change the globals keyword to patches-own. This change means that you are no longer defining any global variables, but each patch has a n-heads and n-tails attribute.
  3. For the moment, we will use these attributes only for one patch: we will let patch 0 0 keep track of the coin flips. So change your go procedure to ask patch 0 0 to do the coin flipping experiment.
  4. Test your changes in the Interface window. Run setup and then enter ask patch 0 0 [show n-heads] in the Command Center. (The result should be 0.) Run go and then enter ask patch 0 0 [show n-heads] in the Command Center. (The result is random but is probably near 25.)
  5. Add a slider taking values from 1 to 50 (with an increment of 1), with a default value of 50, for a new global variable named n-flips. Note that creation of the slider introduces and initializes this variable; you shold not declare it separately using the globals keyword. Change your go procedure to use the new n-flips global variable. Test your model by clicking the Setup and Go 100 buttons.
  6. In the Interface window, right click on the Go 100 button to edit it. Change the display name to Go N, and redefine it to run the go command n-trials times. (Note how the button text is red after creation, indicating that n-trials is not yet defined.)
  7. Add a slider taking values from 1 to 200 (with an increment of 1), with a default value of 100, for a new global variable named n-trials. Note that creation of the slider introduces and initializes this variable; you should not declare it separately using the globals keyword. Test your model by clicking the Setup and Go N buttons.
  8. In the Interface window, edit your plot so that the pen update command is now plot [n-heads] of patch 0 0.

Answer Sketch

patches-own [ n-heads n-tails ]

to setup
  clear-all
end

to go
  ask patch 0 0 [
    set n-heads 0
    set n-tails 0
    repeat n-flips [ flip-coin ]
    set plabel n-heads
  ]
  update-plots
end

to flip-coin
  ifelse (random-float 1 < 0.5)
    [set n-heads (n-heads + 1)]
    [set n-tails (n-tails + 1)]
end

Coin Flipping: Part III

  1. First, make sure you have saved your file coinflip02.nlogo from Part II. Next, copy this to coinflip03.nlogo, a new NetLogo file. We are going to make some changes in this new file.

  2. For the previous program, we only made use of one patch. This time, we will use one patch for each coin flip. So add the following to your setup procedure:

    resize-world 0 0 0 (n-flips - 1)
    set-patch-size (400 / n-flips)
    

    Read about resize-world and set-patch-size in the NetLogo Dictionary, and then explain in detail what this code does. Test this code by running your setup procedure.

  3. Delete the patches-own statement from your Code window. Introduce a global variable named n-heads.

  4. Next we introduce a little memory. In your setup procedure, intialize the global variable n-heads to an empty list.

  5. Each patch will flip a coin and change its color to green for a head and to red for a tail. So replace the body of your flip-coin procedure with

    ifelse (random-float 1 < 0.5)
      [set pcolor green]
      [set pcolor red]
    
  6. Replace the body of your go procedure. It should now

    • ask each patch to flip-coin
    • count the number of heads (i.e., green patches)
    • append that number to the n-heads list
  7. Change your plot so that it plots the last number appended to n-heads. To the same chart, add a plot pen that plots the mean of n-heads.

  8. Add a slider taking values from 0 to 1 (with an increment of 0.01), with a default value of 0.5, for a new global variable named p-head. This will be the probability of getting a head from a single coin flip. Change your flip-coin procedure to use p-head.

  9. Experiment with your NetLogo program. Explain what your plot illustrates.

Mushroom Hunt

  1. Implement the Mushroom Hunt, following the details provided in Chapter 2 of Railsback and Grimm (2011). (Be sure to fully comment your program.)

  2. Change the body of your setup procedure to:

    ca
    setup-globals
    setup-patches
    setup-turtles
    reset-ticks
    

    (Comment: this is a rather typical setup procedure. Comment: order matters; set up in this order.) Create appropriate setup-globals, setup-patches, and setup-turtles procedures. We will add to these.

  3. Introduce new globals, growback-time, max-energy, min-energy, and max-speed. Your setup-globals procedure should initialize these to 100, 10, 0.4, and 1.

  4. Add a harvest-time attribute to patches. (This is automatically initialized to 0.) Give turtles an energy and metabolism attributes, initialized (in setup-turtles) to 1 and 0.001.

  5. Introduce a new global variable n-hunters in a slider. Let the number vary from 1 to 10 but have a default of 2, and use this variable to determine how many hunters you create in your setup-turtles procedure. (Comment: when you create a global variable with a slider, you do not also declare it in your declarations section.)

  6. Each tick, check the yellow patches to see if growback-time has passed since their harvest-time. If it has, turn the patch red again.

  7. Constrain hunters' search speed to max-speed.

  8. Each tick, after hunters search, deduct metabolism from each hunters energy, but constrain the minimum energy to be min-energy. Scale the turtle’s color to its energy. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#scale-color

  9. Each time a mushroom is harvested, set the patch’s harvest-time to the ticks value. Also, add 1 to the hunter’s energy, but then constrain energy not to exceed max-energy.

  10. Every 100 ticks, clear the traces made by your hunters http://ccl.northwestern.edu/netlogo/docs/dictionary.html#mod http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-drawing

  11. Add a plot of the average energy of your hunters. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#mean http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of

  12. When you run the simulation, if you want to be able to see the hunter behavior, you will probably need force it to go slower. Use the slider provided for this in the Interface tab.

  13. It would be nice to ensure that when a user starts up your model, that the use is presented with your chosen default values for slider variables. However, the user will proceed as follows. 1. pick n-hunters using a slider, then 2. click the "SetUp" button to set up the model. If you set n-hunters in setup, you will override the user's choice.

    However, NetLogo does provide a workaround for this: a special procedure named startup. Use this to initialize your user interface. http://ccl.northwestern.edu/netlogo/docs/dictionary.html#startup

Assignment Goals

  • foster attention to detail; model building is a detail-oriented exercise.
  • introduce you to the standard structure of the setup procedure.
  • gain familiarity with core NetLogo primitives, including if, ifelse, of, mean, clear-drawing, mod, scale-color
  • require you to pay careful attention to the context in which commands are given.
  • practice adding a time-series plot
  • learn how to slow the progression of the simulation
  • learn how to use startup to initialize your user interface.

The Process of Programming

Do things a little bit at a time. Do not try to do too much at once. Use the number one debugging suggestion: use lots of extra print statements so that you can see what is going on in your program. (In NetLogo programs you may use show instead of print, as it provides a bit more information.)

Answer Sketch


globals [
  num-clusters
  growback-time
  max-speed
  max-energy
  min-energy
]

patches-own [
  harvest-time
]

turtles-own [
  time-since-last-found
  energy
  metabolism
]

to startup ;; initialize slider
  set n-hunters 2
end

to setup  ;; typical setup proc
  ca
  setup-globals
  setup-patches
  setup-turtles
  reset-ticks
end

to setup-globals
  set num-clusters 4
  set growback-time 100
  set max-energy 10
  set min-energy 0.4
  set max-speed 1
end

to setup-patches
  ;; ask patches [set harvest-time 0] ;; unneeded
  ask n-of num-clusters patches [
    ask n-of 20 patches in-radius 5 [
      set pcolor red
    ]
  ]
end

to setup-turtles
  crt n-hunters [
    set energy 1
    set metabolism 0.1
    set size 2
    set time-since-last-found 999
    set color yellow
    pen-down
  ]
end

to go
  tick
  if (ticks mod 100 = 0) [
    clear-drawing
    clear-plot
  ]
  
  ask patches with [pcolor = yellow] [
    growback
  ]
  ask turtles [search]
end


to search
  ifelse time-since-last-found <= 20 [
    right (random 181) - 90
  ] [
    right (random 21) - 10
  ]
  
  fd min (list energy max-speed)
  set energy max (list min-energy (energy - metabolism))
  
  ifelse (pcolor = red)   [
    set energy min (list max-energy (energy + 1))
    set time-since-last-found 0
    set harvest-time ticks
    set pcolor yellow
  ] [
    set time-since-last-found (time-since-last-found + 1)
  ]
  set color scale-color yellow energy 0 max-energy 
end

to growback
  if (ticks >= harvest-time + growback-time) [
    set pcolor red
  ]
end

Gambler’s Ruin

Two-Person Gambler’s Ruin

Name the file for this part of the exercise ruin01.nlogo.

  • Implement the 2-Person Gambler’s Ruin, as described in the exercise in the lecture notes. (Note that NetLogo automatically provides the ticks global, but you need to update it each iteration with the tick command.)
  • Make a line plot of the evolution of one player’s wealth over time. This is a time-series plot of the wealth of one player. Give it the name "Player 1 Wealth". Run your simulation to produce this plot.
  • From NetLogo’s Command Center, use the export-plot command to export your plot as temp.csv to whatever you use as a temporary directory (e.g., "c:/temp/temp.csv"). Open this CSV file in your favorite spreadsheet (e.g., Calc or Excel). Reproduce your NetLogo plot from this data. Save your spreadsheet graph as a PNG file, and submit it with this assignment.

Make sure you code is fully commented. See the NetLogo Dictionary for help with the following: ticks, tick, plot, export-plot.

N-Person Gambler’s Ruin: Static Pairs

Name the file for this part of the exercise ruin02.nlogo. (This is a separate file from the 2-person model.)

  • Implement the N-Person Gambler’s Ruin, with static pairs, as described in the lecture notes.
  • Add a dynamic histogram of the evolution of the wealth distribution over time.
  • Add buttons named setup and static-pairs to setup and run this simulation.

Questions to consider:

  • How many times should the literal number 1000 appear in your code? Why? Why might we introduce a slider (say, n-agents)?
  • What happens if you never run setup but try to run static-pairs? Why?

N-Person Gambler’s Ruin: Random Pairs

This work goes in the same file as your previous work on the N-person model. (That is, just modify ruin02.nlogo.)

  • Write a reporter that takes a list as its input argument and returns randomly paired elements from the list, using each element once. (If there is an odd number of elements, one random element will not be used.) (Comment: I've posted a solution already in the Gambler’s Ruin notes, but try to do this on your own first.)
  • Implement two versions the N-Person Gambler’s Ruin, with random re-pairing, as described in the lecture notes. The first version (random-pairs01) stops when any player’s wealth goes to zero. The second version (random-pairs02) stops after a fixed number of iterations.
  • What does the histogram look like when you stop when the first wealth goes to zero? What does the histogram look like when you stop after maxitr rounds?
  • add two buttons random-pairs01 and random-pairs02, which run these two simulations (after setup, of course)

N-Person Gambler’s Ruin: Using Patches

This goes in a separate file from the previous exercises. Name the file for this part of the exercise ruin03.nlogo.

  • Implement the N-Person Gambler’s Ruin with random re-pairing, using patches with a wealth attribute (instead of using a wealths array. (Use resize-world to make 1000 patches as a 40 x 25 grid.)
  • Make a line plot of the evolution of one player’s (i.e., patch’s) wealth over time.
  • Make a dynamic histogram of the evolution of the entire wealth distribution over time
  • Fill in the Info tab. (You can delete the NetLogo Features and the Related Models sections.) Include some discussion. For example ... What does the histogram look like when you stop after maxitr rounds? What does the histogram look like when you stop as soon as any one player’s wealth goes to zero? It is reasonable to interpret these as “institutional” considerations?

Questions to consider:

  • Why bother with the patch version? (After all, it should give the same results.)

Assignment Goals

  • better familiarize you with NetLogo programming
  • learn how to export data from a plot
  • learn how to use NetLogo’s array data type
  • learn how to represent an agent as simply a location in an array
  • reflect on the questions: what is an agent?
  • see that there can be very different implementations of the same concept (i.e., of players with a wealth attribute who play a betting game).
  • learn how to produce pairings and random pairings of any sequence
  • think about the importance of developing reusable code

Comment: an array location seems like a pretty shallow concept of an agent. It is actually a very common one in the literature. This assignment shows you how it can be simple and useful.

The Process of Programming

Do things a little bit at a time. Do not try to do too much at once. Use the number one debugging suggestion: use lots of extra print statements so that you can see what is going on in your program.

Let us see how you might approach the problem of writing a static-pairs-ruin procedure, step by step.

First, start with an empty procedure. This is sure to execute without a problem.

to static-pairs-ruin
end

Next, make a list of the things you want to do, and take them up one at a time. Here they are:

  • let %n be the length of the wealths array
  • let %pairs be the %n/2 static pairs returned by idxpairs01
  • for each pair, call ruin01

Ok, let us take up the first one:

to static-pairs-ruin
  let %n 10  ; pretend we just have 10 wealths for testing
  show %n
end

Check the syntax of your code. (In NetLogo, press the "Check" button in the Code tab.) It seems to be OK, so switch to the Interface tab and "run" your procedure. I.e., just entering its name into the command center.

Voila, it works! Of course we have a residual concern: you set %n to 10, regardless of the length of wealths. So make a note to yourself to figure out how to get the length of the wealths array. You can do this later.

to static-pairs-ruin
  ; let %n be the length of the `wealths` array
  let %n 10  ;; todo: get length of `wealths`
  show %n
end

After (seriously, after) you have that working ok, then you add the next line.

to static-pairs-ruin
  ; let %n be the length of the `wealths` array
  let %n 10  ;; todo: need to get length of `wealths`
  ; let %pairs be the %n/2 static pairs returned by idxpairs01
  let %pairs idxpairs01 %n
  show %pairs
end

You have added a line, so press the "Check" button to check your code again. (Do this every time you add a line.) Ooops! It fails unless you copied my idxpairs01 proc into your Code tab. So copy it over, attribute it (right away!), and try again. That checks, so run it from the command center. Note that we again included a show command, so that you can examine the result. Does the result look like you expected? Make sure it does!! If it does, then you are ready to try to add another line to your proc.

But now we hit a barrier.

to static-pairs-ruin
  ; let %n be the length of the `wealths` array
  let %n 10  ;; todo: need to get length of `wealths`
  ; let %pairs be the %n/2 static pairs returned by idxpairs01
  let %pairs idxpairs01 %n
  show %pairs
  ; for each pair, call ruin01
  ; how to do this???
end

The problem is, although you suspect you should use the foreach command, you do not yet understand this command. So first you need to make sure you understand this command. So you go to http://ccl.northwestern.edu/netlogo/docs/dictionary.html#foreach and to https://subversion.american.edu/aisaac/notes/netlogo-intro.xhtml#agentsets-vs-lists and read about how to use foreach. You learn that ? is a special name that is sequentially assigned to each item in the foreach sequence. So you test that out:

to static-pairs-ruin
  ; let %n be the length of the `wealths` array
  let %n 10  ;; todo: need to get length of `wealths`
  ; let %pairs be the %n/2 static pairs returned by idxpairs01
  let %pairs idxpairs01 %n
  ; for each pair, call ruin01
  ; how to do this???
  ; first, test use of ``foreach``
  foreach %pairs [print ?]
end

You use the Check button and find this is OK, so you again run your procedure from the command center and look at the output. Does it look like you expect? Make sure you can explain why you are seeing this output!

Now for your last step, you want to replace [print ?] with the code block that can take a pair, which is a list like [4 9], and execute [ruin01 4 9]. To do that, you should move to the command center and try a few things.

For example, at the Command Center you try

let test [4 9] ruin01 test

and you get

ERROR: RUIN01 expected 2 inputs.

Oh, of course: ruin01 needs two numbers. So you try

let test [4 9] ruin01 4 9

and that works, but ... how to get the list items from the list? Well, how about item!

let test [4 9] ruin01 item 0 test item 1 test

Hey, that works! Now you are ready to go back and used what you have learned to complete your procedure.

First Approach to the Template Models

All four parts of this exercise are due as one NetLogo file. It is broken into parts for your convenience in implementing a model of increasing complexity.

Submit to me your fully commented code implementing all parts of the exercise as a single NetLogo file: template01.nlogo. (If anyone prefers to use Python or some other language, let me know.)

Plan! Use explicit comments to layout your program structure!

You will be graded on completeness of the assignment, correctness of the implementation, and adequacy (!!) of your comments.

Remember, you will not changing the display size of your agents. So, you cannot use "size" for the agents' size attribute, because that already has separate meaning in NetLogo. Use the name mysize instead.

Part I

Parameters (e.g., global variables)
  • world_shape: the grid dimensions (100 × 100)
  • n_agents: the number of agents (100)
Setup
  • create an iterable collection of agents
  • give each agent a unique, random position on the grid
Iteration
  • each time step, each agent moves once, to a random unoccupied neighboring location
Supplementary Detail
  • unique-location constraint: no two agents share a position, not even initially
  • movement is random in a specified neighborhood
    • neighborhood: a Moore neighborhood of radius 4
    • an agent must change position unless all neighboring locations are occupied
    • the move action must terminate, even if all neighboring locations are occupied (This is a requirement imposed on your move algorithm.)
GUI and display suggestions
  • shape: display agents as circles
  • color: use a red fill color for agents
  • background color: display agents against a white or a black background
Comment:

Remember, there are four (4) parts to this assignment. Part I of the assignment is intended to have two challenging components.

  1. Produce a Moore neighborhood that is not just radius 1.
  2. Move as specified in the neighborhood, being careful to attend to the possibility that the entire neighborhood may be occupied.

There are many different ways to accomplish both parts.

NetLogo Hints for Part I:
Common NetLogo Mistakes:
  • using the Moore code from the models library but having a model with the origin in a corner
  • setting the grid dimensions as resize-world -50 50 -50 50 or resize-world 0 100 0 100

Part II

New Global Variables
  • as in model 1, plus
  • agent_initial_size: the initial size of an agent (0.0)
  • extraction_rate: determines the change in agent size (0.1) (but we will change this soon)
Iteration (sequential)
  • each agent moves, and after all have moved,
  • each agent changes size
Supplementary Detail
  • movement: agents move as in model 1
  • size change: the agent’s mysize attribute is augmented by the extraction_rate
GUI and display suggestions
  • color: each agent’s fill color should represent its "size". (Specifically, use white if mysize=0.0, red if mysize>=10.0, and increasingly chromatic tints of red as mysize increases from 0 to 10.)
Comment:
Depending on the language, appropriately scaling the color of the agent can take a little thinking. Note that when the agent has a size of zero, we want its color to be white. When it reaches a size of 10, we want its color to be red. For sizes greater than 10, the color is still red.
NetLogo Hints for Part II

Part III

New Global Variables
  • agent_max_extract: the maximum extraction rate of an agent (1.0)
  • cell_initial_supply: initial resource availability in a cell (0.0)
  • cell_max_produce: maximum production rate of a cell (0.01)
Iteration (sequential)
  • each cell produces
  • each agent moves
  • each agent grows
Supplementary Detail
  • production: random, uniform between 0 and cell_max_produce
    • a cell’s attributes include its current supply and its maximum production rate
    • a cell’s production is added to its supply
  • movement: agents move as in model 1
  • growth: an agent “grows” by “extracting” from its cell
    • an agent can interact with the cell at its position (specifically, it can extract the cell’s supply)
    • an agent has a maximum extraction rate attribute (set equal to the global variable agent_max_extract)
    • an agent extracts whichever is smaller: its maximum extraction rate, or its cell’s supply
    • an agent’s mysize changes by the quantity it extracts
    • a cell’s supply is reduced by the amount extracted
GUI and display suggestions
  • unchanged from model 2
Comment:
Part III is intended to give you experience implementing interaction between turtles and patchs (through the extraction process).
NetLogo Hints for Part III

Part IV

We begin with a brief exercise (with no corresponding code).

Set up your simulation from part III.

Right click an patch 0 0. Note that the resulting GUI monitor reports your new patch attribute (supply). Note the patch coordinates, and close the monitor. Now enter (in the command center in observer context): inspect patch 0 0.

Right click on a turtle and inspect it. Note that the resulting GUI monitor reports your new turtle attribute (max-extract). Note the turtle's who number, and close the monitor. Now enter (in the command center in observer context): inspect turtle num where num is your turtle's who number.

Right click on a patch and inspect it. Note that the resulting GUI monitor reports your new patch attribute (supply). Note the patch's pxcor and pycor, and close the monitor. Now enter (in the command center in observer context): inspect patch px py where px py is your patch's pxcor and pycor.

Next we will make a permanent change in the GUI interface for your model. Facilitate user setting of two model parameters by adding a slider for each of

  • the initial number of agents, and
  • the maximum extraction rate of agents

Next, add buttons in the GUI to set up and run the simulation, where set up includes the creation of agents.

Finally, add a stopping condition. You want to terminate iterations based on model state. Stop when any agent reaches mysize >= 100. (See the NetLogo stop command.)

NetLogo Hints for Part IV
  • You have a global variable, agent_max_extract. The instructions say:

    an agent has a maximum extraction rate (equal to agent_max_extract)

    So you also need to an a turtle attribute, max-extract, that you set equal to the global agent_max_extract during setup-turtles.

    During Part III, you declare agent_max_extract in globals. In Part IV you move it to a slider, so you need to comment it out in your globals declaration (as we've discussed in past classes). A slider also declares a global variable, and you can only declare the variable once.

Second Approach to the Template Models

Part 1

Before you begin, copy your “first approach” to a new file. (E.g., tm2.nlogo.) Don't change your first file any more.

In your tm2.nlogo file, change the model slightly: each iteration, sort agents by their “size” (i.e., their mysize attribute) to determine the move order: a larger “size” implies an earlier move.

Part 2: Optimization

Optimization: each agent moves to a best available neighboring cell.

  • an agent’s neighborhood remains a Moore neighborhood of radius 4, but now the agent’s current cell is included
  • a cell is “available” if it is unoccupied
  • a cell is “best” if it has greatest supply
  • if the agent’s current cell is not a best cell, the agent changes location to a best available cell, resolving any ties with a random choice from the best cells

This is probably the hardest thing you have done yet.

Part 3: Entry & Exit

We now add entry and exit of agents.

Model Iteration (sequential)
  • as before, then
  • each agent with mysize > 10 attempts to propagate and then exits, then
  • each remaining agent (including new entrants) exits with a fixed probability
Propagation:
  • agents attempt propagation in random order
    • a propagating agent (“parent”) makes five sequential propagation attempts
    • a propagation attempt succeeds by finding an unoccupied location, which becomes the position of a new agent, where for each attempt
      • search is restricted to a Moore neighborhood of radius 3
      • for each propagation attempt, cells to search are selected by random sampling without replacement of the neighborhood
      • search is sequential and terminates if an unoccupied cell is found
      • no more than 5 cells are searched (if all five are occupied, search terminates, and the propagation attempt fails)
    • a new agent should begin "life" with a size of 0
Exit
  • each remaining agent (including the new entrants) exits the simulation with fixed probability (agent_exit_probability)
New Stopping Condition:
  • the number of agents reaches 0, or the number of iterations exceeds 1000
Hint:
NetLogo users should look at hatch and die

Part 4: Useful Plots

Let's add to your model two graphs: a time-series plot of the Gini, and a dynamic Lorenz curve (of mysize).

Your code should be heavily commented.

Additionally, you should also add a time-series plot that displays the evolution of a new model statistic over time: the number of agents alive at each iteration.

Additionally, I would like you to do a simple randomization of the initial model state, as follows.

Introduce two model parameters (with sliders):
  • mean of the size distribution of initial agents (default: 0.1)
  • standard deviation of the size distribution of initial agents (default: 0.03)

Assign each initial agent a random size during the model set up. (Do not apply this to any offspring.)

  • each initial size is drawn independently from a normal distribution
  • mean and standard deviation of the size distribution are model parameters
  • if the size draw is less than 0.0, it is set to 0.0

Third Approach to the Template Models

Copy tm2.nlogo to tm3.nlogo. Do not change tm2.nlogo any more.

Part 1: File Input

Change the topology so that it no longer wraps. And change the grid size to 251 (x values of 0 to 250) by 113 (y values from 0 to 112). As usual, svn add this file in your personal folder.

Next, find the celldata.txt file in the folder that holds your personal folder. You do not need to add it to the repository; it is already in the repository. The file format is plain text: look at it (!!) with a text editor. You will read in the given file of cell data to initialize your model.

Here is how change your model code.

Setup

  • the first three lines are header information (to be discarded)
  • each additional line provides three space-delimited numbers:
    • an integer x coordinate,
    • an integer y coordinate,
    • and a floating point production rate.
  • set a production rate for each cell based on the cell data (comment: use file-read-line and file-read, which we will discuss Thursday)
  • production: each iteration a cell produces the amount specified by the file of cell data (i.e., production is no longer random)

Change in display:

  • display cells in the GUI and color-code the cell state as follows:
    • base a cell’s color on the value of its supply attribute: a cell is green when supply is 0.5 or higher and shades to black as supply goes to 0
Comments:
  • a Moore neighborhood on a rectangular grid (instead of a torus means that coordinates off the grid are now unavailable (instead of wrapping)

Part 2: File Output

Create a folder below your homework folder called output.

Each iteration, compute some summary statistics for the model and write model summary to the file "output/myoutput.csv".

  • as part of your setup, write a header as the first line in the log file
  • use CSV format for the output file
  • output from a single iteration is a single line in the text file
  • write summary statistics for the size of agents: the minimum, mean, and maximum size.

Be sure to open, append to, and close the output file each iteration.

After you are done, open the file in a text editor to view its contents. Then, open the file in a spreadsheet and graph your three series. (If you are not familiar with any spreadsheets, the SSRL can help you with Excel.)

Part 3: Hunters

Parameters, World, and Setup
  • as before, plus: create 200 randomly distributed “hunters” (no two on the same patch)
Iteration (sequential)
  • as before, then each hunter hunts
Stopping Condition
  • unchanged
Supplementary Detail
  • hunters do not grow, reproduce, or die during your simulation
  • a cell may contain a hunter (new type of turtle) and a gatherer (your old type of turtle)
  • hunting: hunters randomly search for gatherers and “kill” the first found
    • search: randomly sample (without replacement) a Moore neighborhood of radius 1, center included
    • if another hunter is found on a patch, search terminates, and the hunter remains at its current location.
    • if another hunter is not found on a patch, but a gatherer is found, search terminates, and the hunter moves to the patch and “kills” the gatherer
    • if no neighboring cell contains another hunter or a gatherer, the hunter moves randomly to an unoccupied patch
    • gatherers are removed from the simulation as soon as they are “killed”

Color your hunters yellow and give them a classic arrowhead shape.

Simple Network Model

setup procedure
  • Create a set of turtles with random positions
  • Create a random set of links between the turtles
    • Each turtle has same chance of having links
go procedure
  • Pick a random turtle and a random one of its links, and replace it within one attached preferentially

    • Higher chance of linking to a turtle with the most links
  • Go to Model Library, open Network > Preferential Attachment, and save under a new name

    • Agentset – a list set of agents
      • Defaults to a random order but can be sorted
      • Can also pick a random agent from the list
      • If we want angentset to persist, must set it to a name we have previously declared in globals or locally
    • If we have picked a turtle, other turtles is an agentset of all of the other turtles

Modify Life

  • File > Model Library > Computer Science > Cellular Automata > Life
  • Save on desktop under a new name

Bowen’s suggested modifications of Life * add a slider for global variable init-number

  • default = 2
  • possible values from 1 to 5
  • find the go procedure
    • change 2 to init-number
    • change 3 to init-number + 1

Modify Small Worlds

  • File > Models Library > Networks > Small Worlds
  • Save on desktop under a new name
  • On interface, put in a slider:
    • Global variable init-links
    • Minimum 1
    • Increment 1
    • Maximum 3
    • Value 2
  • Procedures
    • scroll through to find setup, make-turtles, and wire-them
    • determine: what does wire-them do?
  • modifications (suggested by Bowen):
    • Always link to n+1
    • If init-links = 2 or 3 then also link to n + 2
    • If init-links = 3 then also link to n + 3
  • handle divide-by-zero error when running with init-links = 1
    • Divide by clustering-coefficient-of-lattice . divide by dum, protect dum from being zero
      • We might eventually want a better fix

Prisoner’s Dilemma Exercise

We will have the agents interact by playing a simple two-player game. We will combine this two-player game with of learning. Here agents will learn what strategy to use when playing the game.

Implement this game

Write a Netlogo simulation in which agents play a simple two-player game like the Prisoner’s Dilemma. Each agent plays the game using some strategy (by “strategy” I mean something like Tit-for-tat) and initially each agent randomly selects which strategy to use. After that, the game proceeds in rounds. On each round every agent is paired up with exactly one other agent, and the agents play the game. Depending on how both agents play — and on the game that they play — each agent gets a score. Agents total up their scores over time.

After some number of rounds, agents make a decision about whether to change strategy.

Things your simulation must do:

1. The simulation must include at least two games, one of which is the Prisoner’s Dilemma (for the other, you can use any of the games that we talked about in class, or any two-player game that you care to invent).

  1. The simulation must include at least three strategies, and one of these must be Tit-fot-tat.

3. The simulation must include some decision making about which strategy to use and this should be based on the scores that different agents obtain through playing their strategy.

4. The simulation must update on ticks (see the Netlogo manual to get a full explanation of this), and it must display a count of the total number of ticks that have elapsed in a simulation.

  1. The simulation has to show the number of agents with each strategy at each tick in the simulation window.
  2. The simulation must display the number of agents playing each strategy
  3. The simulation must stop if all the agents end up playing the same strategy.
  4. The simulation must allow the user to pick the proportion of agents that start playing each strategy.

You can do everything with patches, but it is also fine to use turtles.

Document

All you are going to hand in is the Netlogo program so make sure you:

  1. Write lots of comments in your code. If I don’t understand what your code does, you won’t get full credit.

2. Write a description of your program in the Information tab. Here you should write an overview of the problem, the strategies for playing the game, and the ways in which agents make their decision about which strategy to use.

Experiment

Once your simulation is complete, experiment with different initial proportions of strategies, and different games, seeing whether the agents all converge on the same strategy and if they do how many ticks it takes. Since there is randomness in the simulation, you’ll need to do several runs (say 10) of each combination in order to get a reliable idea of how they perform.

Describe the results of your experiments, including the statistics you collect, in the Information pages of your project.

Hand it in

Save your model as <my-name>-pd.nlogo, where you replace <my-name> with your own name (so my program would be called parsons-pd.nlogo) and email it to the TA.

The subject line of your email should say: LastName Econ 396/696: PD Project

If you don’t get an acknowledgement within 24 hours, send me a follow-up email.

Segregation Exercise

  1. Carefully describe (in words) the essential structural features of the Schelling (1978) segregation model (hereafter referred to as the Schelling Model), as set out by [schelling-1978ch4-mm] on pages 147-155. (You may rely on my notes or read that chapter.)

    • Does the Schelling Model satisfy the standard definition of a 2D cellular automaton? (Be very specific and detailed.)
    • What social issues did Schelling think his model addressed? (This is not a question about the simulation outcomes but rather of the model structure: in what ways can you map the model to the real world?)
  2. Does the Schelling Model in the NetLogo Models Library capture the general structural features of the Schelling Model? (What is included; what is missing; what if anything is an extension?)

  3. Construct an activty diagram (i.e., flow chart) for the Schelling model. (You can use any drawing program you like, but you may want to use Dia for this.)

  4. What parameter values must be specified by the user before “experiments” can be run?

  5. Based on your reading and on your preliminary observations of the demo, propose two different quantitative measures of segregation. Justify your proposals.

  6. Create an experimental design, carefully following our discussion of experimental design. (Example: explore how your final measure(s) of segregation are affected by changes in one or more model parameters.)

  7. Run your experiments and report your results, carefully following our discussion of results reporting.

    Summarize your results. Do they support your hypotheses? Comment on the compatability of your proposed segregation measures: do they produce similar or divergent results? Do either or both of your proposed measures have any advantages or drawbacks? (Does either appear more useful than the other?)

  8. Propose some possible extensions to the Schelling model. (Be clear about what applications you have in mind.) You do not have to implement these extensions.

NetLogo Hints:
  • Use BehaviorSpace to implement your experimental design.

Additional Resources

See the NetLogo Models Library for a simple version of the Segregation model.

Cook, Christopher, “Home Page for the Schelling Segregation Model: Demonstration Software” http://www.econ.iastate.edu/tesfatsi/demos/schelling/schellhp.htm

Tesfatsion, Leigh, “Experimental Design: Basic Concepts and Terminology” http://www.econ.iastate.edu/classes/econ308/tesfatsion/ExpDesign.pdf

Thomas C. Schelling, Micromotives and Macrobehavior, W. W. Norton & Company, New York, 1978, Chapter 4 (“Sorting and Mixing: Race and Sex”), pages 137-155

ZIT Exercise

Based on: http://mcbridme.sba.muohio.edu/ace/labs/lab/assets/ZITraderLab.pdf

  1. develop flow diagrams for the ZIT Gode-Sunder computational model

  2. Consider a ZIT implementation, such as the McBride (2008) online demo ZI Trading NetLogo Model: http://mcbridme.sba.muohio.edu/ace/labs/zitrade/zitradenetlogo.html McBride implements the zero-intelligence constrained (ZI-C) traders from Gode and Sunder: the ZI-C traders are constrained not to make any trade that will yield a negative profit. McBride sets the following defaults:

    • Number of Buyers: 50
    • Number of Sellers: 50
    • Maximum Buyer Value: 200
    • Maximum Seller Cost: 200
  3. does the McBride ZI Trading demo for ZI-C trading correctly implement the Gode-Sunder experiments? (With ZI-C traders.)

  4. Complete 5 runs of the ZI-C simulation with McBride’s default parameter values, setting T=2000.

    For each run:

    • predict the equilibrium price and quantity (based on the supply and demand curves) (If you use McBrides implementation, you can hover the cursor over the intersection of the demand and supply curves.)
    • record the following data: volume, average price, standard deviation of price, and market efficiency
  5. Experiment: increase the number of sellers to 100

  6. Record your initial initial simulation results in a table like the following. Make a similar table after changing the number of sellers.

    Obs Price Qty Vol Avg-Price Std-Dev Efficiency
    1
    2
    3
    4
    5
    
  7. Your write up should consider the following questions:

    1. Do the observed transaction prices and volumes approach the predicted values? How quickly?
    2. What level of market efficiency arises?
    3. How much dispersion is there in the transaction prices?
    4. How can a transaction price be above the demand curve or below the supply curve?
    5. How does changing the number of sellers affect efficiency? What about the number of buyers? Why?

Sugarscape Exercise: Introduction

Sugarscape Part I

  1. In the NetlLogo Models Library, experiment with the Sugarscape 1 model. What part of the Epstein and Axtell book does this model correspond to? How accurately does it reproduce the AE setup? (Make a table of values from the code and from the book, with page numbers from the book.)
  2. How accurately does it reproduce the AE results? Why does average vision intially rise? Why does average metabolism initially fall? Why do the agents stop moving?
  3. Why do some agents die off no matter how low you set the population? Does this conflict with the notion that this environment has a "carrying capacity"?
  4. Examine the code. How exactly does the random-in-range "reporter" (i.e., function) work?
  5. Suggest at least one code improvement (in readability, speed, or elegance) that does not change the way the model functions. Note: if you change the code, be sure to work with a copy of the file, not with the original!
  6. Use BehaviorSpace to allow the initial population to vary from 200 to 1000 by increments of 100. As your output, measure the population after 100 ticks. (For this experiment, you may use a single repetition.) Describe the relationship between initial population and final population. Criticize EA’s concept of “carrying capacity”.

Sugarscape Part II

  1. In the NetlLogo Models Library, experiment with the Sugarscape 2 model. What part of the Epstein and Axtell book does this model correspond to? How accurately does it reproduce the AE setup and results? (Make a table of values from the code and from the book, with page numbers.)
  2. How exactly does it differ from the Sugarscape 1 model? What do we learn from this change? (I.e., how do the outcomes change, and why?)
  3. How does the "visualization" chooser work? (Be very detailed.)

Sugarscape Part III

  1. Copy the Model Library's Sugarscape 3 model into your homework directory as sugarscapeIII.nlogo.
  2. Add spice to the model by "rotating" the sugar distribution by 90 degrees. (You should end up with something like Figure IV-1.)
  3. Turn off replacement of turtles that die.
  4. Following EA chapter 4, implement the multi-commodity movement rule.
  5. Use BehaviorSpace to vary maximum vision and maximum metabolism. End each run after 100 iterations, and record the final population (carrying capacity).
  6. Fit a model of the carrying capacity to your variables. (E.g., use Mma's LinearModelFit command.) Hint: you will find using Import to be easiest if you have only data in the file.
  7. Implement the agent trade rule T, and add a switch to turn trade on or off.
  8. Use BehaviorSpace to vary maximum vision, maximum metabolism, and your trade switch. End each run after 1000 iterations, and record the final population (carrying capacity).

Resources

DA-MAOS (RepastJ/Java, open source) by Nanpeng Yu and Ian Guffy:
a double-auction market platform with learning by heterogeneous traders, which can be zero-intelligence traders http://www.econ.iastate.edu/tesfatsi/demos/DAMAOS/DAMAOSHomePage.htm