Farms Using Area Subdivision
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
STEP WISE AREA SUBDIVISION by James Steiner
WHAT IS IT?
This model demonstrates a method of generating square clusters of patches of varying sizes using progressive subdivision.
HOW IT WORKS
A farm is a turtle that manages a square cluster of patches. By making 4 copies of the farm, and dividing the patches in the cluster among the copies, then removing the original farm, a cluster of patches is divided into four clusters.
By repeating the subdivision process, we can create clusters with the desired properties.
HOW TO USE IT
Set the min-farm-size, max-farm-size, and min-farms to the desired values. Note: this model does not do any sanity checking on these inputs.
min-farm-size: desired minimum number of patches that a cluster may contain. such farms can not be further subdivided.
max-in a cluster: desired maximum number of patches that a cluster may contain. such farms are always subdivided.
min-farms: the desired minimum number of farms. If the number of farms is less than this number, and there are any farms larger than the minimum size, one of them will be subdivided.
THINGS TO NOTICE
The ratio of the count of farms of various sizes are rather consistant.
Since the selection of a farm to divide is from an even distribution, as the number of farms increases, and since these are smaller and smaller farms, it becomes more likely that the selected farm will be a small farm, and the likelyhood that a remaining large farm will remain whole increases.
EXTENDING THE MODEL
You can use the concepts and techniques in this model to create sub-divided patch clusters for your own models.
RELATED MODELS
See the voronoi models in the Models Library or on TurtleZero.com to see another way to subdivide patches based on a "root" patch or turtle.
Comments and Questions
globals [ ;; for farm color assignments new-color ;; the last color provided by the next-color utility new-color-inc ;; the direction (plus or minus) to shift the shade new-color-base ;; the shade of gray that is the base color for the current color series stop? ] patches-own [ farm-id ] breed [ farms farm ] farms-own [ farm-root farm-patches farm-size ] to start-up setup-farms end to reset ;; (for this model to work with NetLogo's new plotting features, ;; __clear-all-and-reset-ticks should be replaced with clear-all at ;; the beginning of your setup procedure and reset-ticks at the end ;; of the procedure.) ;; sanity check on mean-farm-size if desired-mean-farm-size < min-farm-size and seek-mean-farm-size? [ user-message (word "The desired mean farm size can't be less than the minimum farm size,\n" "or the desired mean can never be reached!\n\n" "Please change either the minimum farm size or the desired mean farm size." ) stop ] clear-all set stop? false reset-ticks end to go end to setup-farms reset ;; create the initial farm ask patch min-pxcor min-pycor [ sprout-farms 1 [ set farm-size world-width initialize-farm ] ] while [ stop? != true ] [ build-farm tick ] histogram-farm-size end to build-farm ;; first, enforce MAX-FARM-SIZE, split any farms over the max size. ;; using ONE-OF just to slow things down in demo! ;; --remove for production model ( ifelse ( any? large-farms ) [ ask one-of large-farms [ split-farm ] ] ( seek-mean-farm-size?) [ ifelse ( mean [ farm-size ] of farms > desired-mean-farm-size and any? splittable-farms ) [ ask one-of splittable-farms [ split-farm ] ] [ set stop? true ] ] [ ;; otherwise ;; enforce MIN-FARM-COUNT ;; split randomly, until at least enough farms ifelse ( count farms < desired-min-farm-count and any? splittable-farms ) [ ask one-of splittable-farms [ split-farm ] ] [ set stop? true ] ] ) end to position-farm let scale farm-size / 2 set size scale setxy ( [ pxcor ] of farm-root + scale ) ( [ pycor ] of farm-root + scale ) end to highlight-borders ask farm-patches with [ any? neighbors4 with [ farm-id != [ farm-id ] of myself ] ] [ set pcolor [ color + 3 ] of farm-id ] end to-report large-farms report farms with [ farm-size > max-farm-size ] end to-report splittable-farms report (farms with [ farm-size > min-farm-size ] ) end to split-farm ;; do not even try to split if this farm is only 1 unit wide. if farm-size <= 1 [ stop ] ;; OK, split! let xx 0 let yy 0 let new-size farm-size / 2 ;; create new farm-roots relative to current farm root ;; (do this relative to farm-root so that farm turtle's location is coupled to ;; determinig patches for splitting, etc) let new-farm-roots [ patches at-points map [ ?1 -> (list (first ?1 * new-size) (last ?1 * new-size) ) ] [ [ 0 0 ] [ 0 1 ] [ 1 1 ] [ 1 0 ] ] ] of farm-root ask new-farm-roots [ sprout-farms 1 [ set farm-size new-size initialize-farm ] ] ;; this farm is removed die end to initialize-farm ;; store ID of this patch, ;; so we can use farm-root to id the lower-left corner of farm ;; letting us put farm turtle anywhere, if we =hoose. set farm-root patch-here set farm-patches patches with [ pxcor >= [ xcor ] of myself and pxcor < [ xcor + farm-size] of myself and pycor >= [ ycor ] of myself and pycor < [ ycor + farm-size] of myself ] set shape "farm" set color next-color ask farm-patches [ set pcolor [ color ] of myself set farm-id myself ] position-farm end to-report next-color ifelse new-color = 0 [ set new-color gray ] [ set new-color wrap-color (new-color + 10 ) ] report new-color end to-report between [ value minimum maximum ] report (minimum <= value and value <= maximum) end to histogram-farm-size set-current-plot "by farm size" histogram [ log farm-size 2] of farms end
There are 5 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Farms Using Area Subdivision.png | preview | Preview for 'Farms Using Area Subdivision' | about 3 years ago, by James Steiner | Download |
This model does not have any ancestors.
This model does not have any descendants.