I have a NetLogo model in which agents retrieve multiple lists of variables from other agents. The order in which these lists are returned is crucial, because variables in each list are associated with each other. However, I believe lists are returned from other agents in a random order each time. For example, take the following simplified test case:
turtles-own [testlist1 testlist2 testlist3 testlist4]
to setup
random-seed 1
clear-all
create-turtles 5
ask turtles [
create-links-with other turtles
set testlist1 []
set testlist2 []
set testlist3 []
set testlist4 []
set testlist1 lput [who] of self testlist1
set testlist2 lput [who] of self testlist2] ;identical to testlist1
end
to go
ask turtles[
set testlist3 reduce sentence [testlist1] of link-neighbors
show testlist3
set testlist4 reduce sentence [testlist2] of link-neighbors
show testlist4]
end
For my use case, values in testlist3 and testlist4 should be in the same order, but their orders differ at random. Output:
(turtle 2): [0 3 1 4]
(turtle 2): [3 4 1 0]
(turtle 3): [4 1 0 2]
(turtle 3): [1 0 2 4]
(turtle 0): [4 2 3 1]
(turtle 0): [3 4 2 1]
(turtle 1): [0 4 2 3]
(turtle 1): [4 2 3 0]
(turtle 4): [0 2 1 3]
(turtle 4): [0 3 2 1]
My question: What is the best way to return multiple lists (such as testlist
and testlist2
above) from an agent-set in the same order in a given procedure?
Replacing link-neighbors
with turtle-set sort link-neighbors
doesn't work, because after converting the sorted list back to an agent-set, the agents in the agent-set are called in a random order. If at all possible, I'd prefer not to have to refactor the entire model from lists to matrices using the matrix
extension.