NetLogo Tutorial Overview
From Backspaces Wiki
| NetLogo Tutorial |
Well, we've down loaded NetLogo and explored its built-in Model Library. We've also seen a bit of the structure of NetLogo: its three panels (Interface, Information, Procedures). We did this by looking in some detail at the Diffusion Graphics sample.
Here we're going to philosophize a bit about just what a model is and what a an ABM tool like NetLogo provides. What are its parts, and how do they relate to each other. The module ends with a short discussion on access to the NetLogo documentation.
Contents |
Space, Time, and Interaction
The "Agents" in Agent Based Modeling are simply entities with a collection of attributes like location, color, velocity, hunger and so on. They correspond to Objects in languages like Java. What makes ABM unique is that the agents live in a "world" that is comprised of Space, Time, and Interaction (or Behavior).
- Space:
- A Grid or Network where the agents live.
- Time:
- The system evolves by taking steps.
- Interaction:
- The agents interact with each other on the space over time. They have behavior.
This seems pretty simple, but we are often surprised by what emerges over time as the model runs. And it's impressive just how many explorations can be done with this simple model. Here's a quote from Dr Lindsay Hood, Institute for Molecular Bioscience:
“The last 30 years or so has seen the advent of computational modeling as a third leg in science, complementing traditional experiment and theory.”
You can browse the NetLogo Documentation as we discuss these in more detail. Use the left hand sidebar on the documentation page to browse different topics.
Space
NetLogo provides a "World" in which the agents evolve. Two primary types of "Views" of this world are used: Patches and Networks. This is the Space part of the model. Agents wander around in the space, interacting with each other.
- Patches are a grid of regularly spaced squares and the more traditional Space component for models. They create an X,Y coordinate system making it easy to traverse the space. The lower left image below shows the default NetLogo patch space, with each patch randomly colored, and the X=0, Y=0 patches colored black.
- Networks are formally Graphs, a set of nodes and their connecting edges. Netlogo calls edges links, while any agent can be a node. (Netlogo has a means for different kinds of agents, called breeds. You will often define a "node" breed if you have a network oriented model.) The lower right image below is a trivial Network created by set of agents, with circular shape, with a random set of links.
The NetLogo View Documentation explains how the view is adjusted via the settings pane. To find out more about Networks, view the Netlogo Links discussion. Note especially the layout help NetLogo provides, giving you several automatic network formats.
Time
ABM's evolve over time. They do so by having each agent taking a "step" during each advance of time (called a "tick" in NetLogo) as the model runs. We are generally looking for macroscopic properties, or emergence properties, of the whole set of agents which are result in their individual steps.
Lets look at a classic, a Flocking model. Click on the Files > Models Library menu (or use the cmd/ctl M keyboard shortcut). Find the Flocking model:
Models Library > Sample Models > Biology > Flocking
The Time aspect of the model are the setup and go buttons. When the model first starts, the world View is blank. Click setup to initialize the world. You'll see something like the View on the left below. (I've made the agents larger for emphasis). Note the "ticks: 0" printout in the top left of the View's header. Also, the initial setup randomly distributes the position and heading (direction) of each agent.
Now click the go button. The model will ask each agent to take a step. (We'll see more about the step details in the next section.) The model repeats this cycle, incrementing the tick counter each time. In the View on the right below, you see the result after 509 ticks.
Interaction
So how did the flock evolve in the preceding section? The answer is the interaction between the agents, the core magic of ABM. Our example is of "Boids", the simulation of the interaction of flocking birds, done for animation for the movie industry.
In 1986, Craig Reynolds discovered that realistic simulation of flocking of birds could be achieved with three very simple steering rules: Separation, Alignment, and Cohesion. The agents, called boids, were very simply modeled by having a vision of a certain distance and breadth, and a velocity and heading (see diagram to the right). Each agent was only aware of part of the overall flock, yet a coordinated flocking behavior emerged from simple local interaction rules.
| Separation: steer to avoid
crowding local flockmates | Alignment: steer towards the
average heading of local flockmates | Cohesion: steer to move toward the
average position of local flockmates |
Here is a somewhat simplified beginning of the Model Library's flocking program, along with its buttons and sliders.
- The turtles-own section defines the variables of each boid: the flockmates set of neighboring boids, and the nearest one of these.
- The setup procedure (called when you click the setup button) simply creates the number of boids of the "population" slider and places them randomly.
- The go procedure (repeatedly called when you click the go button) asks each boid to set its heading according to the separate, align and cohere rules, then moves each forward one patch width, advancing the tick count.
The details are left out (i.e. what is the align procedure etc) but we will revisit this in detail later as a programming exercise.
Homework: NetLogo Documentation
The NetLogo documentation, along with the Models Library forms a very rich learning environment. You are encouraged to read through each of the sections in the documentation sidebar.
These are the essential first readings:
- Party & Three Tutorials: Read through these first. They briefly touch all the high points of the NetLogo UI and language.
- Interface Guide: This presents all aspects of the NetLogo UI in detail.
- Programming Guide: This covers all the core language semantics and is an essential reference.
- NetLogo Dictionary: This covers every NetLogo command. You will use this constantly while writing programs. It is nicely organized by category of the command: turtle, patch, lists and so on. Try it: browse to it, drilling down into specific commands from the Categories: area in the top frame.
You have your own local copy of the entire NetLogo documentation. You access it by the Help menu. The Dictionary is so important that NetLogo's help Menu also has a Lookup feature: select a NetLogo command, "Help > Lookup In Dictionary". NetLogo pops up a web page with the Dictionary's entry for that command. Sweet!
As you start using NetLogo, you'll tend to have both the NetLogo application, and a browser opened to the documentation, side by side as your working environment.
Whenever new models are shown, ask yourself: what are the three components, Space, Time, Interaction in the model.







