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?

2

There are 2 best solutions below

0
On BEST ANSWER

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]
4
On

Many things to say here:

  1. Charles' answer is technically correct.

If a and b are agentsets, a with [ not member? self b ] will give you agents from a that are not already in b.

But I think there are better ways to accomplish what you are trying to do. I will come back to that, but first, a general piece of advice:

  1. Don't use who!

The who primitive has some (very few) legitimate usages, but it's mostly evil. It tends to lead to brittle, inefficient code. For example, when you do:

let i who
; ...
ask companies with [who = i] [ ... ]

NetLogo has to scan all companies to find the one with that specific who number.

NetLogo can store agent references directly. Use that instead! For example:

let this-company self
; ...
ask this-company [ ... ]
  1. Especially don't use lists of who numbers!

NetLogo is adequate for manipulating lists, but its awesome for manipulating agentsets. If you do something like this:

set iburen [who] of b
set iiburen [who] of other c
set iiiburen [who] of d

You are forfeiting the power of agentsets. I don't know why you want to store the three different levels separately, but supposing it's OK to store all your neighbors together, you could do:

set my-neighbors other (turtle-set b c d)

The use of other will exclude the original company and turtle-set will make sure that each agent in the set is unique (as agentsets can only contain unique agents anyway).

If you really want three separate variables, use Charles' answer, but make sure to store agentsets, not lists of who numbers!

If you don't need separate variables, however, I think the best solution would be to:

  1. Use nw:turtles-in-radius.

NetLogo's Networks extension has a primitive that does exactly what I think you want to do:

ask companies [ set my-neighbors nw:turtles-in-radius 3 ]

That's it.