create-links-with

 

create-links-with is a turtle procedure that creates a link between the current turtle (self) to every member of a provided agentset.

ask turtles [
    create-links-with other turtles-here
]

Notice that we use the other primitive in our code because if we did not use other, our code would give an error. NetLogo shows this error because the turtles-here primitive reports all the turtles in a model, including the turtle who is trying to create the links, but a turtle cannot create a link with itself. So, do not forget to use the other primitive when you are using similar agentset reporter primitives such as in-radius and turtles.

Also keep in mind that this primitive is used to create multiple links at once, so you need to provide an agentset. If you want to create a link with just one specific turtle, you should use the create-link-with primitive.

In the model example below, we use the create-links-with primitive to simulate contact tracing. Every time two people are on the same patch, a new link between them is created. Then, the trace-back button/procedure uses the links between the individuals to trace back the people who may have been exposed to an infectious person.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

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

Reports all agents connected to a turtle with links.

Read more
layout-circle

Places turtles in a circle circle around the center of the world.

Read more
links

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

Read more
n-of

Reports "n" randomly picked agents from an agentset or items from a list.

Read more
 
Learn another primitive: