【问题标题】:Determining max, min and mean turtle cluster size, as well as number of turtle clusters in netlogo确定最大、最小和平均海龟集群大小,以及 netlogo 中海龟集群的数量
【发布时间】:2017-10-02 21:13:33
【问题描述】:

请参阅下面的代码,用于确定许多随机分布的未定居海龟(黑色)中定居的海龟集群(红色和灰色海龟)的数量,以及最大、最小和平均集群大小(径向范围)在 netlogo 世界/界面中。

globals[ cluster-size cluster-count cluster-size-growth cluster-count-growth ]

to setup
  clear-all
  ask patches [ set pcolor white ]
  create-turtles 1000 [
    set color black
    set label-color blue
    setxy random-xcor random-ycor
    set cluster-size 1
  ]
  ask n-of 5 turtles [
    ask turtles in-radius one-of [1 2 3] [
      set color one-of [red grey]
    ]
  ]
end

to cluster-collect
  let base-settlers turtles with [ color = red ]
  let consp-settlers turtles with [ color = grey ]
  ask base-settlers [
    set cluster-count count consp-settlers in-radius cluster-size
    set cluster-size-growth cluster-size + 1
    set cluster-count-growth count consp-settlers in-radius cluster-size-growth
    if cluster-count >= 1 [
      ifelse ( cluster-count-growth - cluster-count != 0 ) [
        set cluster-size cluster-size + 1
      ][
        print count base-settlers with [ count turtles with [ color = grey ] >=  1 ]
      ]
    ]
  ]
  print [ max cluster-size-growth ] of base-settlers
  print [ max cluster-count-growth ] of base-settlers
  print [ mean cluster-size-growth ] of base-settlers
  print [ mean cluster-count-growth ] of base-settlers
  print [ min cluster-size-growth ] of base-settlers
  print [ min cluster-count-growth ] of base-settlers
  print [ standard-deviation cluster-size-growth ] of base-settlers
  print [ standard-deviation cluster-count-growth ] of base-settlers
  print [ variance cluster-size-growth ] of base-settlers
  print [ variance cluster-count-growth ] of base-settlers
end

我得到的错误如下:MAX expected input to be a list but got the number 10 instead. 我敢打赌它也会对均值和最小值函数做同样的事情,因为它没有将基本定居者识别为代理集。关于如何转换此代码以获得最大、最小和平均集群大小(径向范围)和定居(红色和灰色)海龟数量的任何想法?

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    当您运行代码时,NetLogo 会突出显示产生错误的行。问题行是print max cluster-size-growth。如果你早点看,你之前有let cluster-size-growth cluster-size + 1let cluster-size 1。所以cluster-size-growth是1 + 1,也就是数字2。变量cluster-count-growth也是一个数字。

    我认为(但不确定)您正在尝试为每只海龟计算这两个变量,然后对同一类型的海龟取最大值/平均值/最小值。如果是这样,您需要先为所有海龟创建变量(即结束ask [] 语句),然后执行print max cluster-size-growth of base-settlers 之类的操作。您可能还需要为这些建立turtle-own 变量,因为局部变量值将在ask [] 块的末尾丢失。

    【讨论】:

    • 我将集群变量设为全局变量,但似乎 netlogo 即使在 ask [ ] 命令之外仍然存在 print max cluster-size-growth of base-settlers 问题。我得到的错误是MAX expected input to be a list but got the number 11 instead.
    • 那是因为你在 [] 中有max。试试print max [ cluster-size-growth ] of base-settlers。抱歉,我在原始评论中没有使用正确的语法。
    猜你喜欢
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多