Reputation: 4090
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.
I know that I can simply
count patches with [pvalue = X] ; X - whatever plabel of patches in connected cluster
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 ]
However, can I automatically identify the most extended cluster and get the count of connected patches?
Thank you for all suggestions,
* * *
Which cluster is the most extended one?
Upvotes: 4
Views: 257
Reputation: 9610
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
Upvotes: 3