Determining max, min and mean turtle cluster size, as well as number of turtle clusters in netlogo

匆匆过客 提交于 2019-12-04 05:51:37

问题


See the code below intended for determining the number of settled turtle clusters (Red and grey turtles) out of a number of randomly distributed non-settled turtles (black), as well as the maximum, minimum and mean cluster size (radial extent) in a netlogo world/ interface.

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

The error i get is the following: MAX expected input to be a list but got the number 10 instead. I bet it would do the same for the mean and min functions as well because it is not recognizing base-settlers as an agent set. Any thoughts on how to transform this code to get the maximum, minimum and mean cluster size (Radial extent) and number of settled (red and grey) turtles?


回答1:


When you run the code, NetLogo highlights the line that generates the error. The problem line is print max cluster-size-growth. If you look earlier, you have let cluster-size-growth cluster-size + 1 and let cluster-size 1 prior to that. So cluster-size-growth is 1 + 1, or the number 2. The variable cluster-count-growth is also a number.

I think (but am not sure) that you are trying to calculate these two variables for each turtle and then take the max/mean/min over the turtles of the same type. If so, you need to create the variable for all the turtles first (that is, end the ask [] statement), and then do something like print max cluster-size-growth of base-settlers. You may also need to establish turtle-own variables for these as the local variable values will be lost at the end of the ask [] block.



来源:https://stackoverflow.com/questions/46533808/determining-max-min-and-mean-turtle-cluster-size-as-well-as-number-of-turtle-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!