NetLogo:如何识别最扩展的群集(补丁群集示例)? [英] NetLogo: how to identify the most extended cluster (patch cluster example)?
问题描述
我正在使用模型库中的补丁集群示例,我希望识别补丁数量最多=扩展最多的集群,然后将该集群变成红色.
I'm working with Patch Cluster Example from Model Library and I wish to identify the cluster with the highest number of patches = the most extended one and then turn this cluster red.
我知道我可以简单地
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]
的范围是什么...要为其着色,只需:
to know what is the extent of specific cluster with [plabel = 1]
, cluster with [plabel = 2]
, cluster with [plabel = 3]
... To color it, it is simply:
ask patches with [plabel = X] [
set pcolor red ]
但是,我是否可以自动识别扩展范围最大的群集并获得连接补丁的数量?
感谢您的所有建议,
* * *
哪个集群是扩展范围最大的集群?
推荐答案
您可以从NetLogo模型库中的Giant Component示例轻松修改find-all-components
过程.为了方便起见,您将需要添加全局变量
component-size
,giant-component-size
和giant-start-node
,
以及补丁属性explored?
.快速适应
(警告:未经测试!)类似于:
You can easily adapt the find-all-components
procedure from the Giant Component example in the NetLogo Models Library. For convenience, you will need to add global-variables
component-size
, giant-component-size
, and giant-start-node
,
along with a patch attribute explored?
. A quick adaptation
(warning: untested!) would be something like:
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
这篇关于NetLogo:如何识别最扩展的群集(补丁群集示例)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!