goodgest
goodgest

Reputation: 418

Netlogo: How to select a turtle with the lowest ID for each stagnant turtle in each specified patch in the world?

I have a model that keeps turtles in several patches each. I would like to select a turtle with the lowest ID for each stagnant turtle in each specified patch in the world. For example, the answer is as follows. At patch coordinates (1, 0), five turtles stayed. And the ID of the turtle with the smallest ID was ID = 5 within the patch coordinates (1, 0). The following is a sample program. But this program is not intended. Is there something good syntax instead of the syntax "min-one-of turtles [who]"? I want your advice. Thank you.

ask (turtles-on patch 1 0) [
ask min-one-of turtles [who] [
set flag-1 TRUE
]

Upvotes: 0

Views: 398

Answers (1)

JenB
JenB

Reputation: 17678

I'm not sure what you mean by 'program is not intended'. Your problem is that you ask each of the turtles on patch 1 0 to identify the minimum who over all turtles. What you want is:

let targets (turtles-on patch 1 0)
[ ask min-one-of targets [who]
  [ set flag-1 TRUE
  ]
]

If the only thing you are going to do with the turtles on that patch is to select the lowest who, you don't need to set up the agentset explicitly. Instead:

ask min-one-of (turtles-on patch 1 0) [who]
[ set flag-1 TRUE
]

Upvotes: 3

Related Questions