Spacing agents in NetLogo based on territory size

2019-07-20 22:47发布

I'm trying to develop a model in NetLogo in which animal agents will be randomly distributed across space each time the model is started. However, the animals are territorial. Any suggestions on how to have the animals start with a circular territory of some size that can overlap with other animals to a certain extent but not completely? Below is the fragment of code I have started on it, but frankly I don't even know where to start. In the code below the animals aren't aware of the other territories when initialized. Any help would be much appreciated.

to setup  
    ask n-of (number-of-animals) TropForst 
    sprout-animals 1
    set territory patches in-radius ((sqrt ((territory-animals * 1000000)/ pi)) / 10)
end

标签: netlogo
1条回答
放我归山
2楼-- · 2019-07-20 23:37

this is one way to do it : you can change the center patch for each type of animals and you can set how much you want their territory to overlap.

breed [animals animal]
animals-own [territory]
to setup  
  clear-all
    create-animals number-of-animals / 2  
    [
      set color red
    set territory pathces-in-territory patch 10 10
      move-to one-of territory 
      ]


   create-animals number-of-animals / 2  
    [
      set color blue

      set territory pathces-in-territory patch 15 15 
      move-to one-of territory 
      ]


end

to-report pathces-in-territory [Center ]
  let ptr []
  ask Center [set ptr patches in-radius 5]
  report ptr
end

enter image description here

you can do it this way as well:

breed [animals animal]
animals-own [territory]
to setup  
  clear-all
    create-animals number-of-animals / 2  
    [
      set color red
    set territory pathces-in-territory patch 10 10 5
      move-to one-of territory 
      ]


   create-animals number-of-animals / 2  
    [
      set color blue

      set territory pathces-in-territory patch 15 15 10
      move-to one-of territory 
      ]


end

to-report pathces-in-territory [Center rd]
  let ptr []
  ask Center [set ptr patches in-radius rd]
  report ptr
end

enter image description here

since I like examples ;) this is another one which you can change the pcolor of each territory as well :

to-report pathces-in-territory [Center rd c]
  let ptr []
  ask Center [set ptr patches in-radius rd 
    ask  patches in-radius rd [set pcolor c]
    ]
  report ptr
end

enter image description here

and you can call the function like this : set territory pathces-in-territory patch 10 6 15 blue *Update

I should check it with netlogo later

create-animals number-of-animals  
        [
          set color blue
          move-to one-of patches with [not any? animals-here]
          set territory patches in-radius 5 

          ]

In case you want the territory to be defined for each individual animal you can check if there is no turtle in radius more that the territory for example 5 and then set the territory to patches around the turtle

   create-animals number-of-animals / 2  
    [

      move-to one-of patches with [not any? animals in-radius 5]
      set territory pathces-in-territory patch-here 2
      let h who
      ask territory [set pcolor h + 10 ] ; just for visual clarification 
      move-to one-of territory 
      ]

enter image description here

查看更多
登录 后发表回答