NetLogo:如何识别最扩展的集群(补丁集群示例)?
NetLogo: how to identify the most extended cluster (patch cluster example)?
我正在使用模型库中的 补丁集群示例,我希望识别补丁数量最多的集群 = 扩展最多的集群,然后将此集群变为红色.
我知道我可以
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 ]
但是,我可以自动识别最扩展的集群并获取连接的补丁数吗?
感谢您的所有建议,
*
*
*
哪个集群最广泛?
您可以轻松地从 NetLogo 模型库中的 Giant Component 示例中改编 find-all-components
程序。为了方便起见,您需要添加全局变量
component-size
、giant-component-size
和 giant-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
我正在使用模型库中的 补丁集群示例,我希望识别补丁数量最多的集群 = 扩展最多的集群,然后将此集群变为红色.
我知道我可以
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 ]
但是,我可以自动识别最扩展的集群并获取连接的补丁数吗?
感谢您的所有建议,
* * *
哪个集群最广泛?
您可以轻松地从 NetLogo 模型库中的 Giant Component 示例中改编 find-all-components
程序。为了方便起见,您需要添加全局变量
component-size
、giant-component-size
和 giant-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