Netlogo, Systems Biology, and Agent Based Modeling

Mtchel Resnick is the director of the Lifelong Kindergarten group at the Media Laboratory at MIT. Although his creativity appears to be endless (see his website)we will focus on a software concept that he and team developed in the 90′s. The programming tool he developed was called StarLogo which was an extension as well as a major refocusing of the older functional programming language Logo originally developed for educational use. Logo is mainily famous for its use of Turtle graphics. Resnick and team started with the concept of Turtle Graphics and redesigned the system to allow the programmer to developed simulations of agent based decentralized systems(A Lecture). These include but are not limited to biological system simulations involving ants, mold slime and flocking to name a few. You can create physics simulations of collisions between particles bounded, perfume particle dissimulation as well as wave motion on a rope. The applications are endless.

Rather than use StarLogo (which by the way is still available and in use) we will use a more advanced version developed at Northwestern University by Uri Wilensky called NetLogo.  The program and manual are free and can be downloaded from the indicated site.

In this class we will restrict outselves to biological agent based simulation. Why, because that is what I am interested in at the moment. Next semester I may change to social systems. You never know. Well lets get started. First you can download the software on your home machine if you desire. There is a version for many of the OS’s out there including Windows, Mac’s and Unix. In class you may access the executable by going to My Computer , Coursework, on Y:/RichardSimpson/NetLogo 5.0/NetLogo 5.0.  If you are running the software from an installed version at home you will note that there are many example projects that you can open and run under file/models library. Select some of these and observe what happens. You may need to click go to get this to run. Try out several of these programs to get a feel of the variety of directions that these can take.  The wolf Sheep Predation is interesting.  

When you run the program initially the opening screen should look like the following.

The applications has three tabs of interest.  The Interface tab is what is presently available.  It will allow us to put buttons, sliders etc on the left of the black rectangular area (the Netlogo world of patches).  The Code tab will take you to the programming editor where you can write netlogo procedures.  These procedures can be attached to buttons in order to facilitate interactive execution of code.  The final tab is the Info.  Here you can document your program indicating what it does, who wrote it  etc.

At the very bottom of the screen is the Command Center.  Here the user can enter commands next to observer> and have them immediately executed with the list of commands and output appearing in the Command Center section.  There are a quite a lot of other features but we will delay their discussion until we get a better handle on the system.  Note that if you click on the observer> you will get a little window that will allow you to select the input mode.  These include observer, turtles, patches and links.  If you select turtles you will be placed into the turtles mode and see turtles>.

Ok, lets get started. The programming language concerns itself with four objects, turtles, patches, links and the observer. Turtles are small objects that you can move around on the world screen using program control.  Lets do some interactive commands to get the feel.  The first command we shall look at is the create-turtle (crt for short) command.   Type crt 10 in the observer> mode and hit return. You should see a blob in the center of the screen as well as the Command Centers note of the execution of this command.

The little blob in the center of the screen is really a stack of turtles that have different orientations(headings). To see this first click on observer> at the bottom of the screen and select turtles.  You should now see turtles>.  Now type the command fd 10 withing the Turtle command section.

You should see a ring of turtles on the right.  t 180 degrees.  The original turtles (little triangles in this case) have each moved outward  10 steps.  Each turtle is pointing away from the center.  This is because they were initially created with those headings.  Type fd 3 at the bottom and see what happens.  Do this several times.  What do you observe?

Lets now clear the screen of turtles and create some more to work with. In order to create turtles and clear screen we need to be in the Observer mode.  In the Observer Command Center type ca and return. This means ClearALL. The turtles will disappear. Now create 10 turtles using crt 10. Go back to the Turtle mode and execute fd 5 over and over again and see what happens when you go off the scree.. Hmmm

This takes way too much work. We would of course like to animate this so we can see a lot of moves done repeatedly.   This of course requires us to write code so click the Code tab at the top.  This opens the code editor so you can type in a program.   Programs in NetLogo are really just a collection of procedures.  In order to start lets type in the  code on the right.  When you are finished click Check and it will tell you if you have typed correctly.  Now go back to the Interface tab and run the two following commands in the command center. 

  1. observer> setup
  2. turtles>repeat 1000 [fd 1]

The repeat 1000 [fd 1] command does what you think. It repeatedly executes the command fd 1 1000 times.  You can slow things down by moving the speed slider to the left.


The above method of executing your code is too much of a hassle.  Another way we can execute procedures is by creating a button on the interface that will execute the procedure when pressed. This is very easy. Just click once on the blue button icon on the command bar and then select the button option.  Click in the white area to the left of the world and a button will appear.  Within the popup window type setup in the commands area.  Now hit ok.  This is a button that will run the setup procedure when it is clicked.

Now add a second button below this one and in the command section type go.  Before clicking ok we need to change the mode from observer to turtles.  This is the menu next to agents at the top.  Now click ok.  Check it out by clicking this button several times.  After you get tired of doing this lets make it run repeatedly.  Right click on the go button and select edit.  Click the forever flag and then ok.  Now hit the go button.


Here we will make a turtle wander around randomly on the screen. StartLogo has a command called random that allows us to grab a random number when desired. The command random 10 does this. Look it up inthe Commands section on the StarLogo Web site. Keep this site open while you develop programs and you can check out commands quickly. From this documentation we see that random n returns a random number between 0 and n, including 0 but not n, based on a uniform distribution. To make the turtles wander around replace the rt angle command with right 30 left random 90 and rerun.

If you have problems with the above compiling remember the following

  1. use only small letters
  2. use spaces to separage numbers and commands etc (IE if ( random 100 < 5 [ setpc green ]])
    1. if you are unsure then put a space there
  3. When you create a button and place the name of a procedure in it make sure you click the turtle or observer selection.
  4. Incrementally develop the program. Many of us had problems on Wed because I tried to speed up the process.


Comments are closed.