1
00:00:08,643 --> 00:00:12,091
We've talked about turtles which are the
basic mobile agent
2
00:00:12,091 --> 00:00:18,227
and probably the agents that you'll use
the most often within your NetLogo models
3
00:00:18,227 --> 00:00:23,785
but there are two other types of agents
that exist within the NetLogo space.
4
00:00:23,785 --> 00:00:29,429
One is the patches. Patches are the
immobile background objects...
5
00:00:29,429 --> 00:00:34,721
that exist behind every space of the
world.
6
00:00:34,721 --> 00:00:37,549
They may not be obvious, because they're
all black,
7
00:00:37,549 --> 00:00:43,393
but the world that you're seeing here is
actually composed of many different patches.
8
00:00:43,393 --> 00:00:47,113
We can address them much like we address
the turtles
9
00:00:47,113 --> 00:00:50,610
by saying 'ask patches' to do something.
10
00:00:50,610 --> 00:00:55,303
The patches, much like the turtles,
have a color,
11
00:00:55,303 --> 00:00:59,042
So we can set their pcolor which is their
patch color -
12
00:00:59,042 --> 00:01:03,721
we'll explain in a second why that's
different from color for the turtles -
13
00:01:03,721 --> 00:01:08,625
we can set their pcolor to be a particular
value.
14
00:01:08,625 --> 00:01:16,375
So one thing we could do is set their pcolor
to depend on their x and y coordinates
15
00:01:16,375 --> 00:01:21,003
and for the patches that's pxcor and
pycor.
16
00:01:21,003 --> 00:01:24,739
So in this case I'm asking the patches to
set their pcolor
17
00:01:24,739 --> 00:01:28,239
to be pxcor times pycor:
'ask patches [ set pcolor pxcor * pycor ]'
18
00:01:28,239 --> 00:01:33,329
and when I hit 'enter' you'll now see that
the patches are there fairly obviously,
19
00:01:33,329 --> 00:01:37,159
and that there are a number of different
ones in the space.
20
00:01:37,159 --> 00:01:43,101
In fact, if you remember back to the first
subunit of this unit,
21
00:01:43,101 --> 00:01:46,778
we discussed how you can modify the
settings of the world...
22
00:01:46,778 --> 00:01:51,212
in order to make more or less patches
within the world.
23
00:01:51,212 --> 00:01:56,610
So we can use the patches in much the same
way we use turtles,
24
00:01:56,610 --> 00:02:00,705
they have properties, we can look at them,
we can manipulate those properties.
25
00:02:00,705 --> 00:02:08,076
We can inspect one of the patches and then
we can see what properties it has.
26
00:02:08,076 --> 00:02:13,316
a pxcor, pycor, pcolor, plabel and a
plabel-color.
27
00:02:13,316 --> 00:02:22,246
What's interesting about patches in terms
of their interaction with turtles...
28
00:02:22,246 --> 00:02:31,115
is that turtles have direct access to all
the different patch variables.
29
00:02:31,115 --> 00:02:39,139
So, for instance, we can create a bunch of
turtles now, 'crt 100',
30
00:02:39,139 --> 00:02:49,284
and we can ask those turtles to go to a
random xcor and ycor:
31
00:02:49,284 --> 00:02:51,950
'ask turtles [ setxy random-xcor random-ycor ]'
32
00:02:51,950 --> 00:02:54,409
so now they're scattered across the
screen,
33
00:02:54,409 --> 00:02:58,953
and now we can have the turtles set the
patch variables,
34
00:02:58,953 --> 00:03:04,509
so we can ask the turtles to set the patch
color to their own color:
35
00:03:04,509 --> 00:03:06,844
'ask turtles [ set pcolor color ]'
36
00:03:06,844 --> 00:03:14,544
The reason why this works is because every
turtle can only ever be on one patch at a time
37
00:03:14,544 --> 00:03:17,411
so it only has access to one set of patch
variables.
38
00:03:17,411 --> 00:03:22,185
This is why the color variable for the
turtle is named something different
39
00:03:22,185 --> 00:03:25,301
from the patch color variable.
40
00:03:25,301 --> 00:03:30,234
By the way, in addition to random-xcor
and random-ycor
41
00:03:30,234 --> 00:03:34,394
there is also random-pxcor and
random-pycor
42
00:03:34,394 --> 00:03:37,102
which will give you random patch
coordinates
43
00:03:37,102 --> 00:03:40,121
and those are at the centre of the
patches.
44
00:03:40,121 --> 00:03:46,586
We can also use patches in a different
way -
45
00:03:46,586 --> 00:03:54,635
so let's set all the patches back to black
'ask patches [ set pcolor black ]'.
46
00:03:54,635 --> 00:04:05,948
We could, for instance, have turtles
find their NetLogo patches
47
00:04:05,948 --> 00:04:13,826
so we could ask the turtles to facexy -
which means face a particular x,y coordinate
48
00:04:13,826 --> 00:04:17,613
and we're going to have them face the
coordinates of their current patch:
49
00:04:17,613 --> 00:04:19,590
'ask turtles [ facexy pxcor pycor ]'
50
00:04:19,590 --> 00:04:23,567
so this is aiming them at the centre of
the patch they happen to be standing on.
51
00:04:23,567 --> 00:04:26,683
So in this way we can have turtles and
patches interact.
52
00:04:26,683 --> 00:04:29,980
They can work together in interesting
ways
53
00:04:29,980 --> 00:04:35,518
and you can use patches to manipulate the
actions of your turtles.
54
00:04:35,518 --> 00:04:43,044
In addition to patches there is one last
agent type that exists -
55
00:04:43,044 --> 00:04:47,038
we won't spend a lot of time talking this
now but I want you to know about it.
56
00:04:47,038 --> 00:04:49,304
This is the link agent type.
57
00:04:49,304 --> 00:04:57,050
The link agent type allows us to move beyond
having physical attributes of the turtles...
58
00:04:57,050 --> 00:05:00,105
to having network based attributes.
59
00:05:00,105 --> 00:05:11,739
We can ask the turtles to create a link
with one of the other turtles:
60
00:05:11,739 --> 00:05:14,782
'ask turtles [ create-link-with one-of other turtles ]'
61
00:05:14,782 --> 00:05:17,300
and what you now see is they've all
created links.
62
00:05:17,300 --> 00:05:20,221
That command was a little complex, so let
me dissect it a bit,
63
00:05:20,221 --> 00:05:25,365
so we ask each turtle to create-link-with,
to create a singular link with...
64
00:05:25,365 --> 00:05:29,895
one-of, which basically takes a random
element of a set...
65
00:05:29,895 --> 00:05:36,767
other turtles, which takes the set of all turtles
and removes the turtle that's currently calling it
66
00:05:36,767 --> 00:05:39,295
and just looks at the other turtles, so
it's saying...
67
00:05:39,295 --> 00:05:41,550
'create a link with one of the other
turtles'.
68
00:05:41,550 --> 00:05:46,816
A nice thing about NetLogo is that often
the English interpretation of the phrase...
69
00:05:46,816 --> 00:05:50,439
is actually the way the model will run.
70
00:05:50,439 --> 00:05:52,401
Now here I'm creating an undirected link.
71
00:05:52,401 --> 00:05:57,321
But you could create a directed link, that
command is 'create-link-to' another turtle
72
00:05:57,321 --> 00:06:00,131
or 'create-link-from' one of the other
turtles.
73
00:06:00,131 --> 00:06:02,562
And I can create multiple links at the
same time,
74
00:06:02,562 --> 00:06:08,416
so I can 'create-links-with' n-of the
other turtles, rather than 'create-link-with'.
75
00:06:08,416 --> 00:06:13,930
One last comment is that links are fully
fledged agents,
76
00:06:13,930 --> 00:06:17,513
just like turtles and patches,
77
00:06:17,513 --> 00:06:21,177
so I can look at the properties of links.
78
00:06:21,177 --> 00:06:25,676
One of the properties is the ends, so we
can see which turtles they connect,
79
00:06:25,676 --> 00:06:28,383
the color, the label, etc.
80
00:06:28,383 --> 00:06:32,541
So those are the three basic agents in
NetLogo,
81
00:06:32,541 --> 00:06:36,413
turtles being the most basic and most
common type you're going to work with,
82
00:06:36,413 --> 00:06:41,566
but patches and links are very
important
83
00:06:41,566 --> 00:06:46,484
and have many of the same properties and
abilities as turtles.