Search code examples
netlogopatchneighbours

Choosing patch analysing neighboors netlogo


I am trying to model an community that engages in shifting cultivation. For that I want each household to change the patch every year. Each household can have a different crop area, depending on time and number of people working. I want them to be able to choose a patch that has the amount of forest patch need to open their crop. For example, one household has a crop area of 3, so the new location needs to be a forest patch with two other forest patch neighbors. Any idea how can I specify that?

Thanks


Solution

  • Here is a possible solution:

    patches-own [ patch-type ]
    breed [ households household ]
    
    to setup
      clear-all
      ask patches [ set patch-type one-of ["forest" "rock" "sand"] ]
      let forest-neighbors-needed 2
      create-households 100 [
        let candidate-locations patches with [
          not any? households-here and
          patch-type = "forest" and
          count neighbors with [ patch-type = "forest" ] >= forest-neighbors-needed
        ]
        ifelse any? candidate-locations [
          move-to one-of candidate-locations
        ] [
          error "No suitable location found!"
        ]
      ]
    end
    

    This method is not the most efficient, because it rebuilds the set of possible location for each household it creates, but if your model is not two big, it shouldn't make much of a difference.

    Note that you don't give us a lot of detail about how your model is organized, so I had to make a few assumptions. Next time, please tell us bit more: what breeds to you have, what are their variables, etc. Ideally, post a bit of code showing what you already tried.