NetLogo Tutorial
From Backspaces Wiki
| NetLogo Tutorial |
Hi! Welcome.
This is an introduction to the NetLogo modeling system.
NetLogo is a complete environment for creating and running models you make, using a variant of the Logo programming language. It has its own rapid prototyping IDE (Integrated Development Environment) as well as the run-time environment for running the model. It has a wonderful set of features that include creating videos of your model running, putting your model on the web via Java applets, a Behavior Space which runs your models over and over again with different parameter settings, lots of tutorials and sample models, brilliant documentation and a dynamic community of users with an active mail-list.
We're going to take a bit different approach than usual. It is a self-paced tutorial which you can pursue when/where you want. You'll need an internet connection. We are not going to focus primarily on the NetLogo language and how to program with it. Rather we are going to guide you through the existing material and several demo models, showing how it all fits together. NetLogo is immersive, you'll pick up the NetLogo language easily as we go through examples in detail.
Contents |
Navigating the Tutorial
Before we get started, a quick note on the tutorial structure. We are using MediaWiki, the Wikipedia software. The tutorial consists of several modules, each on its own wiki page. To navigate between the tutorial modules, use the links in the NetLogo Tutorial table, floating to the right, above. To navigate within a module, use the Contents table on the left, above, which navigates to the sections within the module.
Downloading and Installing NetLogo
Because NetLogo is written in Java, it will run on all of our computers: Linux, Mac, and Windows. Java also makes it web friendly, letting you create a web page with your model "live" inside the page (as an applet).
So we'll start the immersion promptly by guiding you through downloading and running NetLogo.
First go to Northwestern University's NetLogo site. It will look like the picture below, left. (Note: click on any picture you see within the wiki to see it full size.)
Click on the Download link.
This will take you to a page letting you choose between several versions of NetLogo (below middle). You'll want the most recent, 4.1. Use the drop-down menu labeled "Version:" to select the 4.1. Then click on the download button which will take you to a page letting you choose your computer type: Windows, Mac, Other (below, right).
It'll take a while, the typical size is over 40Mb.
| | | |
Once the download is complete, you'll want to place the resulting folder in a convenient place. On my Mac, I simply move it to the Applications folder. If you run into any problem, just ask one of the students with a similar computer what they did.
The download will include both the standard NetLogo and the 3D version. We'll generally use the standard version, but you'll want to experiment with 3D modeling too. This is particularly interesting if you want to model a non-linear dynamics model like the Lorenz system. More on that later.
We also have a small folder of NetLogo files we'll use during the tutorial. To download NetLogoTut.zip, click here. You can place it anywhere you'd like on your computer.
OK: by now you should have downloaded both versions of NetLogo along with the tutorial folder and put them in the appropriate place on your computer. Lets start hacking!
Running NetLogo on your desktop
Open NetLogo by double clicking on the application icon. It will open looking like this (remember that clicking on the image will enlarge it):
| |
|
We'll start by showing you how to run the huge set of built-in demos. They live in the Models Library. To see them, click on the File menu, selecting the Models Library item. (Note that there is a keyboard shortcut, Cmd-M on the Mac screen-shot above. You may want to remember yours, it's quite a time saver while you are learning!)
The Models Library browser pops up, letting you look at sample models .. see below. We click on the Art folder and select the Diffusion Graphics model. Notice that when we select a sample, it shows some information about the model. In this case it tells us that it mainly shows how the "diffuse" NetLogo command works.
| | |
To choose the Diffusion Graphics model, click the "Open" button.
It will open the model in its startup, blank state. Note that you are in the Interface panel - see circled button on the top of the NetLogo window below. There are two other choices: Information, where the model is described, and Procedures, where you write the code for your model.
The Interface panel is the UI/Graphics part of the model, where you run your model and show its results.
To run the model, you first click on the "setup" button, then the "go" button. This is a standard NetLogo style:
- setup: This initializes the model, using the global variables you've set via sliders, switches, and other UI elements.
- go: This starts "stepping" the model -- running the go procedure over and over again. Note the little icon of two arrows in the go button. This indicates a repeating button. It will run until you click on it to stop. Each repeat is called a "tick" and you can see a ticks counter on top of the model's display window.
| | |
In case you do not have NetLogo running yet, here's a movie of the model running. Note that this movie was created by NetLogo itself! You can also go to the web version of the model.
Play with more of the models in the Models Library, there really are lots! At last count, well over 300, all told. Here are some images taken from the Models Library, just to whet your appetite:
| | |
The models panel also has a search capability. Here we search for other models using diffusion.
| |
Once you are comfortable with the standard NetLogo, start your 3D version. As above, go to the models library. Run the Raindrops 3D model (3D>Sample Models>Raindrops 3D). Here's a movie of it running, again made by NetLogo itself.
Some details of the NetLogo application
We've seen how to run the Diffusion Graphics sample. Now we'll show a bit more detail.
As we saw above, the NetLogo application starts up in the Interface pane. The Information pane is how the model is documented, and as a plus, how the model is shown on the web. The Edit button above the text is used to convert the Information view into editable text area.
| | |
The third pane is the Procedures pane, where your write your model's program. Note that this model is only 24 lines of code! The Interface pane communicates with the code via the sliders, switches etc UI elements. We show the code variables underlined in the image below and their corresponding UI widget.
The Rest of Us
Believe it or not, for non-programmers, getting this far (downloading, installing, and running the application and its demos) is quite a challenge. If you're still with me, you're doing very well.
So this is a good time to take a break. (We'll go to a Modeling Overview next.) And to give you some pointers to other NetLogo resources. Its comforting to know you are in a very active and supportive community.
- NetLogo User's Group Where NetLogo users hang out. Sign in and ask questions!
- Tom Carter's Computer Simulation Techniques class discuses a wide variety of models.
- Michael Gizzi's Workshop Another site for learning NetLogo
- Nick Bennett's Tutorials: NetLogo exercises (.pdf) from a highly effective Santa Fe teacher/consultant.
Notes
- Navigation: Don't forget -- the next module is found in the NetLogo Tutorial table of links in the top-most section of every page, opposite the Contents table used to navigate within the current module.
- Search (Google): Unfortunately, there is no Search field on the NetLogo site. But, wait! .. there's a trick. Google and Yahoo will search within a site for you using the "site:<site>" syntax. Entering this in a Google or Yahoo search finds all pages with "command center" within the NetLogo documentation:
command center site:ccl.northwestern.edu/netlogo/docs
- Search (user's group): You can also search through the NetLogo Users Group. Go to the site, and you'll see a search field. And if you still can't find an answer, just join the group and ask the question you need answered!
- Nick Bennett's models were developed for use, in part, by participants in Project GUTS, the SFI Summer Internship-Mentorship, and the New Mexico Supercomputing Challenge.

