From Animations To Science

EES 4760/5760

Agent-Based & Individual-Based Computational Modeling

Jonathan Gilligan

Class #6: Thurs. January 25 2018

Starting Up:

Download the following files
(see download page at



  • Absence:
    • I will miss class Feb. 8, Mar. 13–15, and Apr. 10–12.
      • I will schedule make-up sessions for the classes I miss.
  • Semester Project:
    • Fri. Feb. 9: Pick a model from one of the open-source repositories, or NetLogo “model library” that you want to work with.
      • One-page description of model and thoughts for extending it (post to Box)
    • Feb. 22: Examine ODD and code of your chosen model.
      • Short write-up of how model works and output from running it
    • Fri. Mar. 16: ODD for extending model
    • Apr. 17-19: Presentations on experiments with extended models
    • Apr. 24: Write-up of research project (around 10 pages)
  • Team Project:
    • Each team (2–3 students) will code a model from an ODD in the textbook (Ch. 10 or Ch. 13)
    • Use model to do exercises from book
    • Make presentation about what you learned (Tues. Feb. 27)
  • Detailed Assignments on Brightspace

Experiments with the Butterfly Model

Plot Corridor Width

  • On the interface tab, add a plot

    plot dialog box

  • On the code tab, add a line to go to plot the corridor width

    plot corridor-width

Enhance Interface

  • Add a button to export the plot to a file:

    export-plot "Corridor-width" (word "corridor-output-for-q-" (precision q 2) ".csv")               
  • Add a button to increment q by 0.1


  • If your model is having problems, compare it to butterfly_class_06b.nlogo

  • Open BehaviorSpace and create an experiment
    • Call it experiment
    • Vary real-terrain between false and true
    • Vary q from 0 to 1 in steps of 0.2
    • Run 20 repetitions for each value of q.
    • Measure corridor-width at the last tick only
    • Set time limit to 0 to let model run until it stops
  • Run BehaviorSpace experiment
    • Save “table” output
    • Speed things up by unchecking “Update view” and “Update plots and monitors”
  • Open the analyzeBehaviorspace app at
    and use it to compare the relationship between corridor width and q for each terrain



  • Work together with a partner
  • Add a button to erase the tracks of the turtles (Exercise 5.2)
  • Using the realistic terrain, play with q and see what values do best at helping butterflies find mates near hilltops.


Testing Models

  • Using monitors
  • Unit testing resource “Testing Is Fun”
    • Open “butterfly_class_06a_testing.nlogo
    • At beginning of code:

      __includes ["jg-tif.nls"]
    • In to_setup add:

    • In to go add:

      set-context "Reporting corridor-width"
      test-that "# visited patches should equal # yellow patches"  
      expect-that (count patches with [visited?]) equals (count patches with [pcolor = yellow])            
      if ticks >= 1000 or all? turtles [finished?]



  • A tricky concept
  • Early definition: “stable macroscopic patterns arising from the local interaction of agents” — Joshua Epstein, 1996
  • Epstein ten years later: “I have always been uncomfortable with the vagueness and occasional mysticism surrounding this word.”
  • Epstein now prefers to talk about Generative Social Science”
  • Other scientists (especially in natural sciences: biology, physics, etc.) are more comfortable talking about emergence.