vendredi 1 avril 2016

Error using "n-of" in NetLogo to select specific patches

I am new to NetLogo and I am working on a deforestation model, where farmers are my agents. They have a ID variable (lotid-farmer) that matches a ID in the patches (lotid-patch) that they own. Basically, farmers check how much money and labor they have to deforest some forest patches or abandon some of their agricultural patches (pcolor = red) in their farms. By the end of the latter procedure, farmers have a "n-aband" value calculated, which is the number of patched they will abandon (randomly) within their farms (pcolor = yellow). This is the piece of code that was supposed to do that:

ask farmers [
...
     if pcolor = red and lotid-patch = [ lotid-farmer ] of self [     ; Asks the farmer to randomly convert a # of the agricultural patches without maintenance to regrowth...
        ask n-of n-aband patches [ set pcolor yellow ]                ; ... among all agricultural patches own by the farmer
        ] 
...

However, when I run the code, farmers start "abandoning" patches that they do not own. I think that is because I am not setting up a proper "restriction" when I use "ask n-of n-aband patches" but I thought that that should be implicit in the "if" statement I have in the line above, no? I have also tried:

ask n-of n-aband patches with [ pcolor = red and lotid-patch = [ lotid-farmer ] of self ] [ set pcolor yellow ]

But I run into a error:

A patch can't access a turtle variable without specifying which turtle.
error while patch 390 414 running OF
  called by procedure CALCULATE-DEFORESTATION
  called by procedure GO
  called by Button 'Go'

Any suggestions on how to get this piece working? Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire