Operations with two NetLogo agents

I have two agents. Are there any functions to find:

  • Agent agents that are present in both (intersection)
  • Agent agents that are present in one and not the other

I find it very difficult to implement this manually, especially when it is necessary inside the triple ask

Ideal use would be similar to with syntax:

 let cross set1 and-in set2 let uniq set1 with [color = red] not-in set2 

Simple things like "Is Agent A in Agent X?" are problematic

+8
intersection netlogo
source share
1 answer

For the first, use the turtle-set primitive. For the second, do you need a member? primitive member? who also works with agents. Thus:

 to setup ca create-turtles 10 [set color red] create-turtles 10 [set color blue] let red-ones turtles with [color = red] let blue-ones turtles with [color = blue] ;join 2 agent sets let joinset (turtle-set red-ones blue-ones) show joinset let even-ones (turtles with [who mod 2 = 0]) ;subtract even-ones from red-ones let subtractset red-ones with [not member? self even-ones] show subtractset end 
+11
source share

All Articles