Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

641 lines (611 sloc) 27.082 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>
NetLogo User Manual: Tutorial #1: Models
</title>
<link rel="stylesheet" href="netlogo.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<h1>
Tutorial #1: Models
</h1>
<div class="version">
NetLogo User Manual&nbsp;&nbsp;&nbsp;
</div>
<p>
If you read the <a href="sample.html">Sample Model: Party</a>
section, you got a brief introduction to what it's like to
explore a NetLogo model. This section will go into more depth about
the features that are available while you're exploring the models
in the Models Library.
<p>
Throughout all of the tutorials, we'll be asking you to make
predictions about what the effects of making changes to the models
will be. Keep in mind that the effects are often surprising. We think
these surprises are exciting and provide excellent opportunities for
learning.
<p>
You may want to print out the tutorials to make them easier to refer
to while you're using NetLogo.
<h2>
Sample Model: Wolf Sheep Predation
</h2>
<p>
We'll open one of the Sample Models and explore it in detail.
Let's try a biology model: Wolf Sheep Predation, a predator-prey
population model.
<blockquote>
<ul>
<li>Open the Models Library from the File menu.
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image017.png">
<li>Choose &quot;Wolf Sheep Predation&quot; from the Biology
section and press &quot;Open&quot;.
</ul>
</blockquote>
<p>
The Interface tab will fill up with lots of buttons, switches,
sliders and monitors. These interface elements allow you to interact
with the model. Buttons are blue; they set up, start, and stop the
model. Sliders and switches are green; they alter model settings.
Monitors and plots are beige; they display data.
<p>
If you'd like to make the window larger so that everything is
easier to see, you can use the Zoom menu.
<p>
When you first open the model, you will notice that the
&quot;view&quot; (the graphical display of the agents in the model)
is empty (all black). To begin the model, you will first need to set
it up.
<blockquote>
<ul>
<li>Press the &quot;setup&quot; button.
</ul>
<p class="question">
What do you see appear in the view?
<ul>
<li>Press the &quot;go&quot; button to start the simulation.
</ul>
<p class="question">
As the model is running, what is happening to the wolf and sheep
populations?
<ul>
<li>Press the &quot;go&quot; button to stop the model.
</ul>
</blockquote>
<h2>
Controlling the Model: Buttons
</h2>
<p>
When a button is pressed, the model responds with an action. A button
can be a &quot;once&quot; button, or a &quot;forever&quot; button.
You can tell the difference between these two types of buttons by a
symbol on the face of the button. Forever buttons have two arrows in
the bottom right corners, like this:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image002.gif">
<p>
Once buttons don't have the arrows, like this:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/setup.gif">
<p>
Once buttons do one action and then stop. When the action is
finished, the button pops back up.
<p>
Forever buttons do an action over and over again. When you want the
action to stop, press the button again. It will finish the current
action, then pop back up.
<p>
Most models, including Wolf Sheep Predation, have a once button
called &quot;setup&quot; and a forever button called &quot;go&quot;.
Many models also have a once button called &quot;go once&quot; or
&quot;step once&quot; which is like &quot;go&quot; except that it
advances the model by one tick (time step) instead of over and over.
Using a once button like this lets you watch the progress of the
model more closely.
<p>
Stopping a forever button is the normal way to pause or stop a model.
After pausing you can make it resume by pressing the button again.
(You can also stop a model with the &quot;Halt&quot; item on the
Tools menu, but you should only do this if the model is stuck for
some reason. Using &quot;Halt&quot; may interrupt the model in the
middle of an action, and as the result the model could get confused.)
<blockquote>
<ul>
<li>If you like, experiment with the &quot;setup&quot; and
&quot;go&quot; buttons in the Wolf Sheep Predation model.
</ul>
<p class="question">
Do you ever get different results if you run the model several
times with the same settings?
</blockquote>
<h2>
Controlling speed: Speed Slider
</h2>
<p>
The speed slider allows you to control the speed of a model, that is,
the speed at which turtles move, patches change color, and so on.
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/speed-slider.gif">
<p>
When you move the slider to the left the model slows down so there
are longer pauses between each tick (time step). That makes it easier
to see what is happening. You might even slow the model down so far
as to see exactly what a single turtle is doing.
<p>
When you move the speed slider to the right the model speeds up.
NetLogo will start skipping frames, that is, it won't update the
view at the end of every tick, only some ticks. Updating takes time,
so fewer view updates means the model progresses faster.
<p>
Note that if you push the speed slider well to the right, the view
may update so infrequently that the model appears to have slowed
down. It hasn't, as you can see by watching the tick counter race
ahead. Only the frequency of view updates has lessened.
<h2>
Adjusting Settings: Sliders and Switches
</h2>
<p>
A model's settings let you explore different scenarios or
hypotheses. Altering the settings and then running the model to see
how it reacts can give you a deeper understanding of the phenomena
being modeled.
<p>
Switches and sliders give you access to a model's settings. Here
are the switches and sliders in Wolf Sheep Predation:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image010.gif">
<p>
Let's experiment with their effect on the behavior of the model.
<blockquote>
<ul>
<li>Open Wolf Sheep Predation if it's not open already.
<li>Press &quot;setup&quot; and &quot;go&quot; and let the model
run for about 100 ticks. (The tick count is shown above the view.)
<li>Stop the model by pressing the &quot;go&quot; button.
</ul>
<p class="question">
What happened to the sheep over time?
<p>
Let's take a look and see what would happen to the sheep if we
change a setting.
<ul>
<li>Turn the &quot;grass?&quot; switch on.
<li>Press &quot;setup&quot; and &quot;go&quot; and let the model
run for a similar amount of time as before.
</ul>
<p class="question">
What did the switch do? Was the outcome the same as your previous
run?
</blockquote>
<p>
Turning the &quot;grass?&quot; switch on affected the outcome of the
model. With the switch off, the amount of grass available always
stayed the same. This is not a realistic look at the predator-prey
relationship; so by setting and turning on a grass regrowth rate, we
were able to model all three factors: sheep, wolf and grass
populations.
<p>
Another type of setting is called a slider.
<p>
Besides switches, a model may also have sliders. While a switch has
only two values, on and off, a slider has a whole range of numeric
values. For example, the &quot;initial-number-sheep&quot; slider has
a minimum value of 0 and a maximum value of 250. The model could run
with 0 sheep or it could run with 250 sheep, or anywhere in between.
Try this out and see what happens. As you move the marker from the
minimum to the maximum value, the number on the right side of the
slider changes; this is the number the slider is currently set to.
<blockquote>
<p>
Let's investigate Wolf Sheep Predation's sliders.
<ul>
<li>Change from the Interface to the Info tab to learn what each of
this models' sliders represents.
</ul>
</blockquote>
<p>
The Info tab offers guidance and insight into the model. Within this
tab you will find an explanation of the model, suggestions on things
to try, and other information. You may want to read the Info tab
before running a model, or you might want to just start
experimenting, then look at the Info tab later.
<blockquote>
<p class="question">
What would happen to the sheep population if there were more sheep
and less wolves initially?
<ul>
<li>Turn the &quot;grass?&quot; switch off.
<li>Set the &quot;initial-number-sheep&quot; slider to 100.
<li>Set the &quot;initial-number-wolves&quot; slider to 20.
<!--</UL>
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image011.gif">
<UL>
-->
<li>Press &quot;setup&quot; and then &quot;go&quot;.
<li>Let the model run for about 100 ticks.
</ul>
<p>
Try running the model several times with these settings.
<p class="question">
What happened to the sheep population?
<p class="question">
Did this outcome surprise you? What other sliders or switches can
be adjusted to help out the sheep population?
<ul>
<li>Set &quot;initial-number-sheep&quot; to 80 and
&quot;initial-number-wolves&quot; to 50. (This is close to how they
were when you first opened the model.)
<li>Set &quot;sheep-reproduce&quot; to 10.0%.
<li>Press &quot;setup&quot; and then &quot;go&quot;.
<li>Let the model run for about 100 time ticks.
</ul>
<p class="question">
What happened to the wolves in this run?
</blockquote>
<p>
When you open a model, all the sliders and switches are on a default
setting. If you open a new model or exit the program, your changed
settings will not be saved, unless you choose to save them.
<p>
(Note: in addition to sliders and switches, some models have choosers
and input boxes. The Wolf Sheep Predation doesn't have any of
these, though.)
<h2>
Gathering Information: Plots and Monitors
</h2>
<p>
The view lets you see what's going on in a model. NetLogo also
provides has other ways of giving you information about model run,
such as plots and monitors.
<h3>
Plots
</h3>
<p>
The plot in Wolf Sheep Predation contains three lines: sheep, wolves,
and grass / 4. (The grass count is divided by four so it doesn't
make the plot too tall.) The lines show what's happening in the
model over time. The plot legend shows what each line indicates. In
this case, it's the population counts. <!--
<LI>Using any settings you would like and press
"setup" and "go".
<LI>Let the model run for 100 time-ticks.
<LI>At the 50 tick mark, move the "sheep-metabolism"
slider to the far right.
<LI>At the 75 tick mark, move the "sheep-metabolism"
slider back to its original value.
<p class="question">What happened in the plot?
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image012.gif">
-->
<p>
When a plot gets close to becoming filled up, the horizontal axis is
compressed and all of the data from before gets squeezed into a
smaller space. In this way, more room is made for the plot to grow.
<p>
If you want to save the data from a plot to view or analyze it in
another application, use the &quot;Export Plot&quot; item on the File
menu. It saves the plot data in a format that can by read back by
spreadsheet and database programs such as Excel. You can also export
a plot by right-clicking it and choosing &quot;Export...&quot; from
the popup menu. <!--
<u>Editing the Plot Window:</u>
<p>Editing the Plot Window is very straightforward. It is just like
editing the View.
<P>
<LI>Highlight the Plot Window and press the "edit"
button on the toolbar.
<p class=MsoBodyTextIndent style='margin-left:.75in'><span style='font-family:
Times'>&nbsp;
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image013.gif">
<p>Within the Edit Window is a place where you can change the name of the
plot, the x and y-axis labels and adjust the minimum and maximum values for
each axis. If the autoplot function is turned on, it will automatically adjust
the x and y-axis as the model generates a number outside of the minimum and
maximum values.
<P>Turn off the "Autoplot?" and press "OK".
<P>Press "setup" and "go" and watch the Plot Window.
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image014.gif">
<p>If the autoplot is off then the plot will not readjust itself
when the data is outside of the maximum and minimum values. For example, the
blue line on the plot above jumps off of the plot and then starts to come
back down towards the end of the run. As a researcher, it would be difficult to
discuss what type of data happened in between those points. The autoplot
function would adjust the y-axis maximum to show those hidden values. The
autoplot function default setting is on.
<p>At the bottom portion of the Edit Window are the formatting functions
for the plot lines. Here you can change the name, color and mode of the plot
line. For example, the sheep population data could be displayed as bars
and the wolf population data could be displayed as a line.
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image015.gif">
<p>Feel free to familiarize yourself with all of these formatting tools,
but be aware that if you create a pen or plot line, that it will not plot
unless the model has been given some directions on what to plot. This will be
covered more extensively in %%%%Tutorial #3 and the %%%%Programming Guide.
-->
<h3>
Monitors
</h3>
<p>
Monitors are another means of displaying information from a model.
Here are the monitors in Wolf Sheep Predation:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image016.png">
<p>
The monitors show us the population of sheep and wolves, and the
amount of grass. (Remember, the amount of grass is divided by four to
keep the plot from getting too tall.)
<p>
The numbers displayed in the monitors change as the model runs,
whereas the plots show you data from the whole course of the model
run. <!--
<p><span style='color:black'><b>@@@@Challenge:</b>
<p>In the beginning run, the sheep population was lower in
numbers then the wolf population. We then adjusted the initial number of sheep
and wolves favoring the sheep population and still ended up with more wolves
then sheep. Keeping the same values from the previous run, we then increased
the reproductive rate of the sheep, with the result of all sheep and no wolves.
<p><b>@@@@At what settings would you find a balance between the
three populations: grass, sheep and wolf? When you have mastered this
challenge, export the data to an Excel spreadsheet.</b>
<p>####B. <u>Resizing the Interface Elements:</u>
<p>When running models, you may need to move a button or
increase its size.
<p>Place your mouse right next to but still outside of the
button "go".
<p>You will notice that the mouse turns into a crosshair.
<p>Drag the crosshair over the button "go".
<p>The button is now highlighted or selected: <img alt="screen shot"
src="images/tutorial1/image003.gif"> When the button is
selected like this, you can move it around the Interface Tab or resize it.
<p>Move the highlighted "go" button to below the Command Center.
<p>Highlight and move the "setup" button to below the Command
Center.
<p>Both buttons should still be highlighted, elongate them to
fill in the space below the Command Center. Use the picture below as a guide.
<p class="screenshot"><img alt="screen shot" src="images/tutorial1/image004.gif">
<p>Feel free to use this procedure to resize or move any
button, slider, monitor, Plot Window or View.
-->
<h2>
Controlling the View
</h2>
<p>
In the Interface tab, you'll see a toolbar of controls. Some of
these control aspects of the view.
<blockquote>
<p>
Let's experiment with the effect of these controls.
<ul>
<li>Press &quot;setup&quot; and then &quot;go&quot; to start the
model running.
<li>As the model runs, move the speed slider to the left.
</ul>
<p class="question">
What happens?
<p>
This slider is helpful if a model is running too fast for you to
see what's going on in detail.
<ul>
<li>Move the speed slider to the middle.
<li>Try moving the speed slider to the right.
<li>Now try checking and unchecking the &quot;view updates&quot;
checkbox.
</ul>
<p class="question">
What happens?
</blockquote>
<p>
Fast forwarding the model and turning off view updates are useful if
you're impatient and want a model to run faster. Fast forwarding
(moving the speed slider to the right) drops view updates so the
model can run fast, since updating the view takes time that could be
used for running the model itself.
<p>
When view updates are off completely, the model continues to run in
the background, and plots and monitors still update. But if you want
to see what's happening, you need to turn view updates back on by
rechecking the box. Many models run much faster when view updates are
off. For others, it makes little difference.
<p>
The size of the view is determined by five separate settings:
min-pxcor, max-pxcor, min-pycor, max-pycor, and patch size. Let's
take a look at what happens when we change the size of the view in
the &quot;Wolf Sheep Predation&quot; model. <!--<blockquote>
<ul>
<li>Experiment with the three sets of black arrows on the left
of the control strip.
</ul>
<p class="question">What happens the first time you press one
of them?
<p class="question">What happens after that? Try all three
sets of arrows.
</blockquote>-0
<p>The arrows give you a convenient way of changing the number of
patches in the world. NetLogo can't change the number of patches
without starting the model over from the beginning, so that's why it
warns you the first time you press an arrow.-->
<p>
There are more model settings than there's room for in the
toolbar. The &quot;Settings...&quot; button lets you get to the rest
of the settings.
<blockquote>
<ul>
<li>Press the &quot;Settings...&quot; button in the toolbar.
</ul>
<p>
A dialog will open containing all the settings for the view:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image005.png">
<p class="question">
What are the current settings for min-pxcor, max-pxcor, min-pycor,
max-pycor, and patch size?
<ul>
<li>Press &quot;cancel&quot; to make this window go away without
changing the settings.
<li>Place your mouse pointer next to, but still outside of, the
view.
</ul>
<p>
You will notice that the pointer turns into a crosshair.
<ul>
<li>Hold down the mouse button and drag the crosshair over the
view.
</ul>
<p>
The view is now selected, which you know because it is now
surrounded by a gray border.
<!--src="images/tutorial1/image003.gif"> When the button is
selected like this, you can move it around the Interface Tab or resize it. -->
<ul>
<li>Drag one of the square black &quot;handles&quot;. The handles
are found on the edges and at the corners of the view.
<li>Unselect the view by clicking anywhere in the white background
of the Interface tab.
<li>Press the &quot;Settings...&quot; button again and look at the
settings.
</ul>
<p class="question">
What numbers changed?
<p class="question">
What numbers didn't change?
</blockquote>
<p>
The NetLogo world is a two dimensional grid of &quot;patches&quot;.
Patches are the individual squares in the grid. In Wolf Sheep
Predation, when the &quot;grass?&quot; switch is on the individual
patches are easily seen, because some are green, others brown.
<p>
Think of the patches as being like square tiles in a room with a tile
floor. By default, exactly in the middle of the room is a tile
labeled (0,0); meaning that if the room was divided in half one way
and then the other way, these two dividing lines would intersect on
this tile. We now have a coordinate system that will help us locate
objects within the room:
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image007.gif">
<blockquote>
<p class="question">
How many tiles away is the (0,0) tile from the right side of the
room?
<p class="question">
How many tiles away is the (0,0) tile from the left side of the
room?
</blockquote>
<p>
In NetLogo, the number of tiles from right to left is called
world-width. And the number of tiles from top to bottom is
world-height. These numbers are defined by top, bottom, left and
right boundaries.
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image008.gif"> <!--
<p>Using the same way screen edge x was calculated, determine what
the value for screen edge y?
-->
<p class="screenshot">
<img alt="screen shot" src="images/tutorial1/image009.gif">
<p>
In these diagrams, max-pxcor is 3 , min-pxcor is -3, max-pycor is 2
and min-pycor is -2.
<p>
When you change the patch size, the number of patches (tiles)
doesn't change, the patches only get larger or smaller in the
view. <!--
For example, when the "Wolf Sheep Predation" model opens up it has a
screen edge x and screen edge y value of 20. Therefore, the total
number of patches or tiles would be 20 * 20 + 1 = 401 with each patch
being 8 pixels in size. But when you are looking at the smaller sized
View, you notice that screen edge x and screen edge y still
report at 20 but the size of the patches are 5.1219512195 pixels.
-->
<!--
<p>What do you
think happens if screen edge x and screen edge y values are changed?
-->
<p>
Let's look at the effect of changing the minimum and maximum
coordinates in the world.
<blockquote>
<ul>
<li>Using the Settings dialog that is still open, change max-pxcor
to 30 and max-pycor value to 10. Notice that min-pxcor and
min-pycor change too. That's because by default the origin
(0,0) is in the center of the world.
</ul>
<p class="question">
What happened to the shape of the view?
<ul>
<li>Press the &quot;setup&quot; button.
</ul>
<p>
Now you can see the new patches you have created.
<ul>
<li>Edit the view by pressing the &quot;Settings...&quot; button
again.
<li>Change the patch size to 20 and press &quot;OK&quot;.
</ul>
<p class="question">
What happened to the size of the view? Did its shape change?
</blockquote>
<!--<p>Increasing the size of the patches also increased the size of
the View. Whereas, changing the screen edge x and screen
edge y values alters the dimension of the View.-->
<p>
Editing the view also lets you change other settings. Feel free to
experiment with these.
<p>
Once you are done exploring the Wolf Sheep Predation model, you may
want to take some time just to explore some of the other models
available in the Models Library.
<h2>
Models Library
</h2>
<p>
The library contains four sections: Sample Models, Curricular Models,
Code Examples, and HubNet Activities.
<h3>
Sample Models
</h3>
<p>
The Sample Models section is organized by subject area and currently
contains more than 200 models. We are continuously working on adding
new models to it, so come visit this section at a later date to view
the new additions to the library.
<p>
Some of the folders in Sample Models have folders inside them labeled
&quot;(unverified)&quot;. These models are complete and functional,
but are still in the process of being reviewed for content, accuracy,
and quality of code.
<h3>
Curricular Models
</h3>
<p>
These are models designed to be used in schools in the context of
curricula developed by the CCL at Northwestern University. Some of
these are models are also listed under Sample Models; others are
unique to this section. See the Info tabs of the models for more
information on the curricula they go with.
<h3>
Code Examples
</h3>
<p>
These are simple demonstrations of particular features of NetLogo.
They'll be useful to you later when you're extending existing
models or building new ones. For example, if you wanted to add a
histogram to your model, you'd look at &quot;Histogram
Example&quot; to find out how.
<h3>
HubNet Activities
</h3>
<p>
This section contains participatory simulations for use with groups.
For more information about HubNet, see the <a href=
"hubnet.html">HubNet Guide</a>.
<h2>
What's Next?
</h2>
<p>
If you want to learn how to explore models at a deeper level,
<a href="tutorial2.html">Tutorial #2: Commands</a> will introduce you
to the NetLogo modeling language.
<p>
In <a href="tutorial3.html">Tutorial #3: Procedures</a> you can learn
how to alter and extend existing models and build new ones.
Jump to Line
Something went wrong with that request. Please try again.