How to find all the agents who are not included in an agentset?

868 Views Asked by At

I have an agentset named giant-component, and I set all the agents' color to red:

ask giant-component [
    set color red
    ask my-links [
      set color red
    ]
  ]

Now I need to set all other turtles' color to blue. I know that the easy trick would be to first set all turtles' color to blue, and then colour all the giant component to red, but during the simulation it may get confusing for the user to see it. Is there a way to get all the turtles that are not inside giant-component?

2

There are 2 best solutions below

0
On

if it's true that the only turtles with color = red are the ones in your agent-set, you can set the color of all the other turtles like this:

ask turtles with [color != red] [set color blue]

edit

sorry i didn't read well the first line of the question.

I would do this in two ways:

1- set a turtle own to all turtles to true if they belong to the agent-set and then

ask turtles with [your-property = false][set color blue]

2- define two kinds of breed: one for the turtles in your agentset (let's say breed-in), the other for the turtles outside your agentset (let's say breed-out). Now you can just say:

ask breed-out [set color blue]
0
On

The answer above solves your problem of colouring. A more general answer that may be useful for other visitors to this question:

let not-giant turtles with [not member? self giant-component]

This creates the agentset of turtles who are not in the giant-component agentset