Beginners Interactive NetLogo Dictionary (BIND)
Farsi / Persian
NetLogo User Community Models
## WHAT IS IT?
Macal and North [WSC 2008] ABM Example written as a discrete event simulation (DES).
This is a DES (event-driven) version. Instead of time-stepping, the simulation keeps a list of times that patches change colors and "jumps" from one patch color change time to the next. This simulation uses the Array extension to keep the times, organized as a binary heap. Each time is associated with one patch; the patch that changes color at that time. The association of patch to time is kept using the Table extension.
## HOW IT WORKS
Each cycle, the earliest time is removed from the heap, the patch associated with the time is retreived from event table (and removed from the table), and the patch doPatchStuff is called. As part of the doPatchStuff procedure, each turtle is checked to see if it can move and, if so, it is moved until
The Table extension does not allow for two keys with the same value. Therefor, before adding a time to the heap array and event table, the table is checked to see if the time already is in the table. If it is, then the time is incremented slightly, until a time not in the table is calculated, and this is the time that is used for the event. There is another implementation, ExampleABM_Event_Driven_2.nlogo, where agents are kept in a list, so that all agents performing an action at the same time are placed in the table.
## HOW TO USE IT
The only input is the number of turtles. Notice that doTurtleStuff is not directly called in the go procedure. Rather, it is called by the doPatchStuff procedure.
## THINGS TO NOTICE
It is instructive to single step the simulation. In this simulation, there is one tick when a patch changes color. Prior to the patch actually setting its new color, all of the turtles are moved to the time of the patch color change. Then the patch color is set. This process continues until all turtles have reached the edge of the grid.
The results from this simulation should be compared with ExampleABM_TimeStepped.nlogo simulation, where the same model is implemented with the traditional time-stepped simulation mechanism. There, one tick is one minute. The average turtle age and the total simulation time are the same for the same number of turtles, but the execution profile is different. In this implementation, about 2.88 doPatchStuff events occur in a simulated minute, where the time-stepped version does all 144 patches every minute. In the time stepped version, most of the patches do not change color during a tick (in fact about 2.88 change color per tick, on average). In the time-stepped simulation, every turtle is checked once per tick. In this version every turtle is checked for every patch color change event, or 2.88 times per minute. This means that for less than 50 turtles, this simulation will have fewer total doTurtleStuff and doPatchStuff calls, and for more than 50 turtles this simulation will have more total doTurtleStuff and doPatchStuff calls.
## THINGS TO TRY
## EXTENDING THE MODEL
Try implementing the list of event times using a sorted list or a sorted array instead of a heap.
## NETLOGO FEATURES
This model uses the Array and Table extensions to implement an event queue.
## RELATED MODELS
See also ExampleABM_EventDriven_2.nlogo and ExampleABM_TimeStepped.nlogo for different implementations of this model. ExampleABM_TimeStepped is a classical agent-based time stepped simulation. ExampleABM_EventDriven_2.nlogo schedules both patch color changes and turtle moves and is nearly 50 times more efficient.
## CREDITS AND REFERENCES
See https://www.geeksforgeeks.org/binary-heap/ for information on heaps.
This model has been coded by Emmet Beeker, email@example.com. Feel free to contact me with comments or questions.
(back to the NetLogo User Community Models)