【问题标题】:NetLogo: create patchy landscape - sweep 3 parameters?NetLogo:创建不完整的景观 - 扫描 3 个参数?
【发布时间】:2015-08-27 17:56:43
【问题描述】:

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

  • radius - 通过半径值定义聚集块(黄色)的大小
  • 网格 - 簇之间的距离
  • %_weak - 我希望景观中有多少块黄色的补丁??

我想以交互方式使用所有这 3 个参数。但是,在距离、网格和 %_weak 的某些组合中,我没有获得与滑块 %_weak 定义的相同的 count patches with [pcolor = yellow]

请问,我怎样才能在不扩大世界大小的情况下保留所有滑块?我不希望将我的世界的维度扩展到超过 601x601。

我的模型在这里可用:http://ulozto.cz/xdSN2ikr/turtles-in-grid3-nlogo,或代码在这里:

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

【问题讨论】:

标签: netlogo


【解决方案1】:

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

  • 可以通过询问绿色斑块之一来计算其半径'radius'中的斑块,
  • clusters_number 可以通过计算取决于所选 grid 大小的绿色块来计算。
  • 黄色补丁总数为cells-in-cluster * clusters_number
  • 您的代码无法处理超过(Total number of Yellow Patches / Count patches) * 100 的 %weak 值

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

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

【讨论】:

  • 我认为不需要foreach sort...你不能在那里做ask吗?
  • 我想从一个角落开始并添加黄色补丁,随机询问是否这样做,但无论如何根据问题是有更多黄色补丁,限制它们无济于事。我应该在我的答案中添加这一点。
  • 为了限制黄色斑块,增加另一个检查点来查看黄色斑块的总数会更准确,然后允许对附近斑块重新着色的最后一个斑块会有一些限制它可以变黄多少块。
  • 嗨@Marzy,非常感谢您的帮助和代码简化。实际上,原则是在网格中排列黄色斑块。我想从绿色创建网格只是为了“定位”我的黄色补丁的中心,然后在周围创建黄色的“斑点”。确实,我必须对“RateOfYellowPatches”使用 if 条件。拜托,我怎样才能创建斑块表面,但从黄色斑块(在世界网格中本地化的相同颜色的斑块块)。再次感谢你,我真的很感激,我学到了很多!
  • 只需将绿色转换为黄色,或在创建中心色块的同时重新着色附近的色块。在第二种情况下,您根本没有绿色补丁。
猜你喜欢
  • 1970-01-01
  • 2015-08-08
  • 2021-05-25
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多