NetLogo:创建斑驳的景观 - 扫描3个参数?

时间:2015-08-27 17:56:44

标签: netlogo

我有一个非常具体的问题: 我想制作一个由3个滑块定义的网格景观:

  • radius - 按半径值
  • 定义成块补丁(黄色)的大小
  • 网格 - 团块之间的距离
  • %_ weak - 我希望从我的风景中看到多少补丁?

我想以交互方式使用所有这三个参数。但是,在距离与网格与%_weak的特定组合中,我不会获得与滑块%_weak定义的相同globals [ cells-in-cluster ; # of patches in 1 cluster clusters_number ; # total number of clusters over world ] to setup clear-all setup-patches end to setup-patches ask patches [set pcolor black] ; calculate # of patches in 1 cluster, to calculate how many clusters do I need ask patch 0 0 [ set pcolor green ask patches in-radius radius [set pcolor green] set cells-in-cluster count patches with [ pcolor = green ] ; calculate # of clusters set clusters_number round ((world-width * world-height / 100 * %_weak) / cells-in-cluster) ask patches with [pcolor = green] [set pcolor black] ] ; create grid over world - depends on radius value and clusters-number value crt 1 [ let $n 0 ; actual number ofturtles on this patch let $s 0 ; current number of turtles on a side of square pattern - 1 set heading 0 ask patch-here [set pcolor red] repeat clusters_number ; number of needed turtles [ hatch 1 jump Grid ; make one turtle and move set $n $n + 1 ; increment count of curent side ask patch-here [set pcolor red] if $n > $s ; if side finished... [ right 90 set $n 0 ; turn and reset count ask patch-here [set pcolor red] if heading mod 180 = 0 [ set $s $s + 1 ; if headed up or down, increment side count ] ] ] die ] ask turtles [die] ; ask all turtles to die ; create halo effect around "clusters-numbers" patches with radius value ask patches with [pcolor = red] [ ask patches in-radius radius [ set pcolor yellow ] ] end

enter image description here

请问,如何在不扩大世界尺寸的情况下保留所有滑块?我不想将我的世界的维度扩展到601x601以上。

我的模型可在此处获取:http://ulozto.cz/xdSN2ikr/turtles-in-grid3-nlogo或代码:

{{1}}

1 个答案:

答案 0 :(得分:3)

我对你的程序的逻辑感到困惑,%weak受Grid和Radius限制,在封闭环境中你应该调整绿色补丁的半径或距离以获得你想要的比率:

  • 群集中的小区可以通过询问其中一个绿色小块来计算其半径中的小块' 半径',
  • 来计算
  • clusters_number可以通过计算绿色补丁来计算,这取决于所选的网格大小。
  • 黄色补丁总数为cells-in-cluster * clusters_number
  • 您的代码不会处理超过(Total number of Yellow Patches / Count patches) * 100
  • 的%弱值

这是您的代码的简化版本:

globals [
  cells-in-cluster    ; # of patches in 1 cluster
  NumberOfClusters     ; # total number of clusters over world 
  RateOfYellowPatches

]
to setup   
  clear-all   
  SetTheBasicGrid
  setPatchedInRadius  

end

to SetTheBasicGrid

  ask patches with [pycor mod Grid = 0 and pxcor mod Grid = 0]
  [
    set pcolor green
  ]
  set NumberOfClusters  count patches with [ pcolor = green ]
  ask one-of patches with [pcolor = green] 
  [
    set cells-in-cluster count patches in-radius radius 
  ]

  set RateOfYellowPatches   ((count patches *  %_weak) / cells-in-cluster )
end

to setPatchedInRadius
  ask patches with [pcolor = green] 
    [ if  count patches with [pcolor  = yellow ] <= RateOfYellowPatches   
      [
          ask patches in-radius radius 
          [ 
            set pcolor yellow 
          ]
      ]
    ]
end