I have a model that generates clusters of yellow patches and I am interested in looking at the frequency distribution of cluster sizes. To do this I have co-opted the code from 'Patch Clusters Example' in the Code Library of NetLogo. It seems to be working (see photos below) in terms of finding the clusters (although I would prefer that it did not count green patches in the clusters), but I can't figure out how to get the sizes (or patch counts) of each of these clusters. Ideally I would like to make a histogram of the frequency distribution of cluster sizes (excluding green patches) and be able to export that data.
Furthermore, it would be great if I could figure out a way to get the histogram of cluster size frequencies while the model is running.
The code I am using to get the clusters is right out of 'Patch Clusters Example' except I kill all the agents so I can read the numbers. Here it is...
to find-clusters
ask turtles [die] ;; this clears the board so I can see the clusters
loop [
;; pick a random patch that isn't in a cluster yet
let seed one-of patches with [(cluster = nobody)]
;; if we can't find one, then we're done!
if seed = nobody
[ show-clusters
stop ]
;; otherwise, make the patch the "leader" of a new cluster
;; by assigning itself to its own cluster, then call
;; grow-cluster to find the rest of the cluster
ask seed
[ set cluster self
grow-cluster ]
]
end
to grow-cluster ;; patch procedure
ask neighbors with [(cluster = nobody) and
(pcolor = [pcolor] of myself )]
[ set cluster [cluster] of myself
grow-cluster ]
end
;; once all the clusters have been found, this is called
;; to put numeric labels on them so the user can see
;; that the clusters were identified correctly
to show-clusters
let counter 0
loop
[ ;; pick a random patch we haven't labeled yet
let p one-of patches with [plabel = ""]
if p = nobody
[ stop ]
;; give all patches in the chosen patch's cluster
;; the same label
ask p
[ ask patches with [cluster = [cluster] of myself]
[ set plabel counter] ]
set counter counter + 1 ]
end
Thanks for your help!
Model BEFORE finding clusters
Model after finding clusters