Search code examples
databasenetlogoagentrecording

How to record location of patches visited by a turtle in net logo, and reord data for each turtle


I am using NetLogo to create a simulation modelling bees visiting flowers and pollinating them. To understand genetic diversity I'd like each turtle to record the location of a flower it visits, every time it visits one. This means I then know the last recorded flower could have been pollinated by any of the flowers above it in the generated list. I have modelled the flowers as yellow patches that are generated randomly, they turn blue once a bee has collected pollen from them and then white if a bee has pollinated them, although this only happens if they have been visited when the bee has enough pollen to pollinate.

This information would also be needed to clearly be individual to each turtle. My hope would be if after running it could generate a file with each turtle and a list underneath them of the locations of flowers they visited in sequential order.

I imagined it working by every time a bee visits a flower it stores the x and y coordinate of that flower.

 to store-location
  ask turtles [
     if ((pcolor = yellow) or (pcolor = blue) or (pcolor = white))
       set xy_list fput (list int xcor int ycor) xy_list
     ]
   ]
 end

Solution

  • I haven't tested this, but it looks almost correct to me. In fact, I am surprised it didn't work (you didn't explain the problem). But instead of:

    set xy_list fput (list int xcor int ycor) xy_list
    

    have

    set xy_list fput patch-here xy_list
    

    Your approach of putting a new entry in the list is fine. But the way you have it will give you lists of lists. Instead, you can store the patch (so you don't need to take int) and then you will have a single level list with items like patch 1 4 which will be easier to read later.

    Then, when the run is complete, you can write the lists to a file. If you need help with that bit, please ask a separate question.