如何在补丁变量约束下设置的随机 XY 坐标



我有一个名为 ID 和人口的变量的补丁,从 GIS 矢量导入。我要求这些斑块在每个特征 ID 的质心处萌芽种群,即海龟。但我希望海龟不要重叠,在补丁 ID 变量的约束内为每只海龟分配随机 xy 坐标。 例如,在补丁 ID = 1 的质心中喷出的可以在 ID = 1 的任何补丁中,但不能位于具有其他 ID 的补丁中。

> patches-own [ID centroid? pop]
> turtles-own [tID]
>
> ask patches with [ID >= 1] [sprout (pop * 0.1) [
>     set tID ID
>     let mypatch one-of patches with [ID = tID]
>     move-to mypatch   ]]

出现一条错误消息,指出我无法使用 tID 作为补丁上下文,因为 tID 仅供使用。

with语句中的tID使NetLogo感到困惑。 您可以通过设置局部变量来保存该值来解决此问题:

patches-own [ ID ]
turtles-own [ tID ]
to test1
clear-all
ask patches [ set ID random 3 ]
ask patches with [ID >= 1] [
sprout (random 10) [
set tID ID
let tID-local tID
let mypatch one-of patches with [ID = tID-local]
move-to mypatch   
]]
end

但我不确定这是否真的是你想要的。 你已经在要求ID >= 1的补丁来sprout海龟,这意味着它们已经在这些补丁上了。 试试这个,看看它看起来是否正确:

to test2
clear-all
ask patches [ set ID random 3 ]
ask patches with [ID >= 1] [
sprout (random 10) [
set tID ID
]]
end

我可能完全错了,你的意思是在同一ID补丁中洗牌人口,在这种情况下,忽略我的第二部分!

最新更新