确定最大,最小和平均龟群大小,以及netlogo中的龟群数量

时间:2017-10-02 21:13:33

标签: netlogo

请参阅下面的代码,用于确定多个随机分布的非定居龟(黑色)中已定居的龟群(红色和灰色龟)的数量,以及最大,最小和平均簇大小(径向) (在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.我敢打赌它也会对均值和最小值函数做同样的事情,因为它不会将基本定居者识别为代理集。有关如何转换此代码以获得最大,最小和平均簇大小(径向范围)和已定位(红色和灰色)龟数的任何想法?

1 个答案:

答案 0 :(得分:3)

运行代码时,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 []块的末尾丢失。