Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetLogo: Finding the average value of a set of turtles

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?

like image 594
algorhythm Avatar asked Apr 11 '14 14:04

algorhythm


People also ask

What is turtle NetLogo?

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.

What does breed do in NetLogo?

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.

What does NetLogo turtle own?

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.

What does Fd do in NetLogo?

forward is a turtle primitive that makes the asked turtle move forward on a straight patch for a provided number of units.


1 Answers

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.

like image 189
Mars Avatar answered Oct 21 '22 10:10

Mars