Reputation: 733
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
Upvotes: 2
Views: 621
Reputation: 1894
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
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
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
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
]
Upvotes: 1