![]() |
|||
Home Download Help Forum Resources Extensions FAQ NetLogo Publications Contact Us Donate Models: Library Community Modeling Commons Beginners Interactive NetLogo Dictionary (BIND) NetLogo Dictionary User Manuals: Web Printable Chinese Czech Farsi / Persian Japanese Spanish
![]() |
NetLogo Models Library: |
![]() |
If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web |
This model is from Chapter Eight of the book "Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo", by Uri Wilensky & William Rand.
This model is in the IABM Textbook folder of the NetLogo Models Library. The model, as well as any updates to the model, can also be found on the textbook website: http://www.intro-to-abm.com/.
This model provides the basic structure of the code for a HubNet model. For this reason, the model is very simple: all that each participant can do is move their turtle around the world.
This model can be used as a template to build more complex participatory simulations.
The model first loads HubNet. It then listens to HubNet's messages, and does one of four things: If a new users has entered, it creates a turtle for that user. If a user presses the 'forward' button, it asks the user's turtle to move forward. If a user clicks somewhere in their turtle's view of the model, it makes their turtle face that direction. And if a user leaves HubNet, it removes that turtle from the world.
HubNet activities are used from two different interfaces. First, there is the server interface, from where you manage the simulation for all participants involved. Second, there is the client interface, that each participant uses to control their own little part of the simulation.
SETUP -- This button resets the simulation and opens the HubNet Control Center, from which you can see all the connected clients. Clicking LOCAL in the Control Center will allow you to create a client on your own computer so you can test the activity from a user's point of view.
LISTEN-CLIENTS -- This button runs the activity: as long as LISTEN-CLIENTS is pressed, client messages are processed and the model is updated accordingly.
COLOR PATCHES -- This button gives a new random color to each patch.
When using the model as a client, the view follows the turtle that you are controlling, showing only the part of the world immediately surrounding it.
The client interface is just as simple as the server interface:
FORWARD -- This button causes your turtle to move forward by one unit.
LOCATION -- This monitor shows you the (x, y) coordinates of your turtle in the world.
You can also click directly on the view: this will cause your turtle to face the location that was clicked, thereby allowing you to control the direction in which the turtle is going.
When the turtles move over a black background, it is hard for a participant to tell that their turtle is indeed moving, unless there is another turtle in its immediate neighborhood. This is what the COLOR PATCHES button is for: the colorful background makes the movement of the turtle apparent.
The lesson here is that designing an HubNet activity requires you to take the individual agent's point of view into account in addition to the "outside observer" point of view that is commonly used in NetLogo models. In this sense, HubNet activities are very much in the spirit of agent-based modeling.
Note that HubNet messages are always sent between clients and the HubNet server, even if the model doesn't do anything with the messages. If HubNet messages are not fetched, they will queue up for the user to deal with later, using hubnet-fetch-message
.
Our HubNet model is very simple, but our listen-clients
procedure is already fairly long. For a more complex model, it could be worth spending a bit of time to separate the message handling logic from the actions that actually take place when different kinds of messages are received. Stripped to its core, listen-clients
could be something like this:
to listen-clients
while [ hubnet-message-waiting? ] [
hubnet-fetch-message
ifelse hubnet-enter-message?
[ add-client-turtle ]
[ ifelse hubnet-exit-message?
[ remove-client-turtle ]
[ handle-client-action ]
]
]
end
You would then need to fill out add-client-turtle
, remove-client-turtle
and handle-client-action
with the code that we moved out of the procedure. If you wanted to push the modularization even further, you could have a different procedure for each possible client actions instead of handling them all in the handle-client-action
procedure.
This kind of modularization allow you to build complex models without loosing track of the high-level logic of your code.
The main NetLogo features used here are, unsurprisingly, the HubNet related primitives that allow you to build a collaborative simulation.
Notice, also, that the COLOR PATCHES button is a bit different from the others: it has a little patch icon in its upper left corner, indicating that the code associated with it (set pcolor one-of base-colors
) applies to all patches, just like if it had been enclosed inside an "ask patches
" block.
This model originally based upon the Template HubNet model from the library. All the models in the HubNet Activities folder of the library more or less share the same basic structure.
This model is part of the textbook, “Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo.”
If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.
For the model itself:
Please cite the NetLogo software as:
Please cite the HubNet software as:
Please cite the textbook as:
Copyright 2012 Uri Wilensky.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.
(back to the NetLogo Models Library)