|Getting Started With NetLogo|
|Written by Mike James|
|Monday, 11 March 2013|
Page 1 of 4
NetLogo is a remarkable language that is fine tuned for particular types of application - agent-based simulation. Oh, yes, and did I mention it was Logo.
If you think that this educational language died out, NetLogo demonstrates the inevitable truth that no computer language ever dies out!
NetLogo really is a language that deserves to be better known in the wider programming community simply because there are some applications that it is perfect for and not to use it would be taking the long way round. However, there a number of difficulties in getting started with it.
The first is that it is based on Logo and this presents a barrier to anyone not lucky enough to have encountered Logo at school, say. Logo isn't like the popular object-oriented languages that we are all so familiar with. It isn't really a functional language either. The best way to describe it is as a stack-oriented language, but I have no doubt that there are Logo enthusiasts who would take issue with this description.
The second big problem with learning NetLogo is that it is an agent-based simulation language. What this means is that you can create multiple agents very easily and get them to do things equally easily. NetLogo is a quasi parallel language - to be more precise its a simulated SIMD (Single Instruction Multiple Data) language. This makes it ideal for simulations where you have lots of similar agents doing similar things such as population studies, simulating gas molecules, traffic flows and so on. However, don't think that NetLogo is limited to the situations I have listed - it is a completely general purpose language with some special features.
Perhaps the third problem is the documentation. This is very good, but really doesn't give the beginner or the experienced programmer a very easy route into getting started with NetLogo - this is, I hope, where this article comes in. Its objective is, not to teach you the whole of NetLogo, but to simply get you started with the basic concepts and to get you to a point where the excellent documentation becomes useful to you.
The good news is that NetLogo is open source and it runs on Linux, Windows or Mac OS. Simply download, install and run - there should be no problems.
Running A Program
Assuming that you have NetLogo downloaded and running the first thing that you see is a window containing a menu, three tabs (more of which later) and a black window. All a bit mysterious with no real clue as to what to do next.
If you look at the bottom of the Window you will see a horizontal panel and a text box labeled "observer". This terminology doesn't make much sense when you first meet it. In fact it s is just an immediate evaluation entry line. You can type in a line of code and it will be obeyed at once.
This means we can get "Hello World" out of the way at once. Simply type:
into the observer line and press return. You will see the message appear in the command center box above.
Now we need to move on to a program that does a little more.
If you want to enter a long program then the command center isn't good way to do the job. The Code tab takes you to a code entry editor where you can build up larger programs. Everything you enter into to the code editor has to be in the form of a function. Logo functions are just like functions you will find in other languages but the syntax is slightly strange. For example
The name of the function is greet and the keyword to assigns the lines of code until you reach end.
So how do you run the code in a function?
One way is to simply type the function's name into the command center:
You could write an entire NetLogo program as a function and run it from the command center in this way but this is not the most usual way of doing the job.
Now we come to the first unusual feature of NetLogo. The IDE that you use to develop the program is part of the user interface. To allow the user to control the program you have created you place buttons and other controls onto the interface region and define what they do.
For example, to run the greeting function you would place a button on the interface area and in the dialog box that appears you simply enter the name of the function or NetLogo code you want to run when the button is clicked:
There are other important elements in the dialog box which we will return to but notice the Agents drop down This alters where the button sends its command - in this case to the observer which is the command line. So clicking this button has the effect of typing greet on the command line and hence the function runs.
|Last Updated ( Monday, 11 March 2013 )|