How to report agent variables in a consistent order in Netlogo's Behaviourspace

216 Views Asked by At

Picture of my behaviourspace menu

I'm working on an agent based model where a variable (agentvariable1) owned by all agents changes every tick. I want to report a time series for the values of this variable for every agent using Behaviourspace.

However, when I measure runs using the following reporter

[agentvariable1] of turtles

the values that are reported for agentvariable1 are randomly shuffled, because "turtles" calls all turtles in a random order, which is different every tick. Because of this the data that is exported is not usable to create a time-series.

Is it posstible to create a reporter in Behaviourspace that reports the values of the agentvariable1 in a sequence that remains the same every tick?

2

There are 2 best solutions below

1
Matteo On BEST ANSWER

Using sort on an agentset creates a list of those agents sorting them by some criteria. In the case of turtles, they are sorted by their who which means that their relative order will always be the same.

However you cannot directly do [agentvariable1] of sort turtles, because of expects an agent/agentset but you are giving it a list.

What you can do is creating a global variable as a list: at each tick the list is emptied, and later all turtles (sorted as per sort) will append their value to the list. That list is what you will report in your Behavior Space.

globals [
  all-values
]

turtles-own [
  my-value
]

to setup
  clear-all
  reset-ticks
  create-turtles 5
end

to go
  set all-values (list)
  
  ask turtles [
    set my-value random 10
  ]
  
  foreach sort turtles [
    t ->
    ask t [
      set all-values lput my-value all-values
    ]
  ]
  
  show all-values
  
  tick
end
0
Luke C On

As an alternative to Matteo's answer (which is perfectly suitable and directly addresses your intention, I just present another option depending on preference) you could also pair the variable of interest with some turtle identifier and report that as a list of lists. This adds a bit of flexibility in cases where the number of turtles increases or decreases. In this example, I use who and xcor for simplicity, but you may want to create your own unique turtle identifier for more explicit tracking. With this toy model:

to setup
  ca
  crt 5
  reset-ticks
end

to go
  ask turtles [
    rt random 30 - 15 
    fd 1
  ]
  tick
end

to-report report-who-x
  report list who xcor
end

At any point, you can call the list with [report-who-x] of turtles to get a list of lists. With a behaviorspace setup such as:

enter image description here

you get an output that would look something like:

enter image description here