max-n-of

 

max-n-of reports an agentset that contains a specified number of agents with the highest value of a given reporter. For example, if we wanted to create a model where the largest 5 turtles are divided in half, we would write the code below:

ask max-n-of 5 turtles [size] [
    set size (size / 2)
    hatch 1
]

Things to keep in mind when using max-n-of:

In the model example below, we have some people who represent an absurdly simple economy. At each tick, a randomly picked turtle executes a trade by picking another turtle randomly and giving that turtle 5 of its money. This exchange is represented with a temporary link between the two turtles. We use max-n-of to change the richest three turtles' color to blue. We also use min-n-of to change the poorest 3 turtles' color to red.

 

Try it Yourself