Transition Guide

NetLogo 4.0.5 User Manual   

Many models created in earlier versions of NetLogo also work in NetLogo 4.0. However, some models will need changes. If your old model isn't working, this section of the User Manual may be able to help you.

What issues you need to be aware of depends on how old your model is. The older the NetLogo version it was made with, the more issues you may need to be aware of.

This section does not list every change that was made for NetLogo 4.0. It discusses only the changes that are most likely to be issues for users. For a complete list of changes, see the What's New? section.

Since NetLogo 3.1

Who numbering

Prior to NetLogo 4.0, a dead turtle's who number (stored in the who turtle variable) could be reassigned to a later newborn turtle. In NetLogo 4.0, who numbers are never reused until who numbering is reset to 0 by the clear-all or clear-turtles command. This change in behavior may break a few old models.

Turtle creation: randomized vs. "ordered"

NetLogo 4.0 provides two different observer commands for creating turtles, create-turtles (crt) and create-ordered-turtles (cro).

crt gives the new turtles random colors and random integer headings. cro assigns colors sequentially and gives the turtles sequential equally spaced headings, with the first turtle facing north (heading of 0).

Prior to NetLogo 4.0, the crt command behaved the way cro does now. If your old model depends on the "ordered" behavior, you will need to change your code to use cro instead of crt.

It is common for old models that used crt to contain extra commands to randomize the new turtles' headings, for example rt random 360 or set heading random 360. These commands are no longer necessary when used inside crt.

Adding strings and lists

Prior to NetLogo 4.0, the + (addition) operator could be used to concatenate strings and join lists. In current NetLogo, + only works on numbers. To concatenate strings, use the word primitive; to join lists together, use the sentence primitive. This language change was made to increase the speed of code that uses +.

Old code:

print "There are " + count turtles + " turtles."

New code:

print (word "There are " count turtles " turtles.")

Likewise, if you need to concatenate lists, use SENTENCE.

This change is not handled automatically when converting old models; users will need to change their code by hand.

We know this change will be awkward for users who are used to the old syntax. We have made this change for efficiency and consistency. We can implement an addition operator that only adds numbers much more efficiently than one that handles several different data types. Because addition is such a common operation, NetLogo's overall speed is affected.

The -at primitives

The observer may no longer use patch-at, turtles-at, and BREEDS-at. Use patch, turtles-on patch, and BREEDS-on patch instead. Note that patch now rounds its inputs (before it only accepted integer inputs).

Links

NetLogo 3.1 had supports for using links to connect turtles to make networks, graphs, and geometric figures. The links were themselves turtles.

In NetLogo 4.0, instead of links being turtles, links are now an independent fourth agent type, right alongside observer, turtles, patches. The primitives involving links are no longer considered experimental; they are now fully part of the language.

Models that use the old, experimental turtle-based link primitives will need to be updated to use link agents. The differences are not huge, but hand updating is required.

Links are documented in the Links section of the Programming Guide, and in the NetLogo Dictionary entries for the link primitives. See the Networks section of the Models Library for example models that use links. There are also some link-based Code Examples.

First you will need to remove any breeds called "links" if you are only using one type of links then you will not have to use breeds at all. If you are using multiple types of links see undirected-link-breeds and directed-link-breeds. Commands and reporters that contain the word "links" (like __create-links-with, etc.) will automatically be converted to the new form without underscores (create-links-with). However, primitives that use a different breed name (such as "edges") will not be converted. You will need to remove the underscores by hand and unless you are declaring a link breed with that name you will need to change the breed designation to "links".

The commands remove-link(s)-with/from/to no longer exist. Instead you should ask the links in question to die.

For example:

ask turtle 0 [ __remove-links-with link-neighbors ]

becomes

ask turtle 0 [ ask my-links [ die ] ]

Several of the layout commands have slightly different inputs, the first two inputs are generally a turtle agentset and a link agentset to perform the layout on. See the dictionary entries for details. layout-spring, __layout-magspring layout-radial layout-tutte

You may also need to rearrange the declaration of turtles-own variables, since links were once actually turtles. Any variables that apply to links should be moved into a links-own block.

