Search code examples
netlogoagentset

Removing an agentset from another agentset (the agents from the first set which are also present in the second set)


in my netlogo code I have a network with companies (that is my breed). I want to ask the companies to share information with their neighbors and their neighbors and so on, this works (see code below, the agentsets are b, c and d).

However when I ask for information on the third level neighbors my agentset also includes the first level neighbors (obviously since it takes all neighbors into acount), so I want to remove these first level neighbors from the third level neighbors agentset. In the code this means I want to remove agents present in D which are also present in B

But I cant find the way to do it, other doesnt work since it is not the agent asking which has to be removed. And remove also doesnt seem to do the job. I also tried != not equal to the first level but this reports a true or false and I just want to remove these agents from the third level agentset so I dont double count them.

ask companies [
  let i who
  let b link-neighbors
    ask b [ let c link-neighbors
     ask c [ let d link-neighbors

      ask companies with [who = i] [ 
        set iburen [who] of b
        set iiburen [who] of other c
        set iiiburen [who] of d
     ]
   ]
 ]
]

can somebody help me with this?


Solution

  • I think what you want is the member? primitive. If D and B are agentsets, the following should give you the members of D that are not members of B.

    let DminusB D with [not member? self B]