A typical NetLogo agent-based model starts with two global procedures:
to init-model
ca ;
clear all
random-seed new-seed ; randomly seed random number
generator
init-globals ; initialize all global variables
ask patches [init-patch] ; initialize attributes of each patch
crt init-population ; create init-population turtles
ask turtles [init-turtle] ; initialize attributes of each turtle
end
to update-model
if finished?
[
print "Simulation halted" ; displays in the Command Center
stop ;
halts the control loop
]
tick ;
increment the global tick counter
update-globals ; update all globals
ask patches [update-patch] ; update attributes of each patch
ask turtles [update-turtle] ; update attributes of each turtle
update-plots ; update any plotters in the interface
end
The methods invoked (init-turtle, update-turtle, etc.) can be thought of as over-ridables
Usually the init-model procedure is invoked by pressing the INIT button on the interface:
The update-model procedure is iterated by pressing the UPDATE button:
Repeatedly pressing the UPDATE button starts, pauses, and resumes the NetLogo control loop:
while [true] [update-model]
See abm.nlogo for a working template.