Search code examples
netlogobehaviorspace

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


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?


Solution

  • 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