在指定代理的位置和sprewout命令时出现问题。

问题描述 投票:0回答:1

我的子模型的目的是模拟狼代理如何避免人类密度超过狼的容忍阈值的补丁。当运行我的模型时,sprout命令并没有像我期望的那样在城市补丁中生成人类代理的数量。在城市补丁中创建人类的代码是。

ask patches [ if self = urban-patches [sprout-humans initial-number-humans]]

这是我的界面标签的图片。NetLogo空间

灰色是我的城市补丁,棕色是草地补丁,绿色是森林补丁。为什么我的人类代理人没有出现在灰色(城市)补丁中,代理人的数量反映了初始人类数量?

以下是创建人类代理的代码。代码

我已经指定了人类代理人的xy坐标位于城市(灰色)补丁内,但当我运行模型时,只有一个人类代理人出现。我如何正确地编码initial-number-humans与sprewout命令连接?

netlogo agent
1个回答
1
投票

我想你现在已经发现了,在一组补丁中随机分布一组数量的海龟的最简单方法是使用 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

请注意,对 xcorycor 因为 sproutmove-to 总是将乌龟放在补丁的中心位置,而没有将乌龟放在特定补丁的随机位置的基元。

© www.soinside.com 2019 - 2024. All rights reserved.