我正在尝试在NetLogo中开发一个模型,每次模型启动时,动物代理将随机分布在空间中。然而,动物是领土。关于如何让动物从一定大小的圆形区域开始的任何建议都可以在一定程度上与其他动物重叠但不完全?下面是我开始使用的代码片段,但坦率地说,我甚至不知道从哪里开始。在下面的代码中,动物在初始化时不知道其他地区。任何帮助将不胜感激。
to setup
ask n-of (number-of-animals) TropForst
sprout-animals 1
set territory patches in-radius ((sqrt ((territory-animals * 1000000)/ pi)) / 10)
end
答案 0 :(得分:1)
这是一种方法: 您可以更改每种动物的中心补丁,并可以设置您希望其区域重叠的程度。
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
你也可以这样做:
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
因为我喜欢这个例子;)这是另一个你也可以改变每个领域的pcolor:
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
你可以这样调用这个函数:set territory pathces-in-territory patch 10 6 15 blue
的 *更新强>
我应该稍后用netlogo查看
create-animals number-of-animals
[
set color blue
move-to one-of patches with [not any? animals-here]
set territory patches in-radius 5
]
如果您希望为每只动物定义区域,您可以检查半径范围内的乌龟是否超过该区域(例如5),然后将区域设置为乌龟周围的补丁
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
]