AnthropologischeGesellschaftWien

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

RAPTOR Syntax and Semantics By Lt Col Schorsch
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 1 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Automating Tasks With Macros
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Department of Computer Science What is NetLogo UH-DMML  Multi-agent programmable modeling environment  Well suited for modeling complex systems evolving.
An Introduction to NetLogo given by Gabriel Wurzer. ,
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Week 11 DO NOW QUESTIONS. An ask turtles block is a set of instructions that is issued to every turtle. Even though computers can do things very quickly,
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
An Introduction to NetLogo Gabriel Wurzer, Vienna University of Technology AnthropologischeGesellschaftWien.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
XP New Perspectives on Integrating Microsoft Office XP Tutorial 3 1 Integrating Microsoft Office XP Tutorial 3 – Integrating Word, Excel, Access, and PowerPoint.
New Mexico Computer Science For All Variables and Scope Maureen Psaila-Dombrowski.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
M10 WS11:Krankenhausbedarfsplanung The World as We See It given by Gabriel Wurzer and Wolfgang E. Lorenz
1 Agent-Based Tools: focus on NetLogo Ing. Cristina Ponsiglione University of Naples Federico II Laboratorio di Simulazione ad Agenti.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz
MOODLE TRAINING — ADVANCED TOPICS — Fall 2016 Convocation week Michael Scanlan Office of Information Technology.
Debugging with Eclipse
An Introduction to NetLogo given by Gabriel Wurzer and Wolfgang E
VAB™ for INFINITY Tutorial
Using ArcView GIS: Part 3
Creating Oracle Business Intelligence Interactive Dashboards
Management Information Systems
Management Information Systems
What to do when a test fails
Topics Introduction to Repetition Structures
Testing and Debugging.
ECS10 10/10
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
– Officiating Management Software
Hands-On given by Gabriel Wurzer and Wolfgang E. Lorenz
Changing Color, Using Text Objects, and Random Selection in Alice
Saving, Modifying page, grammar & spell checking, and printing
Adding Assignments and Learning Units to Your TSS Course
Topics Introduction to Repetition Structures
Introduction to Events
Important terms Black-box testing White-box testing Regression testing
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Microsoft Word Reviewing Documents.
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
How to Start This PowerPoint® Tutorial
Creating and Modifying Queries
Module 5: Data Cleaning and Building Reports
Coding Concepts (Sub- Programs)
An Introduction to VEX IQ Programming with Modkit
Loops CIS 40 – Introduction to Programming in Python
Introduction to TouchDevelop
CIS 16 Application Development Programming with Visual Basic
Moodle Training — Advanced Topics —
creating a ecosystems model in net logo
Chapter 1 Introducing Small Basic
Debugging with Eclipse
This training session will cover:
Presentation transcript:

AnthropologischeGesellschaftWien Model Building These slides are a slightly updated version of Gabriel Wurzer, Vienna University of Technology www.iemar.tuwien.ac.at

When things go wrong, or: How to debug

Debugging Today meaning "to fix software errors" Previous meaning: located in evanston near chicago Grace Hopper, 1947, Logbook Mark II: "Relay #70, Panel F (moth) in relay.", National Museum of American History, Washington Rear Admiral Grace Hopper, US Navy

Defensive versus offensive debugging The NetLogo program aborts with an error (obvious bug) The NetLogo program behaves incomprehensibly e.g. turtles do not move as expected computed values are not as expected Output intermediate results, in order to check if model behaves correctly Formulate test cases that need to be satisfied by the program, and write test programs that execute these Defensive Debugging Offensive Debugging

NetLogo debugging capabilities ...are astonishingly limited: print value… prints a value to the command center area, e.g. Concatenation may happen for adding a pre- or suffix to the printed value, using the word command: ask turtle 0 [print shape] print (word "The shape is " shape)

Further debugging… self reports the breed followed by the who number of the turtle, (e.g. "turtle 0") watch puts a shiny spot around a turtle if you want to watch one randomly chosen agent out of a population, you can use the reporter one-of in fact, one-of is a general command for choosing one member of a population ask turtles with […] [ print ] watch turtle 0 watch one-of turtles self watch one-of

Querying somebody else's properties Often, you "are" observer or a specific turtle or patch. Querying somebody else's values can be done using of: of is used to access a property of an entity given by you. Examples: print [shape] of turtle 0 print [pcolor] of patch 0 0 ask patch 0 0 [ set pcolor [pcolor] of patch 1 1 ]

Comparing ask and of ask patch 0 0 [ print pcolor ;you are patch 0 0 ] ; you are observer print [pcolor] of patch 0 0 ask enters an entity. Therefore, can access a property by giving its name (e.g. print pcolor) of accesses a property of an entity you give – you need not be "inside" the entity Hint: yes, of is a reporter, you might have guessed it!

Using of for debugging Add a monitor to the Interface In the appearing dialog, you can type any query. Type the following query and hit OK: The result of this query will be shown in the textfield of the monitor.

General Pattern OVERLAY IMAGE

