I'm trying to implement a monitor in the user interface that displays the average value of a variable shared by a breed of turtles (turtles own). Does anyone know of a method of collecting all the values, adding them together and dividing by the quantity of turtles to get the value or know of an easier method?
Turtles are mobile agents in NetLogo that can be placed anywhere in the world, can look like anything (e.g., shape, color, size), and can move around. They are the primary type of agents in NetLogo models. The turtle primitive reports a specific turtle with the given number.
breed is a special primitive that can only be placed in the top of a netlogo code tab. Using breed , you can define custom kinds or breeds of turtles.
The turtles-own keyword, like the globals, breed, <breeds>-own, and patches-own keywords, can only be used at the beginning of a program, before any function definitions. It defines the variables belonging to each turtle. If you specify a breed instead of "turtles", only turtles of that breed have the listed variables.
forward is a turtle primitive that makes the asked turtle move forward on a straight patch for a provided number of units.
If the variable that each turtle has is shell-size
, for example, then:
print mean [shell-size] of turtles
will do it. It might be useful to know how to do this by hand, so that you can do other calculations if you want. Here's one way:
print (sum [shell-size] of turtles) / (count turtles)
Here's another
let total 0
ask turtles [set total total + shell-size]
print total / (count turtles)
Obviously, you'll want to replace the print
statements with whatever suits your needs. For a monitor, you should be able to enter this code directly into the interface, or wrap it up in reporter and then use that in the monitor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With