Early in my agent-based modeling training I fell in love with the idea of hexagonal-tiled discrete spaces (rather than square-tiled). One of my first projects (done with Ken as a matter of fact) was to implement the famous AntPheromones model on a hex grid. For some bizarre reason (perhaps problems in implementation) hex is not commonly used despite its expansive list of known benefits. Support for hex in Repast was/is bad, very bad, and we had to rewrite and correct several buggy methods for that project. Support for hex in NetLogo is worse (see code samples). This post aims to fill this niche in NetLogo by providing a framework for hex-based (cellular automata or free-roaming agent-based) models.

Hex made Easy

A vast majority of spatial agent-based models utilize a discrete space where agents move from location to location rather than through a continuum of coordinates. Under some typical conditions (the space is a torus, cut up into squares, and the von Neumann neighborhood is used) the space is equivalent to a regular degree-4 latticed network. If the Moore neighborhood is used then it is a degree-8 regular network. So it is pretty clear that a space cut up into hexes is equivalent to a regular degree-six lattice. And that’s how I implement the hex grid in NetLogo.

With version 3.1, NetLogo added some experimental network generating primitives. Using these new primitives makes generating networks much easier than before and now it is actually practical to do so in NetLogo. In under half an hour I was able to create the model (more of a code sample) presented here that will provide you a basis for building your own hex-based agent-based models. It includes the code to generate the network (with wrapping boundaries turned ON) and some simple agent movement and agent-“patch” interaction.

You can download the code here and use it to your heart’s content. Note that it requires NetLogo 3.1.1 or later version.