Upload
unique-henthorne
View
218
Download
0
Embed Size (px)
Citation preview
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 1 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 1
PLEASE HAVE NETLOGO INSTALLED
- it‘s open source - available for windows, mac and linux- download:
GOOGLE „NETLOGO“ - FIRST LINK – DOWNLOAD
- DON‘T FORGET TO INSTALL AFTER DOWNLOADING (TAKES 3 MINUTES)
NETLOGO FIRST STEPS(ARTIFICIAL SOCIETIES)
Gabriel WurzerVienna University of [email protected]
„Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 3
YOU GET WHAT YOU SEE HERE
place user interface elements here
see the world
here
type code here
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 4 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 4
THE NETLOGO WORLD
..is a 3D grid, of which
we show only a 2D slice:
• origin in the middle
• X+ goes right• Y+ goes into
screen• Z+ goes up (not
shown, assuming that z=0)
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 5 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 5
THE NETLOGO WORLD
• grid consists of patches (grid cells)
• each patch is identified by the coordinate at its center,
e.g. patch 0 0 0 at origin
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 6 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 6
THE NETLOGO WORLD
• grid consists of patches (grid cells)
• each patch is identified by the coordinate at its center,
or patch 1 1 0 as shown here
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 7 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 7
AGENTS („TURTLES“)
• movable entities within NetLogo
heading
xcorycorzcor
- 0..360 degrees- 0 is north, 90 east, etc.
- in grid coordinates- e.g. 0, 0, 0
pitch
- 0...360 degrees- 0 is level, 90 up, 270
downroll
- 0...360 degrees- rotation of wingtip- 0 is parallel to XY plane
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 8 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 8
AGENTS („TURTLES“)
• movable entities within NetLogo
heading
xcorycorzcor
- 0..360 degrees- 0 is north, 90 east, etc.
- in grid coordinates- e.g. 0, 0, 0 or 0.5, 0.5, 0
pitch
- 0...360 degrees- 0 is level, 90 up, 270
downroll
- 0...360 degrees- rotation of wingtip- 0 is parallel to XY plane
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 9 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 9
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 10 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 10
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“ or „person“
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 11 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 11
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“ or „person“
- relative to patch size- 1 is the default
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 12 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 12
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“ or „person“
- relative to patch size- 1 is the default- but can be 2 as well
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 13 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 13
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“ or „person“
- relative to patch size- 1 is the default- but can be 2 as well
- can be specified using words,- e.g. RED, GREEN, BLUE
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 14 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 14
• can change their appearence
AGENTS („TURTLES“)
shape
color
size
- e.g. „default“ or „person“
- relative to patch size- 1 is the default- but can be 2 as well
- can be specified using words,- e.g. RED, GREEN, BLUE or MAGENTA
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 15 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 15
• can change their appearence
AGENTS („TURTLES“)
hidden?
- default: false
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 16 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 16
• can change their appearence
AGENTS („TURTLES“)
hidden?
- default: false- can set to true
as well
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 17 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 17
• have a pen glued to their belly
AGENTS („TURTLES“)
pen-mode
- default: „up“, can also be „down“
pen-size
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 18 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 18
• have a pen glued to their belly
AGENTS („TURTLES“)
pen-mode
- default: „up“, can also be „down“- when the turtle moves with pen down, it will leave trails- trail colors corresponds
to the turtle‘s color
pen-size
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 19 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 19
• have a pen glued to their belly
AGENTS („TURTLES“)
pen-mode
- default: „up“, can also be „down“- when the turtle moves with pen down, it will leave trails- trail colors corresponds
to the turtle‘s color
pen-size
- may also influence the thickness of the trail
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 20 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 20
change theseto make anagent move
AGENTS („TURTLES“)
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 21 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 21
change theseto make anagent move
AGENTS („TURTLES“)
- special property containing the ID
of the turtle (e.g. turtle 0)
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 22 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 22
cannot move
PATCHES
- are addressed by their center, e.g. patch 0 0 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 23 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 23
HANDS ON
• start NetLogo 3D • type into the
observer
create-turtles 1
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 24 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 24
SEE THE RESULT
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 25 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 25
RIGHT MOUSE-CLICK THE TURTLE
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 26 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 26
CHOOSE TURTLE 0 > INSPECT TURTLE 0
…turtle 0inspect patch 0 0 -16inspect patch 0 0 -15inspect patch 0 0 -15
inspect turtle 0watch turtle 0follow turtle 0ride turtle 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 27 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 27
HERE YOU GO, NOW…
• see the properties we talked about here
• change them & see the 3D view:pen-mode „down“xcor 10ycor 10zcor 10hidden? true
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 28 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 28
NUMBERS
• are entered as-is• you cannot change „who“• colors are numbers, too
(see Tools>Color Swatches)
color name number
RED 15
BLACK 0
WHITE 9.9
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 29 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 29
STRINGS
• enter with quotation marks• pen-mode: „up“ or „down“• shapes(see Tools>Turtle Shapes
Editor) are for example:
shape name looks like
„default“
„person“
„arrow“
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 30 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 30
BOOLEANS
• enter either true or false
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 31 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 31
AGAIN, RIGHT-CLICK
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 32 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 32
CHOOSE INSPECT PATCH 0 0 -16
• SEE THAT YOU CAN CHANGE THE PROPERTIES THERE THE SAME WAY
…turtle 0inspect patch 0 0 -16inspect patch 0 0 -15inspect patch 0 0 -15
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 33 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 33
NETLOGO ENTITIESobserver
turtles patches
crea
tes
live on
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 34 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 34
CREATE-TURTLES
observercreate-turtles 1
turtle 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 35 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 35
INSPECT
observer
turtle 0
inspect turtle 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 36 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 36
ASK AND SET
observer
turtle 0
ask turtle 0 [
] set color BLUE
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 37 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 37
ALSO FOR PATCHES
observer
ask patch 0 0 0 [
] set pcolor CYAN
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 38 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 38
TRY THIS
ask and set are general commands, everything else is
entity-specific, see Help > NetLogo Dictionary
code won‘t work because…
ask turtle 0 [ create-turtles 1]
only the observercan create-turtles
ask patch 0 0 0[ set color red]
a patch has no property color.perhaps you meant pcolor?
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 39 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 39
COMMANDS SPECIFICALLY FOR TURTLES
forward patch-units, back patch-unitsmoves a turtle in the current direction
left degrees, right degreesalters the heading of a turtle
pen-down, pen-upchanges pen-mode
try this yourself!
ask turtle 0 [forward 1]
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 40 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 40
COMMANDS SPECIFICALLY FOR OBERSERVER
clear-all erases everything
clear-drawingerases only the tracks of turtles
create-turtles number […commands…]creates the specified number of turtles and runscommands on each one of them.
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 41 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 41
ASKING ALL AGENTS
observer
ask turtles [
]
set shape „person“
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 42 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 42
ASKING ALL PATCHES
observer
ask patches [
]
set pcolor cyan
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 43 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 43
THE „WITH“ QUERY
Can address entities based on their properties
using a “with” query:
observerask turtles with [ycor > 0] [
]
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 44 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 44
MORE EXAMPLES WITH „AND“/„OR“
ask turtles with[…]ask patches with[…]
ycor > 0
ycor > 0 and xcor < 0
ycor > 0 or xcor < 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 45 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 45
WRITING A PROGRAM
• code is written on the „code“ tab
click on this tab
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 46 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 46
YOUR FIRST PROGRAM
to setup clear-all create-turtles
1end write this
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 47 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 47
GIVE YOUR PROGRAM A USER INTERFACE
get back to the interface
add a buttontype thishere
setup
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 48 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 48
PRESS IT!
• this will go to code and execute „setup“• the view will turn black and one turtle will
be created at the origin
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 49 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 49
YOUR SECOND PROGRAM
to go ask turtles [
set pen-mode „down“
forward 1 ]end
write this
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 50 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 50
GIVE YOUR PROGRAM A USER INTERFACE
get back to the interface
add a buttontype thishere
go
check this!
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 51 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 51
PRESS TO SEE THE DIFFERENCE
• will execute „go“ in a loop (forever)• lots of trails will appear on screen
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 52 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 52
TYPICAL NETLOGO PROGRAM LAYOUTsetup (executes once)• clear everything• set the environment
(patches)– generate or load per-patch
data • create agents (turtles)
– set shape, color, position and orientation
• set simulation time to 0– …using reset-ticks
go (called in a loop)• simulate environment
– e.g. changes to patches• simulate agent behavior
– orient and move turtles – simulate interactions
between turtles and environment
• update statistics– using e.g. charts and plots
• advance time – …using tick
see File > Models library
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 53 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 53
USER INTERFACE
instead of using constant values, e.g.:create-turtles 10
you may
1. add a slider named num-turtles
2. use that as a placeholder, i.e.create-turtles num-turtles
num-turtles
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 54 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 54
WHERE TO GO FROM HERE
• replacing hard-coded values by UI elements is always a good idea:
• after having finished, your program look like our our prototype implementation (which we present in the following slides):
produces a number
produces true or false)
lets you enter a list of values to choose from
ARTIFICIAL SOCIETIES
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 56 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 56
WHAT IS THIS
naively,• a bunch of turtles• interacting with patches• having a behaviour (both patches AND
turtles!)
…interaction (turtle-turtle, turtle-patch, patch-turtle) is the key to complex systems
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 57 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 57
INTERACTION
• per-patch data (e.g. „amount of wood“) is read or set by a turtle (e.g. get amount of wood here; set amount of wood to 0)
• per-turtle data is influenced likewise - can be read or set by a patch (e.g. if any turles here then set color to my color)
data
behaviour
actor
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 58 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 58
DATA: PER-PATCH
is written as: patches-own [ wood food ]at begin of your code. all data is initially set to zero, must explicitly
ask patches [set wood 10] in setup if you want to change that
wood = 0 food = 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 59 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 59
try it, e.g. using
patches-own [ value]
and going to the interface tab
YOUR TURN!
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 60 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 60
DATA: PER-TURTLE
is likewise written as:
turtles-own [ carries-wood carries-food ]
try this outto see
how it looks
carries-wood = 0 carries-food = 0
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 61 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 61
BEHAVIOUR: SETTING A PATCH VALUE
TOP VIEW
value
SIDE VIEW
1. each turtle is in exactly one patch2. it can access a value of a patch by writing
its name, e.g.: ask turtle 0 [set value (value + 1)]
try it!
+1
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 62 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 62
MORE OPTIONS
you can get a value from…
SAME PATCH PATCH AHEAD SURROUNDING PATCH
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 63 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 63
GET VALUE AT
Figure
take
n f
rom
McL
oughlin
, La
ram
ee a
nd Z
hang 2
00
9,
“Easy
inte
gra
l su
rface
s “
option code
same patch value[value] of patch-here
patch one step ahead [value] of patch-ahead 1
surrounding patches(mean, minimum or maximum)
mean [value] of neighborsormax [value] of neighborsormin [value] of neighbors
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 64 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 64
SET VALUE AT
• however, to set a value at a different patch, you must ask:
ask turtle 0 [ ask patch-ahead 1 [ set value (value + 1) ] ]• yes that‘s right you can nest asks (in fact,
you can nest almost everything)
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 65 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 65
NEED FOR INTERMEDIATE MEMORY
ask turtle 0 [ ask patch-ahead 1 [ set pcolor color ]]
pcolor
doesn‘t workwhich of these two colors do
you mean?color color
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 66 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 66
INTERMEDIATE MEMORY
ask turtle 0 [ let the-color color ask patch-ahead 1 [ set pcolor the-color ]]
use let to remember things even after nesting, like here:
the color
RED
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 67 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 67
BEHAVIOUR: SETTING TURTLE VALUES
ask patch 0 0 0 [ ask turtles-here [ set color red ]]
• remember: there can be many turtles in the same patch
color
RED
colorcolor
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 68 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 68
MORE OPTIONS
you can also set a value to…
RED
one-of turtles-here
one-of turtles-herewith [color = purple]
RED
RED
one-of turtles in-radius 2
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 69 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 69
SELECTING TURTLES
sample model:• garden.nlogo –
used as demo for selecting turtles
Wurzer, Lorenz, Popov: „NetLogo Workshop (Part 1)“, in eCAADe 2012 Prague, Slide 70 „Netlogo First Steps (Artif. Societies) “, in Social Simulation Conference 2014, Barcelona, Slide 70
SO WE COME TO BREE DS
• NetLogo predefines one „breed“ of agents called turtles
• As programmer, you are free to define more breeds using the „breed“ keyword:
• breed inherits properties ofturtle (no multiple inheritence, no patch breeds)
breed [persons person]
plural singular
THANK YOU