我的子模型的目标是模拟狼代理如何避免具有高于狼的耐受阈值的人类密度的补丁。在运行我的模型时,sprout命令没有像我期望的那样在城市补丁中生成人类代理的数量。在城市补丁中创建人类的代码是:
问补丁[ if self =城市补丁萌芽-人类初始数字-人类]
这是我的界面选项卡的图像:NetLogo space
灰色是我的城市斑块,棕色是草地斑块,绿色是森林斑块。为什么我的人类智能体没有出现在灰色(城市)补丁中,并且智能体的数量反映了最初的人类数量?
下面是创建人工代理的代码:code
我已经指定了位于城市(灰色)补丁中的人工代理的xy坐标,但当我运行模型时,只有一个人工代理出现。我如何正确地编码初始数字人类以使用sprout命令进行连接?
发布于 2020-06-10 16:34:12
正如我想您现在已经发现的那样,在一组补丁中随机分配一定数量的海龟的最简单方法是使用create-turtles
而不是sprout
。这是因为sprout
在每个正在萌发海龟的补丁上创建了指定数量的海龟,因此您需要权衡要创建的总数量和补丁的数量。但是,如果您希望实现均匀分布而不是随机位置,则该选项非常有用。下面的代码可以同时完成这两个任务。
globals [urban-patches n-humans]
to setup
clear-all
set urban-patches n-of 20 patches
ask urban-patches [set pcolor gray]
set n-humans 100
make-humans-sprout
make-humans-create
end
to make-humans-sprout
ask urban-patches
[ sprout n-humans / count urban-patches
[ set color red
set xcor xcor - 0.5 + random-float 1
set ycor ycor - 0.5 + random-float 1
]
]
end
to make-humans-create
create-turtles n-humans
[ set color blue
move-to one-of urban-patches
set xcor xcor - 0.5 + random-float 1
set ycor ycor - 0.5 + random-float 1
]
end
请注意,对xcor
和ycor
的调整是因为sprout
和move-to
始终将乌龟放置在补丁的中心,并且没有用于在特定补丁的随机位置放置的原语。
https://stackoverflow.com/questions/62291371
复制相似问题