NetLogo:如何识别最扩展的集群(补丁集群示例)?

时间:2016-04-22 04:16:07

标签: netlogo

我正在使用模型库中的修补程序集群示例,我希望识别具有最多修补程序数量的群集=扩展最多的群集,然后将此群集设置为红色。

我知道我可以简单地

count patches with [pvalue = X]  ; X - whatever plabel of patches in connected cluster

了解具体cluster with [plabel = 1]cluster with [plabel = 2]cluster with [plabel = 3]的范围...要为其着色,只需:

ask patches with [plabel = X] [
    set pcolor red ]

但是,我可以自动识别最扩展的群集并获取已连接补丁的数量吗?

感谢您提出的所有建议,

* * *

哪个群集是最扩展的群组?

Which cluster is the most extended one?

1 个答案:

答案 0 :(得分:2)

您可以轻松地调整NetLogo模型库中Giant Component示例中的find-all-components过程。为方便起见,您需要添加全局变量 component-sizegiant-component-sizegiant-start-node, 以及补丁属性explored?。快速适应 (警告:未经测试!)类似于:

    globals [component-size giant-component-size giant-start-node]
    patches-own [explored?]

    ;; find connected components and their sizes
    to find-all-components
      set giant-component-size 0
      set giant-start-node nobody
      ask patches [ set explored? false ]
      ;; keep exploring till all turtles get explored
      loop [
        ;; pick a node that has not yet been explored
        let start one-of patches with [ not explored? ]
        if start = nobody [ stop ]
        ;; reset the number of patches found to 0
        set component-size 0
        ;; at this stage, we recolor everything to light gray
        ask start [explore]
        ;; the explore procedure updates the component-size variable.
        ;; so check, have we found a new giant component?
        if component-size > giant-component-size [
          set giant-component-size component-size
          set giant-start-node start
        ]
      ]
    end

    ;; Finds all patches reachable from this node
    to explore ;; node procedure
      if explored? [ stop ]
      set explored? true
      set component-size component-size + 1
      ask neighbors4 with [pcolor = [pcolor] of myself] [
        explore
      ]
    end