2

I am writing a predator-prey model where the predator has a small internal machine learning model to decide which habitat it is going to hunt in.

If the predator has not had a successful hunt the day prior they assign themselves on of four strategies randomly. Each strategy has a unique habitat they can hunt in however despite they all move from random areas of the environment into a central location and then "paint it" with pen mode down and ignore the all other parts of the environment, I cannot figure out why.

I have tried many combinations of code to fix this and it always does the same thing. My latest attempt is the following


    if strat = "strat1" [ifelse any? patches in-cone 0 250 with [habitat = "rugged slope"]
      [set target-patch min-one-of patches in-cone 0 250 with [habitat = "rugged slope"] [distance myself]
 face target-patch
  fd 1]
      [face one-of patches with [habitat = "rugged slope"]
        fd 1]]

    if strat = "strat2" [ifelse any? patches in-cone 0 250 with [habitat = "gentle slope"]
      [set target-patch min-one-of patches in-cone 0 250 with [habitat = "gentle slope"] [distance myself]
 face target-patch
  fd 1]
      [face one-of patches with [habitat = "gentle slope"]
        fd 1]]

    if strat = "strat3" [ifelse any? patches in-cone 0 250 with [habitat = "rugged forest"]
      [set target-patch min-one-of patches in-cone 0 250 with [habitat = "rugged forest"] [distance myself]
 face target-patch
  fd 1]
      [face one-of patches with [habitat = "rugged forest"]
        fd 1]]

        if strat = "strat4" [ifelse any? patches in-cone 0 250 with [habitat = "gentle forest"]
      [set target-patch min-one-of patches in-cone 0 250 with [habitat = "gentle forest"] [distance myself]
 face target-patch
  fd 1]
      [face one-of patches with [habitat = "gentle forest"]
        fd 1]]

  ]
end

As you can see they are being told to go to certain areas but the result looks like this (picture attached)

The predators leave their den (pink) and despite having unique commands on where to go they simply meet in the middle and paint. turtles painting the map

Kilian Murphy
  • 321
  • 2
  • 14
  • Are the patch colours indicating habitat type? – JenB Apr 16 '20 at 18:37
  • Hi, yes they are! – Kilian Murphy Apr 17 '20 at 10:04
  • so, following from Charles's answer, if they can't see very far, then they will face a random patch of the correct type. If they are near an edge, then most of the patches of any type will be away from the edge, so they are drawn into the centre. Once they are in the centre, then habitats are in all directions and they move essentially in a random direction until they move too far out and the bulk is behind them again so move inward. If you turn off world wrapping, my guess is that they would randomly move everywhere. If so, this is your problem. – JenB Apr 17 '20 at 13:53

1 Answers1

3

I think that we might need to see more of your code to see how the areas are distributed. But the problem may be that patches in-cone 0 250 will look only at the patch that the predator is currently on (in radius zero). So, if (say) strat = "strat2" and the predator is on a patch with habitat = "gentle slope", the target patch will be the patch the predator is on. If the habitat is not "gentle-slope", which is perhaps the most likely, its path will be pretty aimless, even if there is a particular gentle-slope habitat nearby.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Charles
  • 3,888
  • 11
  • 13