1

I am writing a Netlogo model which only involves patches. I have managed to create a landscape consisting of patches of 6 different colours (each representing a different vegetation in my project) according to probability. So red patches have a probability of 10% to occur on each patch, yellow 5%, brown 20% and so on.

An example of my code where this probability is set up:

    let i random-float 1
    ifelse i + random-float 0.1 <= 0.8 ;random 0.1 threshold for environmental noise
      [ set pcolor green ]
      [ ifelse i + random-float 0.1 <= 0.9
        [ set pcolor yellow ]
        [ set pcolor blue ] ]

However, this creates a random pattern for each colour. But I would like to create a clustered spatial pattern for one of them.Specifically, in my landscape, I want the proportion of brown patches to be 50%. But if I were to set this 50% probability for every patch, the brown patches will be randomly distributed. How do I get it to occupy 50% of my landscape, but appear in a clustered pattern?

I tried creating the clustered pattern using the Moore neighbourhood, but that obviously changes the proportion of brown patches.

I hope this is somewhat clear. Thanks for any help in advance.

Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
lyh198
  • 61
  • 1
  • 6
  • http://stackoverflow.com/questions/19326781/adding-patch-clusters-in-a-landscape, http://stackoverflow.com/questions/20336364/how-to-create-cluster-patches-that-do-not-overlap-between-them, http://stackoverflow.com/questions/22121735/to-build-patch-clusters-at-large-spatial-scales, http://stackoverflow.com/questions/20997901/creating-a-random-shape-blob-of-a-given-area-in-netlogo/ – Seth Tisue Aug 06 '16 at 15:09

1 Answers1

1

You could seed based on your weights and then grow around the seeds. Here is a different approach: color all patches based on your weights, and then cluster the colors.

extensions [rnd]    ;use the rnd extension
globals [threshold]

to setup
  ca
  set threshold 2
  let _cw [[red 10] [yellow 20] [blue 70]]   ;colors with weights
  ask patches [set pcolor first rnd:weighted-one-of-list _cw [last ?]]
  repeat 20 [cluster]  ;adjust to taste
end

to cluster
  ask patches [
    if unhappy? [
      swap-pcolor
    ]
  ]
end


to swap-pcolor
  let _c pcolor
  let _p one-of neighbors with [pcolor != [pcolor] of myself]
  set pcolor [pcolor] of _p
  ask _p [set pcolor _c]
end

to-report unhappy?
  let _ct count neighbors with [pcolor = [pcolor] of myself]
  report (_ct < threshold)
end
Alan
  • 9,410
  • 15
  • 20
  • Hi Alan! Thanks so much! That worked mostly for me except for the nested lists part, where I'm trying to replace the weight number with a variable that was calculated in another procedure. I read I have to use 'list' to create a list with a variable? But I get the error 'expected a constant'...do you perhaps know how to solve this? – lyh198 Aug 05 '16 at 23:48
  • What I've tried so far let _cw list (list brown x) [ blue 0.2 ] ; x is variable set in previous procedure. Netlogo allows it but error surfaces that I can't use go in an observer context. – lyh198 Aug 06 '16 at 01:10
  • Your list is correct, but you'll need parentheses if you have more than two sublists. The `go` error is something else. It means you have written go so that it directly refers to a patch (or turtle) variable, instead of asking a patch (or turtle) to access its attribute. – Alan Aug 06 '16 at 01:43