Skip to content

NetLogo and algorithm 0

  • code

This is a boring, esoteric post for most. The Code category should be a warning. Esoteric means intended for initiates. That is not the case, though. It is at the contrary intended for those who are not initiated into playing with NetLogo. That is a platform on which toy worlds can be built, set in motion and studied. That can be helpful. That can also be fascinating. Mister Sum has decided to turn part of the time that is freed because of the corona crisis into an account of his attempt to understand that crisis by building toy worlds of it and studying their behavior. The idea is that whoever reads this is enabled to recreate and change / improve those games and arguments themselves.

How to get NetLogo to work

NetLogo is not available for Android or iOS phones or tablets. If you have a PC with Microsoft Windows as the operating system or Apple OS / X or a Linux variant, you can download NetLogo here. Install it and note where the executable file is stored. Check if it starts up and exit the program.

How to get the example (algorithm 0) to work

Download and save this file as your personal copy of Algorithm 0 and give it the extension “.nlogo”. When this is done, double click on that file name. Your NetLogo software should now open and run it (otherwise open NetLogo itself and load the file manually). You will see the interface upon opening. It has a setup button. Press it. It also has a go button. press it too. You should now see the interface.

algorithm-0.netlogo after setup en go

The interface

I expect your first impulse is to try to understand what the algorithm is trying to tell. (It is a report of what an extremely simple model of an epidemic virus making its way through a population would tell us.) But that is not important now. What is important here is to get an idea of how the NetLogo platform supports individuals in formulating and executing such models. This focus directs our eye to the top left corner of the figure.

The first line contains some commands that are directed to the operating system (in this case: OS / X). The second line lists the name and location of the source code file for the model (under MS Windows, the first two lines are in reverse order). The third line has what we are looking for – the tabs: Interface, Info, Code (Interface is currently active). These three represent the different modes in which the NetLogo platform opens up to users. The Interface tab is for viewing running algorithms, the Info tab is for finding and explaining, and the Code tab is for writing and testing algorithms.

The interface opens to the person trying to use the algorithm for study and allows the user to specify different parameter values (parameters are global variables that can be set before the run). algorithm-0 has three parameters: generation number, incubation time and reproduction number.

The Info tab is for the modeller to inform the user about the intentions of the model. At the time of writing this text, the Info tab of Algorithm-0 is empty. But in due course I’ll fill it with snippets, harvested from blog entries from the Code category.

Code

The Code tab is for the modeller to design, test and run algorithm 0 code. The image below shows the content of the code of algorithm-0 as an example. To those new to NetLogo, this may seem like nonsense. Nevertheless, I give a few hints:

Source snippet of algorithm 0

There are three sections. The first is introductory and starts with extensions and ends before to setup. I use the matrix extension because it helps to print the results the way I want. The introductory section declares the global variables. The parameters (which are also global variables) are implicitly declared by naming them as elements of the interface and modeling them there (via the button that supports adding items. That’s how I made the three sliders). The last section has procedures. Procedures are opened with the keyword to, and ended with end. to setup prepares, to go executes and to print-numbers prints the results. to go works in cycles. This is the heart of the NetLogo platform: it supports thinking and modeling in generations. The counting of the processed cycles is done in the reserved variable: ticks.