适应模型的适应:如何在此处避免其他品种的密度

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

我的子模型的目的是模拟狼,避免人类密度大于其耐受极限的斑块。人为代理仅在城市斑块(灰色)上创建,但在NetLogo世界中也有草斑(棕色)和森林斑块(绿色)(有关视觉信息,请参见下面的界面选项卡链接)。人类特工是静止不动的,而狼特工如果对当前位置不满意,可以选择逃跑并找到新地点。

Interface Tab

globals [
  grass-patches
  forest-patches
  urban-patches
  percent-unhappy
  ]

breed [wolves wolf]

breed [humans human]

wolves-own [
  happy?
  anthro_tolerance
  ]

humans-own [
  human-population]

patches-own [
  human-density]


;; creating the urban patches
  set urban-patches patches with [pxcor < 10 and pycor < -30 ]
  ask urban-patches [set pcolor grey]
  ask urban-patches [set human-density human-density = pop-density]


to-report pop-density
      report count humans / (count urban-patches)
    end

为狼确定快乐的代码?水平并报告不满意的百分比是:

to update-wolves
  ask wolves [
    set anthro_tolerance 0.049
    ifelse (patch-here human-density >= anthro_tolerance)  ;;Error message
    [set happy? FALSE]
    [set happy? TRUE]
  ]
end

to update-globals
  set percent-unhappy (count wolves with [not happy?]) / (count wolves) * 100
end

我该如何编码ifelse happy?代表个体狼问自己:“我所贴片的人为密度是多少,它超出我的忍耐度了吗?”

此外,当我检查一个补丁时,所有市区补丁的人为密度变量均为零(即使该补丁上有一个人)。我该如何纠正?

netlogo agent
2个回答
1
投票

好的,我可以在这里看到几个问题。第一个是:

ask urban-patches [set human-density human-density = pop-density]

我不确定为什么没有抛出错误。但是无论如何,在NetLogo中,不要在C0变量值上使用'='。假设您的意图是要将计算的pop-density值分配给名为human-density的补丁变量,则该行应为:

set

关于您的实际错误。您有:

ask urban-patches [set human-density pop-density]

用于检索属于某个模型实体的变量的值的正确语法使用原语ifelse (patch-here human-density >= anthro_tolerance) ,因此您可以编写(未经测试):

of

但是您也可以利用以下事实:海龟可以访问其所在补丁的补丁变量。请注意,这并不能反向执行-乌龟到斑块是唯一的,因为一次只能将乌龟放在一个地方。但是,一个补丁上可能有很多乌龟,因此一个补丁不会知道访问哪个乌龟的变量。]​​>

使用该技巧可以使您:

ifelse ([human-density] of patch-here >= anthro_tolerance)

您可以使用另一个技巧,因为ifelse human-density >= anthro_tolerance 会将变量设置为true或false。这有点微妙,所以有些人不使用它,因为它比较难读,特别是如果您刚接触NetLogo。但是您可以替换:

ifelse

with:

ifelse human-density >= anthro_tolerance
[set happy? FALSE]
[set happy? TRUE]

从右到左阅读。首先,它应用比较运算符“ set happy? human-density < anthro_tolerance ,则报告为true;如果不是human-density < anthro_tolerance,则报告为false。然后将该值(human-density < anthro_tolerancetrue)提供给名为“ happy?”的变量。]​​>

我自己回答了问题的最后一部分,但是我想发表一下,如果有人像我一样对NetLogo感到好奇或陌生,我将如何解决该问题。

[当我检查单个城市补丁时,即使补丁上有一个人类代理(非常清楚),补丁的变量“人的密度”也将为0。我通过在[设置]和[执行]过程的末尾添加[update-patches]解决了这种纠结。

false

[通过在[setup]和[go]过程结束时调用此update-patches命令,当我检查补丁时,可以准确显示人的密度。


0
投票

我自己回答了问题的最后一部分,但是我想发表一下,如果有人像我一样对NetLogo感到好奇或陌生,我将如何解决该问题。

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