Download PDF - Complex Adaptive Systems Modeling

Transcript
North et al. Complex Adaptive Systems Modeling 2013, 1:3
http://www.casmodeling.com/content/1/1/3
// Add the model input.
addInput("innovationProbability", 0.001)
}
The generated “UserGlobalsAndPanelFactory.groovy” file may contain additional example code that will not be activated given that it is commented. Commented code lines
may begin with either “//” or “/*” and will be ignored by the simulation runtime. The three
new lines added above create graphical buttons in the model runtime window that provide
functions to setup and run the model. Changes to the “UserGlobalsAndPanelFactory.
groovy” file are now complete. The “UserLink.groovy” file does not require any modifications at this time.
Next, you should open the “UserObserver.groovy” file, which will contain code that
defines how to initialize the model and what happens at each simulation tick. Again,
there will be example code in the generated “UserObserver” that can be ignored or
deleted. The “UserObserver” requires two methods: “setup” and “go,” which are listed
below:
// Define the model builder.
def setup(){
// Remove any existing turtles.
clearAll()
// Build a new set of turtles.
createTurtles(20){
setShape("person")
setColor(gray())
forward(1)
}
// Distribute an initial innovation.
ask (turtles().first()) {
innovation = yellow()
setColor(innovation)
}
}
// Define the model time step routine.
def go(){
// Give each turtle a chance to act.
ask(turtles()){ act() }
}
The “setup” method is called when the “setup” button in the runtime window is
pressed. The button was previously created in the “UserGlobalsAndPanelFactory,” and
the functionality is provided in the “UserObserver.” The setup routine first clears the
model of any existing turtles using “clearAll()” for the case when the model had already
been run. Next the “setup” method creates a set of 20 turtles, sets the shape of each
turtle to the “person” icon shape, sets the initial color of the icon to gray, and moves
the turtle agent one step forward. Finally, setup retrieves the first turtle and sets its
Page 21 of 26