根据 netlogo 中距原点的距离计算海龟死亡率

Calculating turtle mortality based on distance from origin in netlogo

我正在编写一个程序 (Pass-Away-Space) 来计算从原点 (start-patch) 到世界各地的海龟死亡率。每只海龟根据其与原点的距离 (start-patch) 计算自己的死亡率。我尝试为此过程实现的代码如下:

    to Pass-Away-Space
  ask turtles [
  let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
    if chances >= 1 [die
      set dead-count dead-count + 1
    ]
  ]
end

我得到的错误是预期输入是一个数字但得到了列表。我不确定问题出在哪里,我想知道是否有人可以指出并纠正代码中的问题。

这里的问题是你的of turtles。由于 ask 过程一次影响一只海龟,上面过程中的每只海龟都在评估 所有 海龟的 [distance start-patch] 而不是它自己到起始补丁的距离。为了澄清,请检查以下设置:

globals [ start-patch ]

to setup
  ca
  reset-ticks
  crt 10 [
    setxy random 30 - 15 random 30 - 15
  ]
  set start-patch patch 0 0
end

to incorrect-example
  ask turtles [
    print ([ distance start-patch ] of turtles)
  ]
end

to correct-example
  ask turtles [
    print distance start-patch
  ]
end

比较 incorrect-examplecorrect-example 过程的打印输出,您会发现当您使用 [distance start-patch] of turtles 时,您会得到所有海龟的距离列表。当您 ask turtles 评估一个 turtles-own 变量(包括颜色、大小等)时,每只海龟都会自动访问该变量的自己的版本——无需指定是哪只海龟。因此,您的 pass-away-space 可能看起来更像下面的内容(未经测试):

to Pass-Away-Space
  ask turtles [
    let chances 1 - exp( -1 * mortality * (distance start-patch) )
    if chances >= 1 [
      die
    set dead-count dead-count + 1
    ]
  ]
end