So now we've got our basic model, it's up
and running, we have some control over it,
but what if we discover we really want
something within the model...
that every single turtle and patch and
link could access.
We can add what are called global
properties or global variables.
We do this by going up before any of the
procedures are defined,
and we write the word 'globals', and then
we can add the variable in there,
so let's say there's a value which
describes the wealth of the system...
we can add a global value called wealth:
'globals [ wealth ]'
This isn't the wealth of any particular
individual,
it's how wealthy the society is.
And we go into the 'setup' procedure and
we can say 'set wealth 100'.
The observer can modify this value, but
the turtles can too.
So, for instance, at each of the time
steps
we can have each turtle add some wealth.
Let's say they are working in their jobs,
doing a good job,
and they add a little wealth to the system
at each time step:
'set wealth wealth + 1'
That adds a global variable to the
overall system.
But we can also add a variable for each of
the individual turtles.
We can say that the turtles own a
variable or property called 'income':
'turtles-own [ income ]' - which is the
amount of income they currently get.
And we can set that income to be, say,
a random value in the initialisation step:
'set income random 100' - some turtles
are born with more income than others.
Then we can have the 'wealth' be a sum of
the wealth plus the income of that turtle.
Once we've done this, we have properties
defined at both the turtle level...
and the global level. We can have as many
as we want here,
so for instance we could have 'fuzziness',
'job', things along those lines.
Once we've done all that they are added
into the model,
so if we hit 'setup' and 'go' now, if we
look at one of the turtles,
you'll see now that they have an 'income'.
They also have a 'fuzziness' and 'job'...
but these aren't set to anything because
we didn't set them in the model,
but income is set to a value, and if we
look at another turtle -
using the turtle monitors as these
inspectors are called -
you can see that that turtle has a
different value.
By the way, you can also inspect turtles
from the command line,
you can type 'inspect one-of turtles',
and this will just pull a random turtle up
for you to take a look at in the model.
The global 'wealth' is also there...
We can use the 'print' command, which we
haven't discussed yet,
we can print a variable:
'print wealth'
in this case, after a certain amount of
time the wealth is 442,180
So far, we haven't talked about what that
time is.
You'll notice that there's this thing
called 'ticks' at the top of the model...
but it's not set to anything right now.
What we often do in a model is we have a
tick to go by.
The way a tick goes by is that we tell
NetLogo a tick has gone by...
and that allows it to iterate certain
functions within the model.
So we can say 'reset-ticks' at the
beginning of the model
to tell it to start over again.
And then at the end of every 'go' step we
say 'tick' to indicate a step has gone by.
Now if we go back to our model and 'setup'
and 'go'...
you'll see the tick counter increments.
And if we look at our wealth, we now know
this is 270,604 over 52 ticks.
We'll talk as we go forward about how you
can use that to plot things
and look at interesting relationships.
Ticks are also used for building the plots
within NetLogo,
and other aspects of the model, so they're
very important.
Finally, we talked a little about 'repeat'
early on...
which is one of the control structures
within NetLogo,
you can also ask it to do things on a
conditional basis.
So let's say that we only want wealthy
people to be counted in the overall wealth
we can say, if the income is greater than
50, then set wealth to wealth plus income:
'if income > 50 [
set wealth wealth + income]'
...otherwise, don't. And this adds a
conditional to what's going on.
Just to make sure that this works, let's
set the wealthy people's color to red,
so we can see that they're actually
executing this command correctly.
So, sure enough, when we hit 'go', now
we see that the wealthy people are red,
if we inspect a red turtle, it will have
an income over 50,
and it does, it has an income of 64.
This allows us some control over the
system.
So I just wanted to give the idea that you
can write very complex structures,
you can add properties to the NetLogo
model,
you can build control structures that
allow you to make conditional decisions
and in the next series of lectures
we're going to talk about how to build our
first model...
now that we have the basic ideas and some
of the commands. Thanks.