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)

Neighborhoods 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 code example shows how to use the basic neighborhood primitives. These include neighbors, neighbors4, in-radius, and at-points:

  • neighbors: reports the patches surrounding a patch or turtle both patches that share a side and those that share a corner. If the world is a torus every patch will have eight neighbors, if wrapping is not allowed in either direction the edge patches will have fewer neighbors.

  • neighbors4: reports the same patches, excluding the ones at the corners. On a torus there will always be four neighbors.

  • <agentset> in-radius <number>: reports those agents in agentset whose distance from the caller is less than or equal to n.

  • <agentset> at-points <list>: reports those agents in agentset at the given points relative to the caller, where list is a list of two-number lists.

Although in this example, we only change the color of the reported patches, you can of course do more complicated operations, including assigning that agentset to a variable. This is particularly useful in cellular automata models.

RELATED MODELS

Moore & Von Neumann Example shows how to use square (Moore) or diamond (Von Neumann) shaped neighborhoods of any size.

To see neighbors and neighbors4 in the sample models see Shepherds, Altruism, GenDrift P local, Ising, Crystallization models, CA models, Fire, Rumor Mill, Segregation, and Voting.

To see in-radius in the sample models see Fireflies, Flocking, and Simple Kinetics 3.

To see at-points in the sample models see the Crystallization models, and Wave Machine.

(back to the NetLogo Models Library)