The Eco-0 Framework

Many agent-based models are customizations of the basic Eco-0 framework:

eco-0.nlogo

The Eco-0 Interface

The Eco-0 interface consists of two buttons:

Every control (button, slider, switch, etc.) has a corresponding editor that allows us to set the control's attributes and to associate a procedure or global variable with the control. For example, using the button editor we can specify that when the init-model button is clicked, the init-model procedure should be executed by the observer:

Checking the "Forever" box means that when the update-model button is clicked it repeatedly calls the update-model procedure:

This repeated calling of the update-model procedure is called the model update loop. It is the engine that drives the model. Repeatedly clicking the update-model button alternately pauses and resumes the model update loop.

The Eco-0 Code

Of course we must define the init-model and update-model procedures. In addition to these, six additional helper procedures will need to be defined.

Initializing the Model

A model consists of turtles, patches, and global variables. These are initialized by the init-model procedure, which is executed by the observer:

to init-model
  clear-all
  random-seed new-seed
  init-globals
  create-turtles 5
  ask patches [init-patch]
  ask turtles [init-turtle]
  reset-ticks
end

The observer begins by calling NetLogo's clear-all procedure. (Most NetLogo procedures also have nicknames that can be used. The nickname for clear-all is ca.) The clear-all procedure resets all global variables to zero, and calls clear-turtles, clear-patches, clear-drawing, and clear-output.

Simulation often involves modeling random events. NetLogo provides several random number generators. For example:

set fitness random 100 ; sets fitness to a random integer in the interval [0, 100)

Of course random number generators really generate pseudo random numbers starting with a seed value. The command:

random-seed new-seed

sets the seed to a random value so that each time the model runs the sequence of random numbers generated will be different.

Recall that global variables are declared at the beginning of the implementation as follows:

globals [average-age total-energy maximum-weight]

By default, all global variables are initialized to zero. The init-globals procedure allows programmers to initialize globals to non-zero values:

to init-globals
  ; initialize globals here
end

Next, five turtles are created using NetLogo's create-turtles procedure (crt). The five turtles will have random colors and headings. They will all be located in the center of the screen.

Next, the observer asks each patch to execute the init-patch procedure and each of the five turtles to execute the init-turtle procedure.

Recall that each patch has five pre-defined attributes (position, color, label, etc.), and each turtle has 13 pre-defined attributes (position, color, shape, heading, etc.) Additional attributes can also be defined. When a patch executes the init-patch procedure, or when a turtle executes the init-turtle procedure, it simply sets some of these attributes to non-default values using NetLogo's set (assignment) command. At the moment these procedures only contain comments:

to init-patch
   ; initialize patch attributes here
end

to init-turtle
   ;initialize turtle attributs here
end

Finally, NetLogo's reset-ticks procedure is called. This procedure resets the pond's clock to zero. It also resets any plotter pens.

Updating the Model

Recall the model update loop repeatedly calls the update-model procedure:

to update-model
  update-globals
  ask patches [update-patch]
  ask turtles [update-turtle]
  tick
end

The update-globals procedure updates any global variables. The observer asks each patch to execute the update-patch procedure and each turtle to execute the update-turtle procedure. At the moment these procedures only contain comments. The Eco-0 framework is customized by providing implementations for these procedures.

to update-globals
  ; update global here
end

to update-patch
  ; add patch commands
end

to update-turtle
   ; add turtle commands
end

The tick procedure advances the model clock one tick. It also updates all plotter pens.

Customizing the Eco-0 Framework

Turtles with Drinking Problems