Search code examples
netlogo

can a turtle only variable number be assigned to patches?


I'm trying to design a model for the spread of infection from person to environment. Turtles have a hand contamination variable that shows the percentage of their hands that are contaminated. I'd like to give this number to patches that they're passing, but I'm getting an error saying it's a turtle-only variable. Is it possible to give a hand contamination number to the patch? This is part of my code:

turtles-own [hand contamination]
patches-own [p-contamination]

ask patches [set p-contamination hand-contamination]

Solution

  • A patch can't ever refer to turtle variables directly: What if there is more than one turtle there...which one? What if there are none?

    However, a turtle can access the variables of the patch it is standing on. So you would probably do this from the turtle's point of view: I think this also makes sense, logically, since it is the turtle visiting the patch, and contaminating it.

    ;; turtles contaminate the patch they are standing on
    ask turtles [ set p-contamination hand-contamination]
    

    Note that if there is more than one turtle on a patch, they will overwrite each other's values. So, you may need to add the amount, or otherwise blend the two values, rather than replace it.

    If there are more turtles than patches, or you really want the patch to be the thing that in control, the patch can look for turtles and acess their variables with OF:

    ask patches
    [ let visitors turtles-here
      if any? visitors
      [ set p-contamination ..some expression.. 
    

    So, there it depends on your needs, and you have to decide what that value is.

    • There is only ever at most one turtle:
      • [ Contamination ] of one-of visitors
    • Even if many turtles, pick one at random:
      • [ contamination ] of one-of visitors
    • Use the value of the most-contaminated visitor:
      • (max (sentence [ contamination ] of visitors))
    • Average the values of contamination
      • (mean (sentence [ contamination ] of visitors))
    • ...or some other expression that you choose

    Again, this is all overwriting the patch variable. If you need to take the patchs' current values for that variable, you need to decide how:

    If already contaminated, should it:

    • leave value alone
    • add turtle value to current value of P-Contamination
    • save the max of the two values
    • save the mean of the two values
    • blend them in some other way