NetLogo two agentsets operations

前端 未结 1 1510
忘掉有多难
忘掉有多难 2020-12-19 03:45

I have two agentsets. Are there functions for finding:

  1. An agentset of agents that are present in both (intersection)
  2. An agentset of agents that are pr
相关标签:
1条回答
  • 2020-12-19 04:05

    For the first one you use the turtle-set primitive. For the second one you need the member? primitive, which also works on agentsets. As such:

    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
    
    0 讨论(0)
提交回复
热议问题