在Netlogo中使用两种不同的补丁大小

时间:2016-08-27 11:23:02

标签: netlogo

我使用1/16公顷的细胞,其中有一个变量a。其中一些在模拟过程中获取1的值。模式是随机的和ditributed。我想创建一个占地一公顷(4x4补丁)的第二个补丁大小,这样我可以问以下:显示计数公顷[任何补丁这里变量a = 1] 任何帮助非常感谢!

1 个答案:

答案 0 :(得分:1)

没有办法宣布不同品种的补丁,更不用说有不同大小的补丁了。但是你想要的是完全可行的,而不是诉诸任何一个。你的公顷只不过是一组较小的补丁。每公顷可以是一个代理集,您可以将这些代理集存储在列表中。

以下是如何操作:

patches-own [ a hectare-id ]
globals [ hectares ]

to setup
  clear-all
  resize-world 0 31 0 31 ; use a 32 * 32 world to make things nicer

  ask patches [
    ; assign a hectare id based on the coordinates of the patch
    set hectare-id (word floor (pxcor / 4) "-" floor (pycor / 4))
  ]

  ; create a list of patch agentsets
  set hectares map [
    patches with [ hectare-id = ? ]    
  ] remove-duplicates [ hectare-id ] of patches

  ; this is part is unnecessary: it only serve to
  ; visually distinguish hectares in the view
  (foreach hectares n-values length hectares [ ? + 1 ] [
    ask ?1 [ set pcolor scale-color green (?2 / length hectares) -0.5 1.5 ]
  ])

  ask n-of 10 patches [ set a 1 ]

  ; filter the list of hectares, keeping only those
  ; where there is any patch with a = 1 in the agentset
  ; and print the length of that filtered list
  show length filter [ any? ? with [ a = 1 ] ] hectares

end