NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Many Regions Example

[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web

WHAT IS IT?

This example shows how to divide the world in a variable number of regions and keep turtles confined to the region they start in.

HOW IT WORKS

The world is separated in regions divided by vertical lines. When a turtle reaches the left or right boundary of a region, it crosses to the other side, thereby always staying in the same region.

HOW TO USE IT

Choose the NUMBER-OF-REGIONS and the NUMBER-OF-TURTLES-PER-REGION that you want, click SETUP, and then GO.

THINGS TO NOTICE

You can watch one of the turtles and see it jumping to the other edge of the region when it reaches its boundary. Running the model at slower speed makes this easier to see.

THINGS TO TRY

The NUMBER-OF-REGIONS slider is currently capped at a maximum of 32 regions. This number creates narrow regions: only one patch wide! There is still enough room for all of them, however. What do you think would happen if you increased the maximum to a bigger number? Try it. Does the model still work? Why?

EXTENDING THE MODEL

When a turtle reaches the left or right boundary of a region, they "wrap" to the other side. That's not the only possible behavior: they could also just stop there.

The current model only allows vertical regions. Changing to use horizontal regions instead should be fairly easy, but how about a making "grid" of regions, where you would specify a number of rows and a number of columns?

Look at the Bug Hunt models in the library: they use a special breed of turtles called "dividers", with a custom turtle shape, to cover the region divisions and make the wrapping animation appear smoother. You can try to do the same here.

NETLOGO FEATURES

This model makes use of the variadic versions of foreach and map, which allow these primitives to be used with multiple lists at the same time.

The map primitive is used in the region-definitions procedure to loop through two copies of the divisions list at once, thereby scanning through "pairs" of divisions.

The foreach primitive is used in various places to loop through regions and their indices (generated with n-values). This advantageously replaces a while loop, as it is both shorter and less error-prone.

RELATED MODELS

The Bug Hunt models in the ModelSim folder of the library use a version of this code to separate the bugs in two distinct regions.

CREDITS AND REFERENCES

This example was developed by Nicolas Payette, inspired by Michael Novak's work on various ModelSim models.

(back to the NetLogo Models Library)