Link Breeds Example

Link Breeds Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner over 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1686 times • Downloaded 251 times • Run 2 times
Download the 'Link Breeds Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This code example shows how to create different kinds of links using link breeds.

The idea of link breeds is based on turtle breeds; both turtles and links can come in different breeds.

Note that many models that use links don't need link breeds. If a model only has one kind of link, the links can be generic, unbreeded links.

THINGS TO NOTICE

Each link breed is either directed or undirected. When you create the breed, you must specify one or the other.

Two undirected links of the same breed cannot exist between the same two turtles. Two directed links of the same breed cannot exist between the same two turtles in the same direction.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; every link breed must be declared as either directed or undirected
directed-link-breed [red-links red-link]
undirected-link-breed [blue-links blue-link]

blue-links-own [ weight ]  ;; link breeds can own variables just like turtle breeds

to setup
  clear-all
  create-ordered-turtles 10 [
    fd 5
    set color gray
  ]
  ask n-of 5 turtles [
    ;; create--with is used to make undirected links
    create-blue-link-with one-of other turtles [
      set color blue
      set weight random 10
      set label weight
    ]
  ]
  ;; different breeds can have different default shapes
  set-default-shape red-links "curved link"
  ask n-of 5 turtles [
    ;; create--to/from are used to make directed links
    create-red-link-to one-of other turtles [
      set color red
    ]
  ]
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 12 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 13 years ago Updated version tag Download this version
Uri Wilensky over 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 15 years ago Link Breeds Example Download this version
Uri Wilensky about 15 years ago Link Breeds Example Download this version

Attached files

File Type Description Last updated
Link Breeds Example.png preview Preview for 'Link Breeds Example' over 12 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.