Tilman Baum
Tilman Baum

Reputation: 39

use two different patch sizes in Netlogo

I use cells of 1/16 hectare which have a variable a. Some of these acquire the value of 1 during the simulation. The pattern is random and distributed. I want to create a second patch size of one hectare(4x4 patches), so that I can ask the following: show count hectares with [any-patches here with variable a = 1]

Any help very much appreciated!

Upvotes: 1

Views: 146

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

There is no way to declare different breeds of patches, let alone to have patches of different sizes. But what you want is perfectly doable without resorting to any of that. Your hectares are nothing but a set of smaller patches. Each hectare could be an agentset, and you could store those agentsets in a list.

Here is how to do it:

patches-own [ a hectare-id ]
globals [ hectares ]

to setup
  clear-all
  resize-world 0 31 0 31 ; use a 32 * 32 world to make things nicer

  ask patches [
    ; assign a hectare id based on the coordinates of the patch
    set hectare-id (word floor (pxcor / 4) "-" floor (pycor / 4))
  ]

  ; create a list of patch agentsets
  set hectares map [
    patches with [ hectare-id = ? ]    
  ] remove-duplicates [ hectare-id ] of patches

  ; this is part is unnecessary: it only serve to
  ; visually distinguish hectares in the view
  (foreach hectares n-values length hectares [ ? + 1 ] [
    ask ?1 [ set pcolor scale-color green (?2 / length hectares) -0.5 1.5 ]
  ])

  ask n-of 10 patches [ set a 1 ]

  ; filter the list of hectares, keeping only those
  ; where there is any patch with a = 1 in the agentset
  ; and print the length of that filtered list
  show length filter [ any? ? with [ a = 1 ] ] hectares

end

Upvotes: 1

Related Questions