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

自闭症网瘾萝莉.ら 提交于 2019-12-10 17:47:32

问题


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?


回答1:


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




回答2:


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]


来源:https://stackoverflow.com/questions/30956921/how-to-find-all-the-agents-who-are-not-included-in-an-agentset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!