1 / 94

An Introduction to NetLogo given by Gabriel Wurzer *, *not a mathematician

An Introduction to NetLogo given by Gabriel Wurzer *, *not a mathematician. www.iemar.tuwien.ac.at. aia11.nhm-wien.ac.at/index.php?Results_%28New%21%29. see results of AIA11 workshop for an extended version of this tutorial, plus: a video showing this tutorial in full:. Netlogo.

onofre
Download Presentation

An Introduction to NetLogo given by Gabriel Wurzer *, *not a mathematician

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An IntroductiontoNetLogogivenbyGabriel Wurzer*,*not a mathematician www.iemar.tuwien.ac.at

  2. aia11.nhm-wien.ac.at/index.php?Results_%28New%21%29 • see results of AIA11 workshop for an extended version of this tutorial, plus: a video showing this tutorial in full:

  3. Netlogo free* agent-based simulation environment by Uri Wilensky, Northwestern University, which is based on programming language „Logo“ by Seymour Papert, MIT which is based on programming language „Lisp“ by John McCarthy, Stanford __ * http://ccl.northwestern.edu/netlogo/ Wilensky 1999 Papert 1968 McCarthy 1958

  4. Netlogois a discretesimulation Simulation environment with discretized world („patches“), on which agents („turtles“) perform actions in discrete time steps („ticks“)

  5. WhatNetLogoisusedfor…

  6. Example: urban planning Procedural City Modeling (Lechner et al. 2003) http://ccl.northwestern.edu/papers/ProceduralCityMod.pdf Simulation of Urban Land Development and Land Use (Tsai-chu and Bo-yi 2010) http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=5421277 Picture courtesyof Lechner, Watson, Wilenskyand Felsen, Picture courtesyofTsai-chuand Bo-yi

  7. Example: hospitalplanning An Agent Based Simulation Tool for Scheduling Emergency Department Physicians (Jones and Evans, 2008) http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2656074/ Computer Terminal Placement and Workflow in an Emergency Department: An Agent-based Model (Poynton et al. 2007) http://tuvalu.santafe.edu/events/workshops/index.php/CSSS_2007_Santa_Fe-Final_Papers Picture courtesyofPoynton, Shah, BeLue, Mazzotta, Beil and Habibullah

  8. The NetLogo Environment

  9. Main screenof a model forsimulation fordocumentation forcode • simulation performedin interface area • documentation area lists what to do with the model • programming is done in the procedures area world discretized into grid, visible in center of screen Model world (grid)

  10. Co-ordinatespace • origin (0,0) in middle ofgrid • X+ right, Y+ up • world composed of grid cells („patches“) • each patch is identified by the coordinate at its center,

  11. Co-ordinatespace • origin (0,0) in middleofgrid • X+ right, Y+ up • worldcomposedofgridcells („patches“) • eachpatchisidentifiedbythecoordinateatitscenter, e.g. patch 0 0 atorigin

  12. Co-ordinatespace • origin (0,0) in middleofgrid • X+ right, Y+ up • worldcomposedofgridcells („patches“) • eachpatchisidentifiedbythecoordinateatitscenter, e.g. patch 0 0 atoriginpatch 1 1 elsewhere

  13. Properties andabilitiesofturtles

  14. Turtlesare... • movable entities within the netlogo world heading • 0..360 degrees • 0 is north, 90 east, etc. xcor ycor • in grid coordinates • e.g. 0, 0

  15. Turtlesare... • movableentitieswithinthenetlogoworld heading • 0..360 degrees • 0 isnorth, 90 east, etc. xcor ycor • in gridcoordinates • e.g. 0, 0 or 0.5, 0.5

  16. Turtlesare... • taking form (they represent an active, animated entity) shape • e.g. „default“ size color

  17. Turtlesare... • taking form (theyrepresent an active, animatedentity) shape • e.g. „default“ or „person“ size • relative to patch size • 1 is the default color

  18. Turtlesare... • taking form (theyrepresent an active, animatedentity) shape • e.g. „default“ or „person“ size • relative topatchsize • 1 isthedefault • but canbe 2 as well color • e.g. RED, GREEN, BLUE

  19. Turtlesare... • taking form (theyrepresent an active, animatedentity) shape • e.g. „default“ or „person“ size • relative topatchsize • 1 isthedefault • but canbe 2 as well color • e.g. RED, GREEN, BLUE • or MAGENTA

  20. Turtlesare... • by default visible, but can be hidden as well hidden? • true or false

  21. Properties • unique id for each turtle in • NetLogo who heading xcor turtle 0 ycor shape size color hidden?

  22. Commands observer create-turtles 1

  23. Commands turtle 0 observer inspect turtle 0

  24. Commands who heading xcor turtle 0 ycor shape observer size color hidden?

  25. Your turn... • Start NetLogo • In the observer>input box, entercreate-turtles 1 • in the same location, enter inspect turtle 0 • enter RED as color,0 as heading1 as xcor1 as ycor„person“ as shape create-turtles 1 inspect turtle 0

  26. A closerlookattheinspectedproperties... who heading xcor numbers (e.g. 0) turtle 0 ycor shape size color Booleans (true or false) hidden? strings (e.g. „person“) note the parantheses !

  27. Data types In detail… numbers… ordinal type (1,2,3) comparison: (1<2) operators: +,-,*,/ Booleans… truth type (true, false) comparison: (true != false) operators: and, or, not strings… character chains („abra“) comparison „test“ != „abra“ operators: concatenation („abra“ + „cadabra“ = „abracadabra“) slicing („abracadabra“[4:6] = „cad“) … • Numbers, Booleans and strings are data types • Each data type has its own syntax (e.g. „xyz“ for strings) • Each data type has its own benefits • numbers are made for calculations (+, -, /, *, sin, cos, etc.) • Booleans are made for conditions (if hidden? ...) • strings are made for supplying names (e.g. use the „default“ shape)

  28. The askcommand who Observercalled, askingmeto... heading xcor turtle 0 ycor ask turtle 0 [ ] shape observer size color hidden?

  29. The setcommand who heading xcor turtle 0 ycor ask turtle 0 [ ] shape set color blue observer size color hidden?

  30. The setcommand who heading xcor turtle 0 ycor shape observer size color hidden?

  31. Askexplained • The askcommandcalls a setofturtlesorpatches, passingcommandstothem • These commandsaresupplied in brackes, i.e. asksomebody[do thisdo that ] • The commandsareexecutedbythecalled turtle orpatch, andinfluenceitsproperties

  32. Context Because observer, turtles and patches are inherently different, only commands that the called entity understands can be issued who heading xcor ask turtle 0 [ ] turtle 0 create-turtles 1 ycor shape size color hidden?

  33. Context Because observer, turtles and patches are inherently different, only commands that the called entity understands can be issued YOU KNOW PRETTY WELL THAT ONLY OBSERVER CAN CREATE TURTLES #*! who heading xcor ask turtle 0 [ ] create-turtles 1 ycor shape size color hidden?

  34. Context Because observer, turtles and patches are inherently different, only commands that the called entity understands can be issued who heading xcor ycor shape size color hidden?

  35. Commandsforturtles set property value sets a property to a specified value forwardpatch-units,backpatch-unitsmoves a turtle in the current direction leftdegrees, right degrees alters the heading of a turtle ...and every other command listed in the Netlogo Dictionary under „Turtle-related“ (see: Menu - Help – NetLogo Dictionary)

  36. Haveyouseenit? The NetLogo Dictionary is NetLogo‘s central source for help.

  37. Hands on – ifyoudownloadedthistutorial ! • letobserverask turtle 0 - tosetitsproperty „color“ toyellow - toissuethefollowingcommands: forward 1 left 45 forward 1 • seeforyourselfwhathappenswhenyourun:ask turtle 0 [create-turtles 1] • look inside the NetLogo Dictionary and find the meaning ofthe following commands: - pen-up, pen-down then, experimentwiththeseusingforward, leftandrightas additional commands!

  38. Results (Probably) • pen-down and pen-up change the state of a property named „pen-mode“ • color of track equals color of turtle • thickness of track can be set using the property „pen-size“ (also found in a turtle) • observer may erase the tracks by using the command „clear-drawing“ or everythingincluding turtles with „clear-all“ pen-up pen-down „up“ or „down“ a number (default is 1) pen-mode clear-drawing pen-size clear-all

  39. Summingup

  40. Writing Programs

  41. General NetLogoprogramlayout Example from Models Library • set up the program (once), e.g. • clear everything, • set the environment • create agents • simulation loop (called repeatedly) • simulate worlde.g. grain growth on patches • simulate agent behaviour e.g. movement, interaction • update charts & plots 1. open the„Models Library“ 1. type „histogram“ andchooseHistogramExample

  42. Exploringthe „HistogramExample“ • the two buttons „setup“ and „go“ are used to interact with the model • setup clears and fills the world, • go simulates and generates the histogram (repeatedly, in time steps – “ticks”) • click setup, then go buttons plot world

  43. Foreveror not forever 0. (Unpress the „go“ button) • Right-click on the go button • Select Edit... 3. A dialogappears 4. Unclick „Forever“ 5. Choose „OK“  click on „setup“, then „go“ • Buttons areusedtocallsetupandsimulationroutine • Choosing „Forever“ on a button will repeatedlycallit,thereforeestablishing a loop

  44. Behind thescenes • Go to the procedures tab • observe the two routines„to setup“ and „to go“,that contain the actual codethat is performed for settingup and performing a sim step • note how these routines are called from the buttons: (clear) (createturtles) (moveturtles) ...

  45. Procedures • A setofcommandsisstructured • intologicalunitscalled • Procedures • thatalwayshavethesyntax • Note thatthecommands in a • arethe same aswereentered • in commandcenter (observer>) to setup ...commands... end to go ...commands... end tonameofprocedure commands end

  46. Writing thefirstprogram • Choose File – New • Go to Procedures tab • Type the following code: • These arecomments, • startingwith ’ • Comments areignored • byNetLogo, but may • help in understanding • yourcode • A commonapproachis„commentbeforecode“ to setup ;start of „setup“ clear-all ;clear world create-turtles 1 ;create turtle end ;end of „setup“ to go ;start of „go“ ask turtle 0 [ ;ask the turtle forward 1 ;move fwd 1 unit ] ;end of ask end ;end of „go“

  47. Connectingtheprogramtotheuserinterface • On the Interface tab, choose Add („Button“ must be selected in the neighboring dropdown) • Click anywhere within the white space to insert a button • A dialog appears • Enter „setup“ in the Commands textfield and hit the „OK“ button • Insert another button (using the same steps), enter „go“ in Commands and enable „Forever“, then choose „OK“.  press the „setup“ button, then „go“

  48. Introducingmanyturtles (battle plan) The presentedprogramisnowextended in order tocreate a wholepopulationofturtles: • introduce a slidernamed „num-turtles“ whichsetsthenumberofturtlestocreate • usethisvalue in setup • get hold of all turtlesandtellthemtosettheirheading, colorandshapeto a definedvalue • furthermore, distribute all turtlesovertheavailableworld

  49. Adding a slider • In the Interface tab, click on the dropdown where „Button“ is shown, in order to expose all available interface components. • Choose „Slider“ • Click Add and click within the white space in order to add the slider • In the appearing dialog, add „num-turtles“ in the „Global variable“ textfield:

  50. Creatingnum-turtles • changesetupasgivenbelow • runthechangedprocedureusingthe „setup“ button • takenoteofthedozensofturtlescreatedusinginspect(rightmouseclick on theturtles) to setup clear-all create-turtles num-turtles end

More Related