Agent-based modelling with Netlogo

In this blog post I am going to give an overview of Netlogo, an agent-based modeling environment. The first part will consist of a very brief introduction to some elements of the Netlogo environment. This is not intended to be an extensive tutorial but rather a first glimpse into some of the basic features of the programming language. In the second part I will present Brian Arthur’s El Farol Bar model, to illustrate how agent-based models differ from more traditional modelling techniques.

Netlogo allows the user to create computer simulations in a comparatively short amount of time.1 Because the program has a low difficulty threshold for newcomers and high versatility ceiling for experienced programmers, it can be used for a wide range of different applications, covering everything from initial explorations to sophisticated programs. Netlogo is built around the idea that in certain cases, to understand a natural or social phenomenon, it is advantageous to explicitly simulate the behavior of the individual entities constituting the phenomenon. In an ant colony those entities would be ants, in a cloud of gas molecules, and in a trade network individual traders. The Netlogo programming environment therefore includes functions and capabilities to support this requirement. The background, for example, over which agents move, is divided into individual patches, which can be assigned variables representing real world properties like elevation or other geographical features. In a similar way agents (in the Netlogo lingo called turtles) too can be assigned variables representing their properties. This makes it easy to create a set of heterogeneous agents, as can be seen in the El Farol Bar model I am going to introduce further down below.
Although Netlogo has been mainly used by disciplines like sociology, ecology, archeology, and economics, there also have been attempts by humanities scholars to use the programming language to explore their research questions. Some cases in this regard are concerned with the history of book publishing, social research networks or the evolution of social norms.2
Jeremy Throne, for example, developed an agent-based model about the book trade and the communication circle that connects the different entities of the book trade. His model includes, following the studies of the cultural historian Robert Darnton about the 18th century book trade, authors, publishers, printers, shippers, booksellers, and readers.3 In the model authors try to publish their books, publishers accept manuscripts and bring the manuscripts to printers. Printers print books and keep their products until shippers arrive, who deliver the books to booksellers. The booksellers, in turn, sell their products to readers. Each of the elements of the book trade has to further be specified to create a more realistic, although still simplified, picture or the book trade. One of the benefits of this modelling effort is that the different elements of the model can be changed to see how changes in the behavior of agents change the preference for books, inventory levels, how long it takes for a book to reach a reader, why this takes so much or little time, and so on. It also allows to add a dynamic dimension to the usual static descriptions of the relations between the agents of the book trade. Jeremy Throne’s research specifically showed the importance of printers and shippers in this process.
For those interested in getting familiar with Netlogo but hesitant in the face of an unknown programming language there exist good and easy to access tutorials that provide an introduction to what Netlogo can be used for and what modeling is about more generally. 4


A typical example of Netlogo code looks something like this:

to setup       ;; setup procedure
clear-all       ;; resets the world
create-turtles 10 [setxy 0 0]       ;; creates 10 turtles at coordinates 0 0
ask patches [set pcolor green]   ;; sets patch-color green
reset-ticks       ;; resets Netlogo’s tick counter

to go       ;; go procedure
move-turtles       ;; calls another procedure named move-turtles
export-view (word ticks “.png”)       ;; exports the visualization

to move-turtles       ;; move-turtles procedure
ask turtles [
set heading random 360      ;; turtles randomly in a direction between 0-360 degree
forward 1            ;; moves the turtle forward 1 patch
set pcolor black]      ;; sets patch-color under turtles black

A Netlogo program is divided into different procedures.5 This simple program includes three procedures called setup, go, and move-turtles. Setup and go are called via two buttons. If the setup button is pressed the program clears the virtual world and creates ten turtles in the middle of the green background. By default turtles are represented as little colored triangles. After the initialization with the help of the setup procedure, the go button calls the go procedure, which tells the turtles to move forward one patch and generates a visualization like this:

Visualization of the Netlogo code above.

Procedures can be extended to include information about features the turtles/agents should have and rules according to which the agents should behave. The background, which in the example above is just green, can also be customized according to the purpose of the model. It is also possible to include geographical data from GIS applications or to completely ignore the background and only concentrate on the turtles.
In principle, many different social and natural phenomena can be modeled with Netlogo. An impressive number of example models is included in the model library. These examples come from a wide variety of disciplinary fields like archeology, social science, physics, chemistry and art, and are definitely worth exploring if you are interested to find out more about the capabilities of the program.

The El Farol Bar Problem