Since links are no longer turtles they no longer have the built-in turtle variables (though some of the link variables are the same such as color and label. If you formerly used the location of link turtles you will now need to calculate the midpoint of the link. This is fairly simple in a non-wrapping world.

to-report link-xcor
  report mean [xcor] of both-ends
end

to-report link-ycor
  report mean [ycor] of both-ends
end
it is a little bit trickier in a wrapping world but still fairly straightforward.
to-report link-xcor
  let other-guy end2
  let x 0
  ask end1 
  [
    hatch 1
    [ 
      face other-guy
      fd [distance other-guy] of myself / 2
      set x xcor
      die
    ]
  ]
  report x
end

and similarly for ycor.

If you used either the size or heading of the link turtles you can use the reporters link-length and link-heading instead.

New "of" syntax

We have replaced three different language constructs, -of (with hyphen), value-from, and values-from with a single of construct (no hyphen).

old new
color-of turtle 0 [color] of turtle 0
value-from turtle 0 [size * size] [size * size] of turtle 0
mean values-from turtles [size] mean [size] of turtles
When of is used with a single agent, it reports a single value. When used with an agentset, it reports a list of values (in random order, since agentsets are always in random order).

Note that when opening old models in the new version, -of, value-from, and values-from will automatically be converted to use "of" instead, but some nested uses of these constructs are too complex for the converter and must be converted by hand.

Serial ask

The ask command is now serial rather than concurrent. In other words, the asked agents will run one at a time. Not until one agent completely finishes the entire body of the ask does the next agent start.

Note that even the old ask was never truly concurrent; we simulated concurrent execution by interleaving execution among the agents using a turn-taking mechanism described in the NetLogo FAQ.

We have made this change because in our experience, users often wrote models that behaved in unexpected ways due to the simulated concurrency, but rarely wrote models that benefited from the simulated concurrency. Models exhibiting unexpected behavior could usually be fixed by adding the without-interruption command in the right places, but it was difficult for users to know whether that command was needed and if so, where.

In NetLogo 4.0, without-interruption is no longer necessary unless your model uses ask-concurrent (or a turtle or patch forever button containing code that depends on simulated concurrency). In most models, all uses of without-interruption can be removed.

The simulated concurrency formerly employed by "ask" is still accessible in three ways:

Note that ask itself is always serial regardless of the context in which it is used, however.

In our own Models Library, models that make use of this concurrency are rare. A prominent example, though, is Termites, which uses a concurrent turtle forever button.

Tick counter

NetLogo now has a built-in tick counter for representing the passage of simulated time.

You advance the counter by one using the tick command. If you need to read its value, there's a reporter called ticks. The clear-all command resets the tick counter; so does reset-ticks.

In most models the tick counter will be integer-valued, but if you want to use smaller increments of time, you can use the tick-advance command to advance the tick counter by any positive amount, including fractional amounts. Some Models Library models that use tick-advance are Vector Fields and the GasLab models.

The value of the tick counter is displayed in the toolbar at the top of the Interface tab. (You can use the Settings... button in the toolbar to hide the tick counter, or change the word "ticks" to something else.)

View update modes

In the past, NetLogo always tried to update the view about 20 times a second. We're now calling that "continuous" view updates. The biggest problem with it was that you usually want updates to happen between model ticks, not in the middle of a tick, so we had a checkbox on buttons that (by default) forced a display update after every button iteration. That made sure updates happened between ticks, but it didn't get rid of the intermediate updates. You had to use no-display and display to lock them out.

We still support continuous updates. They are the default when you start up NetLogo. But most Models Library models now use tick-based updates. With tick-based updates, updates happen only when the tick counter advances. (The display command can be used to force additional updates; see below.)

The advantages of tick-based updates as we see them are as follows:

  1. Consistent, predictable view update behavior which does not vary from computer to computer or from run to run.
  2. Intermediate updates can confuse the user of your model by letting them see things they aren't supposed to see, which may be misleading.
  3. Increased speed. Updating the view takes time, so if one update per tick is enough, then enforcing than there is only one update per tick will make your model faster.
  4. Instead of having a "force view update" checkbox in every button like in NetLogo 3.1, we only need one choice which applies to the entire model.
  5. Using the speed slider to slow down a model now just inserts pauses between ticks. So with tick-based updates, setup buttons are no longer affected by the speed slider. This was a real annoyance with the old speed slider. (The annoyance persists for models that use continuous updates, though.)

As mentioned above, most models in our Models Library now uses tick-based updates.

Even for models that would normally be set to tick-based updates, it may be useful to switch to continuous updates temporarily for debugging purposes. Seeing what's going on within a tick, instead of only seeing the end result of a tick, could help with troubleshooting.

If you switch your model to use tick-based updates, you'll also need to add the tick command to your code, otherwise the view won't update. (Note that the view still always updates when a button pops up or a command entered in the command center finishes, though. So it's not like the view will just stay frozen indefinitely.)

How to make a model use ticks and tick-based updates

Here are the steps to follow to convert your model to use ticks and tick-based updates in NetLogo 4.0:

  1. In the Interface tab toolbar, on the right hand side where it says "update view:", change the setting from "continuously" to "on ticks".
  2. Add the tick command to your go procedure, at or near the end. In Models Library models we always put tick after the agents move but before any plotting commands. That's because the plotting commands might contain something like plotxy ticks ... and we want the new value of the tick counter used, not the old one. Most models don't refer to the tick counter in their plotting commands, but nonetheless, for consistency and to avoid mistakes we suggest always putting tick before the plotting commands.

Some models will require some additional changes:

  1. If your model already has a global "ticks" or "clock" or "time" variable, get rid of it. Use the tick command and ticks reporter instead. (If your model uses fractional increments of time, use tick-advance instead of tick.) If you had a monitor for that variable, you can get rid of it; there's now a tick counter in the toolbar.
  2. clear-all resets the tick counter to zero. If you don't use clear-all in your setup procedure, then you may need to add reset-ticks to reset the counter to zero.
  3. If you used no-display and display to prevent view updates from happening in the middle of go, you can get rid of them.
  4. If your model needs to update the view without advancing the tick counter (examples: Party, Dice Stalagmite, network models with animated layout, models with mouse interaction buttons), use the display command to force additional view updates so the user can see what is going on.

Speed slider

Previous versions of NetLogo had a speed slider that could be used to make models run slower, so you can see what's going on.

In NetLogo 4.0, the slider can be used to speed up models as well. It does this by updating the view less frequently. Updating the view takes time, so the fewer updates, the faster the model runs.

The default position of the slider is in the center. When you're at the center, the slider says "normal speed".

As you move the slider away from the center position, the model will gradually run faster or slower.

At very high speeds, view updates become very infrequent and may be separated by several seconds. It may feel like the model is actually running slower, since the updates are so infrequent. But watch the tick counter, or other indicators such as plots, and you'll see that yes, the model really is running faster. If the infrequent updates are disconcerting, don't push the slider so far over.

When using tick-based updates, slowing the model down does not cause additional view updates. Rather, NetLogo simply pauses after each tick.

When using continuous updates, slowing the model down means view updates become more closely spaced. If you push the speed slider more than halfway to the left, the model will be running so slowly that you can watch turtles moving one at a time! This is new in NetLogo 4.0; in previous NetLogo versions, no matter how slowly you ran a model, you would never see the agents in an ask moving one at a time; all the agents in an ask always appeared to move together.

Numbers

NetLogo no longer maintains an internal distinction between integers and floating point numbers. So for example:

Old:

observer> print 3
3
observer> print 3.0
3.0
observer> print 1 + 2
3
observer> print 1.5 + 1.5
3.0
observer> print 3 = 3.0
true

(The last line shows that although the distinction between integer 3 and floating point 3.0 was maintained, the two numbers were still considered equal.)

New:

observer> print 3
3
observer> print 3.0
3
observer> print 1 + 2
3
observer> print 1.5 + 1.5
3
observer> print 3 = 3.0
true

We expect that only rare models will be negatively impacted by this change.

A benefit of this change is that NetLogo now supports a much larger range of integers. The old range was -2,147,483,648 to 2,147,483,647 (around +/- 2 billion); the new range is +/-9,007,199,254,740,992 (around +/- 9 quadrillion).

Agentset building

NetLogo 3.1 (and some earlier versions) included primitives called turtles-from and patches-from that were occasionally useful for building agentsets. In NetLogo 4.0, these primitives have been replaced with new primitives called turtle-set and patch-set that are much more flexible and powerful. (link-set exists as well.) See the entries for these primitives in the NetLogo Dictionary. Models that use the old turtles-from and patches-from will need to be altered by hand to use the new primitives.

RGB Colors

In NetLogo 3.1 RGB and HSB colors could be approximated as NetLogo colors using the rgb and hsb primitives. These have been renamed to approximate-rgb and approximate-hsb and now expect inputs in the range 0-255, not 0-1.

The full RGB spectrum is now available in NetLogo so it may no longer be necessary to use these primitives at all. You can set any color variable to a three-item RGB list, with values in the 0-255 range, and get that exact color. See the Color section of the Programming Guide for details.

Tie

In previous versions __tie was provided as an experimental feature. As of NetLogo 4.0 links have a tie-mode variable which can be set to "none", "free", or "fixed". In 4.0 tie is now a link-only primitive. This means that to tie turtle 1 to turtle 0 you write:

  ask turtle 0 [ create-link-to turtle 1 [ tie ] ]

See the Tie section of the programming guide for details.

HubNet Clients

A HubNet activity's client interface is no longer stored in a separate model file. To import a client from an old model select File -> Import -> Import HubNet Client. Then when asked, import from the Interface Tab. You will no longer need the external client model and you will no longer need to point to it when setting the client interface so this:

hubnet-set-client-interface "COMPUTER" [ "my-client.nlogo" ]

becomes:

hubnet-set-client-interface "COMPUTER" []

Performance of Lists

The internal implementation of lists has changed which changes some of the performance properties of lists, see the Programming guide for details on the current implementation. Note that fput is much faster than lput thus, you may improve performance simply by switching to fput. If performance is still a problem you may want to consider using the Array & Table extensions

Since NetLogo 3.0

Agentsets

If your model is behaving strangely or incorrectly, perhaps it's because since NetLogo 3.1, agentsets are now always in random order. In prior versions of NetLogo, agentsets were always in a fixed order. If your code depended on that fixed order, then it won't work anymore. How to fix your model to work with randomized agentsets depends on the details of what your code is doing. In some situations, it is helpful to use the sort or sort-by primitives to convert an agentset (random order) into a list of agents (fixed order). See "Lists of agents" in the Lists section of the Programming Guide.

Wrapping

If you are seeing pieces of turtle shapes wrapping around the view edges, it's because NetLogo 3.0 allowed you to turn off such wrapping in the view without affecting the behavior of the model. Since NetLogo 3.1, if you don't want the view to wrap you must make it so the world doesn't wrap, using the new topology feature. Making this change may require other changes to your model, though. See the Topology section of the Programming Guide for a thorough discussion of how to convert your model to take advantage of this new feature.

Random turtle coordinates

Many models made in NetLogo 3.0 or earlier use setxy random world-width random world-height to scatter turtles randomly, using either random or random-float. It only works if world wrapping is on.

(Why? Because when wrapping is on, you can set coordinates of turtles to numbers beyond the edge of the world and NetLogo will wrap the turtle to the other side. But in worlds that don't wrap setting the x or y coordinates of a turtle to a point outside the bounds of the world causes a runtime error. The world wrap settings were added in NetLogo 3.1. See the Topology section of the Programming Guide for more information.)

To fix your model so that it works regardless of the wrapping settings, use one of these two commands instead:

setxy random-xcor random-ycor
setxy random-pxcor random-pycor

The two commands are a bit different. The first command puts the turtle on a random point in the world. The second command puts the turtle on the center of a random patch. An even more concise way to put a turtle on the center of a random patch is:

move-to one-of patches