Eleanor
Eleanor

Reputation: 41

In Netlogo, how to measure turtle or patch own variables in behavior space in the "measure runs using these reporters" space

I am running my Netlogo model in behavior space. In my model, I created a turtles-own variable called consumption-rate. I want to export the consumption-rate of each turtle for every tick of my run. From my understanding of behavior space, I would somehow put consumption-rate in the box that says "Measure runs using these reporters" in order for it to be exported, but I keep getting different errors every time I try. For instance I mostly get an error that says "Experiment aborted due to syntax error: Expected reporter". I also need to export a patches-own variable I created called quality for every patch in my model at each tick, and I have the same issue. All the examples for this part of behavior space online just show "count turtles" or something similar. Am I able to export a turtle or patch variable there? If so, what code would I use?

I took a shot into the blue and tried using primitives like "show consumption-rate" or "report consumption-rate". I am unsure of the format of code I would even begin to use to give me those exports. Any advice or help? I also tried just typing in "consumption-rate" or "quality" in the "Measure runs using these reporters" box, but got an error saying I can't use a turtle or patch variable in an observer context, how can I make those into the observer context? Anyway around that?

   patches-own [ quality ]
   turtles-own [ consumption-rate ]


to setup-patches
  ask patches
  [set quality (2 + random 8)
  set pcolor scale-color green quality 1 10 ]
end 

to Go
  ask turtles
  [ calculate-consumption ] 
end

to calculate-consumption
  set consumption-rate ( [ quality ] of patch-here ) / ( strength-of-competition * count turtles-here )
end

Upvotes: 0

Views: 1058

Answers (1)

JenB
JenB

Reputation: 17678

You have a conceptual mismatch. There is no problem in exporting a turtle or patch variable in BehaviorSpace, but you haven't told NetLogo which variable to export. You need to specify whether it's that variable for all turtles, or only some turtles or whatever.

Here's a modified version of your code so that it is complete and self-contained.

globals [strength-of-competition]
patches-own [ quality ]
turtles-own [ consumption-rate ]

to setup
  set strength-of-competition 0.4
  ask patches
  [ set quality (2 + random 8)
    set pcolor scale-color green quality 1 10
  ]
  create-turtles 300 [setxy random-xcor random-ycor]
end 

to go
  ask turtles
  [ calculate-consumption ] 
end

to calculate-consumption
  set consumption-rate quality / ( strength-of-competition * count turtles-here )
end

Run this with a BehaviourSpace setup that has [consumption-rate] of turtles as the reporter. Also put 2 in the time limit. You will get the output you requested.

A good tip for working with BehaviorSpace when you are new to it, is to set up a monitor on your interface for each value that you want to save in your output. Get the monitors showing what you want to export and then simply take the code that you ended up with and put it in the reporter box. The advantage of doing the monitor step is that it forces you to get your thinking right without going down the rabbit hole of whether it is a BehaviorSpace issue.

Upvotes: 3

Related Questions