1
00:00:08,589 --> 00:00:14,994
So now we've got our basic model, it's up
and running, we have some control over it,
2
00:00:14,994 --> 00:00:19,354
but what if we discover we really want
something within the model...
3
00:00:19,354 --> 00:00:24,592
that every single turtle and patch and
link could access.
4
00:00:24,592 --> 00:00:30,974
We can add what are called global
properties or global variables.
5
00:00:30,974 --> 00:00:35,121
We do this by going up before any of the
procedures are defined,
6
00:00:35,121 --> 00:00:39,363
and we write the word 'globals', and then
we can add the variable in there,
7
00:00:39,363 --> 00:00:45,014
so let's say there's a value which
describes the wealth of the system...
8
00:00:45,014 --> 00:00:48,207
we can add a global value called wealth:
'globals [ wealth ]'
9
00:00:48,207 --> 00:00:50,610
This isn't the wealth of any particular
individual,
10
00:00:50,610 --> 00:00:53,262
it's how wealthy the society is.
11
00:00:53,262 --> 00:01:00,795
And we go into the 'setup' procedure and
we can say 'set wealth 100'.
12
00:01:00,795 --> 00:01:05,919
The observer can modify this value, but
the turtles can too.
13
00:01:05,919 --> 00:01:08,832
So, for instance, at each of the time
steps
14
00:01:08,832 --> 00:01:12,571
we can have each turtle add some wealth.
15
00:01:12,571 --> 00:01:15,341
Let's say they are working in their jobs,
doing a good job,
16
00:01:15,341 --> 00:01:18,328
and they add a little wealth to the system
at each time step:
17
00:01:18,328 --> 00:01:19,790
'set wealth wealth + 1'
18
00:01:19,790 --> 00:01:23,525
That adds a global variable to the
overall system.
19
00:01:23,525 --> 00:01:30,470
But we can also add a variable for each of
the individual turtles.
20
00:01:30,470 --> 00:01:35,772
We can say that the turtles own a
variable or property called 'income':
21
00:01:35,772 --> 00:01:40,662
'turtles-own [ income ]' - which is the
amount of income they currently get.
22
00:01:40,662 --> 00:01:47,743
And we can set that income to be, say,
a random value in the initialisation step:
23
00:01:47,743 --> 00:01:52,603
'set income random 100' - some turtles
are born with more income than others.
24
00:01:52,603 --> 00:02:02,067
Then we can have the 'wealth' be a sum of
the wealth plus the income of that turtle.
25
00:02:02,067 --> 00:02:07,607
Once we've done this, we have properties
defined at both the turtle level...
26
00:02:07,607 --> 00:02:10,918
and the global level. We can have as many
as we want here,
27
00:02:10,918 --> 00:02:18,958
so for instance we could have 'fuzziness',
'job', things along those lines.
28
00:02:18,958 --> 00:02:24,470
Once we've done all that they are added
into the model,
29
00:02:24,470 --> 00:02:28,956
so if we hit 'setup' and 'go' now, if we
look at one of the turtles,
30
00:02:28,956 --> 00:02:33,696
you'll see now that they have an 'income'.
They also have a 'fuzziness' and 'job'...
31
00:02:33,696 --> 00:02:37,171
but these aren't set to anything because
we didn't set them in the model,
32
00:02:37,171 --> 00:02:40,302
but income is set to a value, and if we
look at another turtle -
33
00:02:40,302 --> 00:02:46,034
using the turtle monitors as these
inspectors are called -
34
00:02:46,034 --> 00:02:49,231
you can see that that turtle has a
different value.
35
00:02:49,231 --> 00:02:53,345
By the way, you can also inspect turtles
from the command line,
36
00:02:53,345 --> 00:02:56,520
you can type 'inspect one-of turtles',
37
00:02:56,520 --> 00:03:07,314
and this will just pull a random turtle up
for you to take a look at in the model.
38
00:03:07,314 --> 00:03:13,057
The global 'wealth' is also there...
39
00:03:13,057 --> 00:03:16,361
We can use the 'print' command, which we
haven't discussed yet,
40
00:03:16,361 --> 00:03:20,186
we can print a variable:
'print wealth'
41
00:03:20,186 --> 00:03:26,013
in this case, after a certain amount of
time the wealth is 442,180
42
00:03:26,013 --> 00:03:30,350
So far, we haven't talked about what that
time is.
43
00:03:30,350 --> 00:03:34,139
You'll notice that there's this thing
called 'ticks' at the top of the model...
44
00:03:34,139 --> 00:03:36,945
but it's not set to anything right now.
45
00:03:36,945 --> 00:03:41,890
What we often do in a model is we have a
tick to go by.
46
00:03:41,890 --> 00:03:47,777
The way a tick goes by is that we tell
NetLogo a tick has gone by...
47
00:03:47,777 --> 00:03:51,951
and that allows it to iterate certain
functions within the model.
48
00:03:51,951 --> 00:03:56,638
So we can say 'reset-ticks' at the
beginning of the model
49
00:03:56,638 --> 00:03:58,670
to tell it to start over again.
50
00:03:58,670 --> 00:04:04,470
And then at the end of every 'go' step we
say 'tick' to indicate a step has gone by.
51
00:04:04,470 --> 00:04:07,951
Now if we go back to our model and 'setup'
and 'go'...
52
00:04:07,951 --> 00:04:10,624
you'll see the tick counter increments.
53
00:04:10,624 --> 00:04:17,141
And if we look at our wealth, we now know
this is 270,604 over 52 ticks.
54
00:04:17,141 --> 00:04:21,023
We'll talk as we go forward about how you
can use that to plot things
55
00:04:21,023 --> 00:04:23,746
and look at interesting relationships.
56
00:04:23,746 --> 00:04:27,377
Ticks are also used for building the plots
within NetLogo,
57
00:04:27,377 --> 00:04:31,069
and other aspects of the model, so they're
very important.
58
00:04:31,069 --> 00:04:37,258
Finally, we talked a little about 'repeat'
early on...
59
00:04:37,258 --> 00:04:40,123
which is one of the control structures
within NetLogo,
60
00:04:40,123 --> 00:04:46,611
you can also ask it to do things on a
conditional basis.
61
00:04:46,611 --> 00:04:52,715
So let's say that we only want wealthy
people to be counted in the overall wealth
62
00:04:52,715 --> 00:04:58,506
we can say, if the income is greater than
50, then set wealth to wealth plus income:
63
00:04:58,506 --> 00:05:01,307
'if income > 50 [
set wealth wealth + income]'
64
00:05:01,307 --> 00:05:06,149
...otherwise, don't. And this adds a
conditional to what's going on.
65
00:05:06,149 --> 00:05:12,308
Just to make sure that this works, let's
set the wealthy people's color to red,
66
00:05:12,308 --> 00:05:16,656
so we can see that they're actually
executing this command correctly.
67
00:05:16,656 --> 00:05:21,169
So, sure enough, when we hit 'go', now
we see that the wealthy people are red,
68
00:05:21,169 --> 00:05:26,077
if we inspect a red turtle, it will have
an income over 50,
69
00:05:26,077 --> 00:05:28,483
and it does, it has an income of 64.
70
00:05:28,483 --> 00:05:32,207
This allows us some control over the
system.
71
00:05:32,207 --> 00:05:36,211
So I just wanted to give the idea that you
can write very complex structures,
72
00:05:36,211 --> 00:05:38,428
you can add properties to the NetLogo
model,
73
00:05:38,428 --> 00:05:42,749
you can build control structures that
allow you to make conditional decisions
74
00:05:42,749 --> 00:05:45,176
and in the next series of lectures
75
00:05:45,176 --> 00:05:48,793
we're going to talk about how to build our
first model...
76
00:05:48,793 --> 00:05:52,728
now that we have the basic ideas and some
of the commands. Thanks.