user2359494
user2359494

Reputation: 733

NetLogo continue search under specific criteria

I'm simulating female animals dispersing from their mother's territory to search for their own territory. Essentially they need to find areas that are unoccupied by other female territories. Patches have a variable owner-fem that identifies which female it belongs to. Ideally, I'd like to have females:

  1. move to a patch,

  2. search within some radius around that patch for any other territory, and if there is another female's territory within that radius to

  3. move to another patch to start the search process again. Below is what I have so far but I don't think I'm using the in-radius correctly.

I'm not sure what the best way is to tell the female to continue searching until the condition is met. Any help would be much appreciated.

to female-disperse
  move-to one-of patches with [owner-fem = nobody]
  if [owner-fem] of patches in-radius 3 != nobody
    [
      move-to one-of patches with [owner-fem = nobody]
    ]
end

Upvotes: 1

Views: 65

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

If you want to it in "one shot", you could have them move directly to a suitable patch:

to female-disperse
  move-to one-of patches with [
    not any? patches in-radius 3 with [owner-fem != nobody]
  ]
end

Note that patches in-radius includes the patch that the turtle is on so there is no need for a separate move-to one-of patches with [owner-fem = nobody].

I don't know what your model requires, but if I were you, I might try to have them disperse a little more gradually. Here is another version that you could call from your go procedure (or any other procedure that runs "forever"):

to female-disperse
  ask females with [owner-fem != self ] [
    move-to one-of neighbors ; or however you want them to move
    if not any? patches in-radius 3 with [owner-fem != nobody] [
      set owner-fem self
    ]
  ]
end

In this version, all females that are not on a patch where they are the owner move to one of the neighboring patches. They then check if that new patch is suitable. If it is, they become the owner of it. If it is not, they just stop there for now: they will continue searching at the next iteration of go. You don't have to do it exactly this way; it could just be something loosely along those lines.

Upvotes: 2

Related Questions