Netlogo Field Guide
Total Page:16
File Type:pdf, Size:1020Kb
A Field Guide to NetLogo Steve Scott and Matt Koehler George Mason University Department of Computational Social Science Copyright © 2014. The MITRE Corporation. All Rights Reserved. About the Cover: The green sea turtle (Chelonia mydas) image on the cover was created by Jack Javech of the National Oceanographic and Atmospheric Administration (NOAA). NOAA's National Marine Fisheries Service (NMFS) and the U.S. Fish and Wildlife Service (FWS) work together to protect sea turtles, which are affected by numerous threats including fisheries bycatch, habitat destruction and degradation, marine pollution, and boat strikes. The NMFS, FWS, and numerous partners are actively involved in sea turtle conservation efforts, such as monitoring sea turtle nesting activity, protecting turtle nests and nesting beach habitat, and implementing and enforcing regulations to reduce bycatch of sea turtles. Visit the NMFS website at http://www.nmfs.noaa.gov/pr/species/turtles/ and the FWS website at http://www.fws.gov/northflorida/SeaTurtles/seaturtle-info.htm for further information about sea turtles and conservation efforts. i Table of Contents Preface ............................................................................................................................................. 1 About This Guide ........................................................................................................................ 1 About NetLogo ........................................................................................................................... 1 Prerequisites ................................................................................................................................ 1 Font Conventions ........................................................................................................................ 1 About the Programs in This Guide ............................................................................................. 1 How to Suggest Improvements ................................................................................................... 2 Other NetLogo References ......................................................................................................... 2 Acknowledgements ..................................................................................................................... 3 NetLogo Versioning .................................................................................................................... 3 1. Getting Started ........................................................................................................................ 5 Running NetLogo ........................................................................................................................ 5 Running a NetLogo Model from the Library .............................................................................. 6 Diving In: A Quick Hands-On Tour ......................................................................................... 10 A Guided Tour of the NetLogo Environment ........................................................................... 13 Summary ................................................................................................................................... 17 2. Agent-Based Modeling Concepts ......................................................................................... 18 3. Programming in NetLogo ..................................................................................................... 21 Agents ....................................................................................................................................... 21 Turtles (and Breeds) .............................................................................................................. 21 Patches .................................................................................................................................. 22 Links (and Breeds) ................................................................................................................ 23 Observer ................................................................................................................................ 24 Data Structures and Variables ................................................................................................... 24 Variables in NetLogo ............................................................................................................ 24 Global Variables (and Interface Objects) ............................................................................. 25 Local Variables ..................................................................................................................... 26 Agentsets ............................................................................................................................... 28 Lists ....................................................................................................................................... 29 Booleans ................................................................................................................................ 34 Neighbors .............................................................................................................................. 35 ii Interface Objects: Button, Slider, Switch, Chooser, Input, Monitor, Plot, Output, Note ......... 36 Button .................................................................................................................................... 37 Slider ..................................................................................................................................... 40 Switch ................................................................................................................................... 41 Chooser ................................................................................................................................. 42 Input Box .............................................................................................................................. 43 Monitor ................................................................................................................................. 44 Plot ........................................................................................................................................ 47 Output ................................................................................................................................... 53 Note ....................................................................................................................................... 53 Control Flow ............................................................................................................................. 54 Ask ........................................................................................................................................ 54 If and If-Then-Else ................................................................................................................ 54 While Loop ........................................................................................................................... 55 Repeat Loop .......................................................................................................................... 56 List Iteration .......................................................................................................................... 56 Procedures ................................................................................................................................. 58 User-Defined Procedures ...................................................................................................... 58 User-Defined Functions (Reporters) ..................................................................................... 59 Passing Parameters ................................................................................................................ 59 NetLogo Extensions (Arrays, Tables, Geographic Info Systems, Sounds, etc.) .................. 60 Input/Ouput ............................................................................................................................... 61 Console I/O ........................................................................................................................... 61 File I/O .................................................................................................................................. 65 4. Using Models for Research ................................................................................................... 70 Updating an Existing Model ..................................................................................................... 70 Running the Updated Model ..................................................................................................... 82 Experimenting with the Updated Model ................................................................................... 83 Managing Multiple Experiments Using BehaviorSpace ........................................................... 85 5. So, Your Model Doesn’t Work… ......................................................................................... 93 Introduction ............................................................................................................................... 93 Random Numbers ....................................................................................................................