link-neighbors

 

link-neighbors is a turtle primitive that reports an agentset that contains all the turtles that are connected to the original turtle via links. For instance, if we were using links to represent friendship relationships, a turtle could send its friends new messages by using the link-neighbors primitive. For example, the following code would ensure that turtles with less than 2 friends make new friends.

ask turtles [
    if count link-neighbors < 2 [
        make-new-friends
    ]
]

In the model example below, we use link-neighbors to simulate contact tracing. Every time two turtles get close to each other, a link between them is formed. Each link represents a "contact" between two turtles, so calling link-neighbors on an individual reports back every other person that this individual had contact with. When we implement the trace-back procedure in our code (on line 26), we ask all of the link-neighbors of any exposed (red) individuals to turn red themselves to signify that they have been exposed as well.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the link-neighbors primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the link-neighbors primitive:
 
 
Similar primitives:
create-links-with

Creates links with every agent in an agentset.

Read more
links

Reports an agentset that contains all the links in a model.

Read more
any?

Checks if there is at least one agent in an agentset.

Read more
count

Counts the number of agents in an agentset.

Read more
 
Learn another primitive: