NetLogo banner

 Home
 Download
 Help
 Resources
 Extensions
 FAQ
 NetLogo Publications
 Contact Us
 Donate

 Models:
 Library
 Community
 Modeling Commons

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

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Link Lattice 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 construct a regular lattice or mesh of links. Two kinds of lattice are demonstrated, a square lattice (where each node has four neighbors) and a hex lattice (where each node has six neighbors).

THINGS TO TRY

The current code creates undirected links. To modify setup-square to create a fully connected lattice of directed links, use create-links-to instead of create-links-with. (Making the same change to the hex lattice code is only a little trickier.)

If you turn off wrapping at one or both world boundaries, the lattice will be bounded. You don't need to change the square lattice code in that case, because the neighbors4 primitive returns fewer than four neighbors for patches on the world edges. (Making the same change to the hex lattice code is only a little trickier.)

The square lattice can be modified to include diagonal links by changing neighbors4 to neighbors.

RELATED MODELS

  • Hex Cells Example: shows how to treat patches as a hexagonal lattice, without creating any links.
  • Lattice-Walking Turtles Example: shows how to make turtles walk along the lattice.

(back to the NetLogo Models Library)