Let’s have a look at one example from the modeling library. The so-called El Farol Bar model played an important role in the history of social science simulations and economics. The idea and first implementation for this model was developed by the economist Brian Arthur.6 During the 1990s Arthur worked in Santa Fe and enjoyed going to a local Irish Bar called El Farol. Once a week there was live music in the bar and usually it got very crowded. Arthur had to make a strategic decision, either going to the bar and risk not having a good time (because of overcrowding) or staying at home. While thinking in terms of a single person is relatively easy, it gets much more complicated if we want to know what happens if everybody is confronted with a similar decision problem and decisions depend on the decisions of other people.
Beside his recreational preferences, Arthur’s choice to develop a model of the situation also had more profound academic reasons. As an economist he was dissatisfied with the common assumption of economic models, (a) that agents have perfect information of the situation they are in and (b) that agents can derive all significant consequences from this information.
To create a useful model, in contrast to the short verbal introduction just given, every part of the model (every aspect of the situation we want to include in the model) has to be represented explicitly and the rules of behavior have to be precisely determined. Even in the case that some aspects of the model situation are not known, those factors have to be included in the model via probabilities or the inclusion of randomness, otherwise the program is inconsistent and does not work. Here the implementation of the model within a programming language forces the user to follow the explicit rules of this language. Especially for historians and researchers working in the humanities this could lead to the readjustment of the style of research they are doing, accompanied with its own advantages and challenges.

Arthurs’s model consists of sixty agents choosing from a number of different strategies to decide if they should go to the bar or not. The strategies in the model are very simple ones and depend on the number of people who visited the bar the weeks before the decision. An agent could for example look only at the last week and then, if there were less than 60 people, decide to go to the bar this week. Other strategies encompass agents looking at more than one week or looking for cyclical patterns.

An interesting outcome of the simulation is that the utilization of the bar settles around an equilibrium around the sixty person threshold.

This graph shows the simulated bar attendance. The data were exported from Netlogo and visualized with Excel. We see that at the beginning of the graph there is a sharp increase of attendees in the bar. This is because agents refer to the random strategies they have been assigned to make the decision to go to the bar. After this we see a zigzag curve. Every week in which the attendance was over sixty the following week sees an attendance under sixty. There is no convergence toward the optimal utilization of the bar, because every agent always works with limited information about the whole system.


The Netlogo platform provides useful tools for researchers interested in simulations. Although modeling and simulations have traditionally been a topic of the natural sciences, recent years have also seen increased attention to models in the social sciences and humanities. Here are some points you should consider before starting you modelling endeavors:

• Realistic modelling requires a fairly good understanding of the phenomenon that’s being modeled. In the case of agents this means that you already need to know how they behave, ideally in the form of rules.
• In cases where this information is not available models can also be used to explore imaginary scenarios, like in the El Farol Bar model.
• Modeling takes time and effort. Although Netlogo helps and is fairly easy to understand, the construction and test of a model can require significantly more resources than data analysis alone.
• What’s the advantage of models over data analysis? A good model allows us to create alternative scenarios, which help us to answer “what would have happened if” questions. Certain internal dependencies of the system we study can only be seen in this way.
• The complexity of the model and the computer program, which implements it, can undermine our efforts to understand what’s going on. Model users have to be able to find a middle ground between opaque complicated and simple unrealistic models.

Whilst taking into account these restrictions, I think Netlogo provides an easy way to make your first steps in the area of simulation and modelling. The suitability of the platform for further more professional applications depends very much on the goals of the users. While in some areas Netlogo has become a legitimate and widespread tool, there also exists a large variety of alternatives to it. 7

Edited by Sam Mersch and Kaarel Sikk

  1. The first version of Netlogo was published by Uri Wilensky in 1999 and has been updated ever since. Version 6.1.1 was released in September 2019. See: Wilensky, U. & Stroup, W., 1999. HubNet. Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.
  2. Some recent examples include:
    Klein, Dominik, Johannes Marx, and Kai Fischbach. “Agent-Based Modeling in Social Science, History, and Philosophy. An Introduction.” Historical Social Research / Historische Sozialforschung 43, no. 1 (163) (2018): 7-27.
    Gavin, Michael. “An Agent-Based Computational Approach to ‘The Adam Smith Problem.’” Historical Social Research / Historische Sozialforschung 43, no. 1 (163) (2018): 308–36.
    Roman, Belinda. “An Agent-Based Model for the Humanities.” Digital Humanities Quarterly 7, no. 1 (2013).
    Gavin, Michael. “Agent-Based Modeling and Historical Simulation.” Digital Humanities Quarterly 8, no. 4 (2014).
  3. Throne, Jeremy. Modeling the Communications Circuit: An Agent-Based Approach to Reading in “N-Dimensions” In Youngman, Paul A., and Mirsad Hadzikadic, eds. Complexity and the Human Experience: Modeling Complexity in the Humanities and Social Sciences. Singapore 2014. pp. 105-119
  5. A useful tool to find information about Netlogo terminology is:
  6. Arthur, W. Brian. “Inductive Reasoning and Bounded Rationality.” The American Economic Review 84, no. 2 (1994): 406–11.
  7. See for example this pretty comprehensive Wikipedia entry about different agent-based modelling platforms:

Leave a Reply