Overlaying an image Can import an image (just for eye candy, does not influence NetLogo) using Can clear the imported image using © Digiglobe and Google Inc. import-drawing "name.png" clear-drawing

Importing PER-PATCH DaTA Patch pattern Importing PER-PATCH DaTA

Usage Data that must be available per patch (i.e. in some previously defined properties) should be imported into NetLogo This data is generated e.g. in a GIS or drawing program There can be a variety of these layers, e.g. one per resource (e.g. grain, ore, water)

Exporting the view… This is a pre-step for importing: Change the pcolor of some patches by right-clicking and choosing "inspect", then set pcolor e.g. to YELLOW Right-click the view area and choose "Export View"

Exported view The exported image is exactly as the NetLogo view. Can edit this file in a graphics program and re-import using: The colors found in the file will be mapped to the nearest NetLogo color, with fine details being lost import-pcolors "name.png"

Hint: Pixel-exact mapping Can also do a pixel-exact import when clicking on Settings in Interface, then specifying: max-pxcor half image width max-pycor half image height Patch-size 1 pixels

Mapping color to a value – existence of grain patches-own [ grain ] … ask patches [ set grain 0 if pcolor = YELLOW [ set grain 1

A closer look at colors Colors in NetLogo are really numbers. Names like YELLOW are only shorthands.

Greys are interesting The color 0 stands for black. This is the default color for patches. The color 9.9 stands for white, and all other colors in between 0 and 9.9 are grays. Observation: Percentages go from 0-100, NetLogo colors from 0-9.9 Hmmmmm…..

Mapping color to a value – quantity of grain patches-own [ grain ] … ask patches [ set grain pcolor Hint: could also use a scale factor, e.g. grain pcolor *

Mapping color to a value – percent of grain patches-own [ grain ] … ask patches [ set grain (pcolor / 9.9) * 100 *

Turtle Pattern CUSTOM TURTLE SHAPES

Custom shapes for turtles From Tools, choose Turtle Shapes Editor Click on "New" to add a shape

The shape editor in brief Draw your shape In the name field, assign a name Should the shape rotate with the heading of the turtle, click on Rotatable Under "Color that changes", give the color that is set to the turtle's color

Assigning your newly drawn shape … create-turtles 1 [ set shape "my shape" ] Hint: if you do not want your shape to change color, set "Color that changes" to some color that does not appear in the shape.

Temporary storage

Storing values - revisited So far, two type of storages have been introduced: properties of an entity values entered via the user interface (called global variables) property

The need for an intermediate storage makes code easier to read, e.g.: get all turtles which meet a certain criterion filter this intermediate result by a second criterion ask the remaining turtles to do something to example introduce set to turtles with[…] ask with […] [ … ] end candidates candidates candidates example of code which uses intermediate storage

Lifespan of intermediate storage intermediate storage is temporary: the storage is thrown away once the code block that introduced it ends. to example introduce set to turtles with[…] ask with […] [ … ] end Lifespan of candidates candidates candidates candidates

Show me the code… an intermediate storage is called "local variable" it is introduced using let: to access the value stored in a variable, its name (candidates) is given. to example let candidates turtles with[…] ask with […] [ … ] end candidates candidates let name value

can assign the following values to a variable: a concrete value (e.g. 10, false, "person") the value NOBODY, i.e. "no value set" a result of a reporter or query

Examples with variables Calculation using variables: let a 12 let b 20 let c (a + b) print (word "c is " c) Incrementing a variable using set: let d 0 set d (d + 1) print (word "d is " d) Calculation using variables Setting a variable to "no value" let e NOBODY print (word "e is " e) Setting a variable to the result of a query or reporter let e turtles with [color = SKY] let f sin 30 ask e [ print self ] print (word "f is " f) Setting a variable to "no value" Setting a variable to the result of a query or reporter Incrementing a variable using set:

When variables take up agentsets with […] reports a set of turtles or patches the returned set is called agentset you can test whether the set is empty by using the keyword any? you can refer to the contained agents by asking the agentset Hint: The keyword for addressing a population (e.g. turtles, patches, persons, etc.) return agentsets as well, so you might well write: if not any? turtles [ print "All dead." ] let redones turtles with [color = RED] if any? redones [ ask redones [print self] ] any?

Writing reporters and using Parameters

A tale of users and programmers User of sin Programmer of sin to setup print sin 30 end to sin (x) 1. 2. give back result to user end We have seen how to use reporters As mentioned, "something is being done behind the scenes", i.e. the parameter or parameters are passed into a reporter this is used like a variable the result is given back to the user

Don't be a user – write reporters yourself you can write reporters yourself: beneficial for "hiding the details" of your model: to-report add [x y] let result (x + y) report result end Usage: to-report name [ parameters ] ; calculate something here ; using the parameters report result end optional no parameters specified to setup print water-patches end to-report water-patches report patches with [color = SKY] end

Parameters …can also be used in procedures, by the way: to move-turtles [ in-direction how-far ] ask turtles [ set heading in-direction forward how-far ] end

Recap – When to use what Write a procedure Write a reporter to group code lines together under a sounding name (e.g. move-turtles) to perform a calculation and returns the result to the user (e.g. add) Use parameters whenever your code depends on values that need to be supplied by the user. Hint: Think of parameters as local variables, which are not defined using "let" but given at the start of your procedure or reporter.

Turtle pattern LINKING TURTLES

Usage Links two turtles together to signify a (social?) relationship between them Should be able to query for "the turtle at the other side of the link"

Introducing links Links are an own breed, which is created by a turtle: Any breed can be linked. Links can be both directed and undirected, although we will only cover the latter ones in this tutorial (refer to NetLogo Dictionary for directed ones). Furthermore, you can create breeds of links, which is also not covered in this course. ask person 0 [ create-link-with turtle 1 ] create-link-with

How the rest is done… ask person 0 [ create-link-with turtle 1 create-link-with turtle 2 ] ask link-neighbors with […] [ print self link-neighbors reports all turtles connected to the current turtle by a link as always, this agentset can be further narrowed down using with[…] link-neighbors

Co-create dependent turtles breed [persons person] … create-persons 1 [ let holder self create-turtles 1 [ create-link-with holder set xcor random-xcor set ycor random-ycor ] Wish to create persons and turtles at the same time, tied together (Note: it is a house- trained turtle we create). turtle is created by the person using hatch-turtles, which is just like create-turtles (but can be used by turtles) laying the turtle on the person's leash is done by creating a link to the holder hatch-turtles

Patch pattern NEIGHBORS

Usage ask patch 0 0 [ ask neighbors [ … ] A patch needs to address its neighbors Should be possible to either get the 8-neighborhood, 4-neighborhood or patches in any radius Additional criteria should be possible using with, e.g. with [not any? turtles-here]

How it is done… ask patch 0 0 [ ask neighbors with[…] [ ] ask neighbors4 with[…] [ ask patches in-radius 4 with[…][ neighbors reports all 8 patches that surround the calling patch, neighbors4 only the four patches in the north, south, west and east. in-radius is a reporter that filters the agentset given on the left (patches) so that only those members being within the given radius of the caller remain neighbors neighbors4 in-radius Hint: in-radius can also be used for turtles, i.e. turtles in-radius 4

DISCOVERING WHO'S (ALSO) HERE Turtle and patch pattern DISCOVERING WHO'S (ALSO) HERE

Usage ask turtle or patch [ get all other turtles at this spot … ] A turtle or patch wants to know which turtles stand here Should also be able to select other breeds than turtles Reported entities should be "all on this spot, excluding caller"

How it is done… … ask turtle 0 [ ask [ print self ] ask patch 0 0 [ ask [ turtles-here is a reporter giving all agents on the current spot as agentset if the caller is an agent, he can exclude himself by using "other" may specifically target other breeds than turtles using breed-name-here (e.g. other persons-here) other turtles-here turtles-here

Turtle Pattern interaction pattern

Usage ask turtle 0 [ ask patch 0 0 [ … ] An agent wants to interact with other agents or patches, probably exchanging some values In the course of the interactions, multiple nested asks are used, i.e. the first entity is asked, to… ask a second entity, to… do something

How it is done… ask turtle 0 [ let the-turtle self ask patch 0 0 [ set pcolor [color] of the-turtle ] The caller temporarily stores himself in a local variable Then, the patch is asked Inside the ask, a property of the caller is retrieved using of This value is then assigned to a property of the patch ask pcolor ask color is set to

Hands on: Dropping a value turtles-own [ carries ] patches-own [ stores to setup ask patches [ set stores 0 ] create-turtles 1 [ set carries 10 end stores = 0 carries = 1

Hands on: Dropping a value to go ask turtles [ forward 1 if carries > 0 [ set carries (carries - 1) let the-turtle self ask patch-here [ set stores (stores + 1) set pcolor [color] of the-turtle ] end patch-here reports the patch under the turtle

Hands on: Retrieving a value turtles-own [ carries ] patches-own [ stores to setup ask patches [ set stores 10 ] create-turtles 1 [ set carries 0 end stores = 10 carries = 0

Hands on: Retrieving a value to go ask turtles [ forward 1 if [stores] of patch-here > 0 [ set carries (carries + 1) ask patch-here [ set stores (stores - 1) ] end

LooPS

So far… The button repeated the code contained in the procedure "go" until it was toggled again. Sometimes, however, you will wish to repeat a set of code lines based on some Boolean condition, e.g.: to go while a settlement is needed add a settlement ] end Usage: while [ condition ] [ run these commands ] A Boolean reporter. The details are hidden from you, it simply tells you if one more settle-ment is needed (true / false)

Example: doing something a number of times let counter 0 while [ counter < 10 ] [ print (word "the counter is " counter) set counter (counter + 1) ] Hint: You should not forget this, or else counter will never reach 10, resulting in an endless loop

AnthropologischeGesellschaftWien Thank you K. Kowarik, H. Reschreiter, M. Doneus, W. Lorenz, N. Popper and G. Wurzer: "Agents in Archeology Workshop 2011", Natural History Museum, Vienna, Austria.