Skip to main content

4.3) Working With Agentsets (ASK)


An agentset is exactly what its name implies, a set of agents. An agentset can contain either turtles, patches or links, but not more than one type at once. But what's powerful about the agentset concept is that you can construct agentsets that contain only some turtles, some patches or some links. For example, all the red turtles, or the patches with pxcor evenly divisible by five, or the turtles in the first quadrant that are on a green patch or the links connected to turtle 0. These agentsets can then be used by ask or by various reporters that take agentsets as inputs.

The command “ask” tells all members of an agentset (or one individual agent) to do the code in the following brackets. All members of the agentset do the code (sequence of commands), one at a time (ticks), or effectively the agents in the set gets randomly selected and do the task one after the other, but at the same modelling time. When you ask a set of agents to run more than one command, each agent must finish before the next agent starts. One agent runs all of the commands, then the next agent runs all of them, and so on. So, how are the following examples different?

ask turtles
   [
   buy
   sell
   update-bank-account
   ]


ask turtles [buy]
ask turtles [sell]
ask turtles [update-bank-account]