Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← abm 2 3 properties

Get Embed Code
1 Language


Showing Revision 3 created 04/25/2017 by mrmrjones.

  1. So now we've got our basic model, it's up
    and running, we have some control over it,
  2. but what if we discover we really want
    something within the model...
  3. that every single turtle and patch and
    link could access.
  4. We can add what are called global
    or global variables.
  5. We do this by going up before any of the
    procedures are defined,
  6. and we write the word 'globals', and then
    we can add the variable in there,
  7. so let's say there's a value which
    describes the wealth of the system...
  8. we can add a global value called wealth:
    'globals [ wealth ]'
  9. This isn't the wealth of any particular
  10. it's how wealthy the society is.
  11. And we go into the 'setup' procedure and
    we can say 'set wealth 100'.
  12. The observer can modify this value, but
    the turtles can too.
  13. So, for instance, at each of the time
  14. we can have each turtle add some wealth.
  15. Let's say they are working in their jobs,
    doing a good job,
  16. and they add a little wealth to the system
    at each time step:
  17. 'set wealth wealth + 1'
  18. That adds a global variable to the
    overall system.
  19. But we can also add a variable for each of
    the individual turtles.
  20. We can say that the turtles own a
    variable or property called 'income':
  21. 'turtles-own [ income ]' - which is the
    amount of income they currently get.
  22. And we can set that income to be, say,
    a random value in the initialisation step:
  23. 'set income random 100' - some turtles
    are born with more income than others.
  24. Then we can have the 'wealth' be a sum of
    the wealth plus the income of that turtle.
  25. Once we've done this, we have properties
    defined at both the turtle level...
  26. and the global level. We can have as many
    as we want here,
  27. so for instance we could have 'fuzziness',
    'job', things along those lines.
  28. Once we've done all that they are added
    into the model,
  29. so if we hit 'setup' and 'go' now, if we
    look at one of the turtles,
  30. you'll see now that they have an 'income'.
    They also have a 'fuzziness' and 'job'...
  31. but these aren't set to anything because
    we didn't set them in the model,
  32. but income is set to a value, and if we
    look at another turtle -
  33. using the turtle monitors as these
    inspectors are called -
  34. you can see that that turtle has a
    different value.
  35. By the way, you can also inspect turtles
    from the command line,
  36. you can type 'inspect one-of turtles',
  37. and this will just pull a random turtle up
    for you to take a look at in the model.
  38. The global 'wealth' is also there...
  39. We can use the 'print' command, which we
    haven't discussed yet,
  40. we can print a variable:
    'print wealth'
  41. in this case, after a certain amount of
    time the wealth is 442,180
  42. So far, we haven't talked about what that
    time is.
  43. You'll notice that there's this thing
    called 'ticks' at the top of the model...
  44. but it's not set to anything right now.
  45. What we often do in a model is we have a
    tick to go by.
  46. The way a tick goes by is that we tell
    NetLogo a tick has gone by...
  47. and that allows it to iterate certain
    functions within the model.
  48. So we can say 'reset-ticks' at the
    beginning of the model
  49. to tell it to start over again.
  50. And then at the end of every 'go' step we
    say 'tick' to indicate a step has gone by.
  51. Now if we go back to our model and 'setup'
    and 'go'...
  52. you'll see the tick counter increments.
  53. And if we look at our wealth, we now know
    this is 270,604 over 52 ticks.
  54. We'll talk as we go forward about how you
    can use that to plot things
  55. and look at interesting relationships.
  56. Ticks are also used for building the plots
    within NetLogo,
  57. and other aspects of the model, so they're
    very important.
  58. Finally, we talked a little about 'repeat'
    early on...
  59. which is one of the control structures
    within NetLogo,
  60. you can also ask it to do things on a
    conditional basis.
  61. So let's say that we only want wealthy
    people to be counted in the overall wealth
  62. we can say, if the income is greater than
    50, then set wealth to wealth plus income:
  63. 'if income > 50 [
    set wealth wealth + income]'

  64. ...otherwise, don't. And this adds a
    conditional to what's going on.
  65. Just to make sure that this works, let's
    set the wealthy people's color to red,
  66. so we can see that they're actually
    executing this command correctly.
  67. So, sure enough, when we hit 'go', now
    we see that the wealthy people are red,
  68. if we inspect a red turtle, it will have
    an income over 50,
  69. and it does, it has an income of 64.
  70. This allows us some control over the
  71. So I just wanted to give the idea that you
    can write very complex structures,
  72. you can add properties to the NetLogo
  73. you can build control structures that
    allow you to make conditional decisions
  74. and in the next series of lectures
  75. we're going to talk about how to build our
    first model...
  76. now that we have the basic ideas and some
    of the commands. Thanks.