netlogo - 如何使用 Netlogo 中的行为空间获取海龟到达不同 10 个补丁的滴答时间?

有 100 block 绿地和 10 只海龟。每当乌龟来到一 block 绿色的地方时,它就会变成红色。所以过了很长一段时间,所有的绿色补丁都会在不同的时间点变成红色。我想使用 BehaviourSpace 将这 100 个不同的滴答时间写入 Excel 工作表。我也想运行这个 100 次。即我想要 100 组 100 个不同的滴答时间。

我编写了一个代码,当一只乌龟来到绿色补丁时,补丁变成红色,我在它下面写了“show ticks”。因此,当绿色补丁变成红色时,滴答时间会显示在屏幕底部的命令中心上。滴答时间示例:34,56,78,98,99,...,1234。有 100 个不同的时间。

breed [InfMosquitoes InfMosquito]

to setup
  clear-all

  set-default-shape InfMosquitoes "butterfly"
  create-InfMosquitoes  num-infected-mosquitoes-red
   [
    set color red
   ]

ask turtles [
    set size 1
    setxy random-xcor random-ycor
     ]

ask turtles[
      ifelse coin-flip?
          [ifelse coin-flip? [set heading 0][set heading 90]]
          [ifelse coin-flip? [set heading 180][set heading 270]]
     ]

ask n-of num-humans patches [set pcolor green]

   show num-infected-mosquitoes-red

  reset-ticks
end

to go
  ask turtles
  [
          right random 360
          forward 1
      ask InfMosquitoes[
      if pcolor = green 
          [
            set pcolor red 
            show ticks   
          ]
       ]
  ]
    tick
end


to-report coin-flip?
  report random 2 = 0
end

我想知道我应该在 BehaviourSpace 表中写什么。我知道 Repititions:100。我想知道我应该在其他命令框上写什么。

最佳答案

您可以创建一个全局变量并将其初始化为一个列表。

globals [
...
ticks-recorder
...
]

to setup
...
  set ticks-recorder []
...
end

然后,您将把它添加到列表中,而不是在命令中心打印刻度号:

to go
  ask turtles
  [
          right random 360
          forward 1
      ask InfMosquitoes[
      if pcolor = green 
          [
            set pcolor red 
            set ticks-recorder lput ticks ticks-recorder   ; this is the line I've changed
          ]
       ]
  ]
    tick
end

您最终会得到 ticks-recorder,它是当补丁颜色变为红色时所有刻度的列表。

然后,您只需将 ticks-recorder 指定为 BehaviorSpace 中的 reporter。

请注意,使用此解决方案,您最终会得到一个被报告的列表。例如,假设您的列表包含值 1 和 2。在 NetLogo 中,这被视为 [1 2]。这意味着,如果您在 Excel 中打开输出文件,报告者所在的单元格将包含文本 [1 2],这意味着您将无法对其进行任何数学运算。 你可能关心也可能不关心这个,我不知道(例如,你可能使用不同的编程语言处理你的输出,而你取消了记者的名单)。 但我认为这会变成另一回事。

https://stackoverflow.com/questions/58179228/

相关文章:

selenium - Appium/WinAppDriver 无法找到上下文菜单 - 但仅在某些机器

bash - 如何使用 Shell 脚本在 mac 中覆盖环境变量

python - 将部分训练的 scikit-learn 模型存储或检查点到磁盘

python - 使用 Python 类型模块指定序列或列表的长度

reactjs - 错误 : [mobx] Computed values are not allo

c# - 程序集绑定(bind)重定向 : How and Why?

angular - 重新加载页面后保持元素位置 - 拖放 cdk Angular 7

android-studio - Android studio 在执行 lint 时找不到 kotl

python - 如何在 keras 中训练顺序模型,给出一个列表作为输出和输入?

google-chrome - 一些 Font Awesome 图标在 Chrome 中不显示