Basic model 1: Networks

Basic model 1: Networks preview image

1 collaborator

Gil Alvaro Gil (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0 • Viewed 533 times • Downloaded 42 times • Run 0 times
Download the 'Basic model 1: Networks' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

to simple_net
  ca
   crt 5
   ask turtles [setxy random-xcor random-ycor ]
   ;; turtle 1 creates links with all other turtles
   ;; the link between the turtle and itself is ignored
   ask turtle 0 [ create-links-with other turtles ]
   show count links ;; shows 4
   ;; this does nothing since the link already exists
   ask turtle 0 [ create-link-with turtle 1 ]
   show count links ;; shows 4 since the previous link already existed
   ask turtle 2 [ create-link-with turtle 1 ] 
   show count links ;; shows 5
end 

to make-a-tree
  ca
  set-default-shape turtles "circle"
  crt 6
  ask turtle 0 [ 
    create-link-with turtle 1
    create-link-with turtle 2
    create-link-with turtle 3
  ]
  ask turtle 1 [
    create-link-with turtle 4
    create-link-with turtle 5
  ]  
  ; do a radial tree layout, centered on turtle 0
  layout-radial turtles links (turtle 0)
end 

to make-a-triangle
  ca
  set-default-shape turtles "circle"
  crt 3
  ask turtle 0
  [
    create-links-with other turtles
  ]
  ask turtle 1
  [
    create-link-with turtle 2
  ]
  repeat 30 [ layout-spring turtles links 0.2 5 1 ] ;; lays the nodes in a triangle
end 

to make-a-tutte
  ca
  set-default-shape turtles "circle"
  crt 6
  ask turtle 0 [ 
    create-link-with turtle 1
    create-link-with turtle 2
    create-link-with turtle 3
  ]
  ask turtle 1 [
    create-link-with turtle 4
    create-link-with turtle 5
  ]  
  ; place all the turtles with just one 
  ; neighbor on the perimeter of a circle
  ; and then place the remaining turtles inside 
  ; this circle, spread between their neighbors.
  repeat 10 [ layout-tutte (turtles with [link-neighbors = 1]) links 12 ]
end 


directed-link-breed [red-links red-link]
undirected-link-breed [blue-links blue-link]

to direct-graph
  ca
  crt 5
  ;; create links in both directions between turtle 0
  ;; and all other turtles
  ask turtle 0 [ create-red-links-to other turtles ]
  ask turtle 0 [ create-red-links-from other turtles ]
  show count links ;; shows 8
  ;; now create undirected links between turtle 0 and other turtles
  ask turtle 0 [ create-blue-links-with other turtles ]
  show count links ;; shows 12
  layout-radial turtles links (turtle 0)
end 

to show-names
  ask turtles [
   ifelse label = ""
   [set label (word who " ")] 
    [set label ""]
  ]
end 

to setup
  ca
  crt Nodes
  set-default-shape turtles "circle"
  ask turtles [setxy random-xcor random-ycor ]
  ;ask patches [set pcolor white]
end 

to create-random-graph
  ask links [die]
  ask turtles [create-links-with n-of ((random Max_Connections) + 1) other turtles]
end 

to circle 
  layout-circle turtles Radius
end 

to radial
  layout-radial turtles links turtle T_Ref
end 

to radial2
  let m []
  ask turtles [
    let n []
    set n lput who n
    set n lput count(my-links) n
    set m lput n m]
  print (word "The array of connections is: " m)
  set m sort-by [last ?2 < last ?1] m
  print (word "The sorted array of connections is: " m)
  let t_max first(first(m))  ;Turtle with high degree
  let n_max last(first(m))   ;Highest degree
  let n_min last(last(m))    ;Lowest degree
  let r_s 2.0 / (n_max - n_min)
  foreach m [
   ask turtle (first(?)) [set size (0.2 + (last(?) * r_s))] 
  ]
  print (word "So the turtle with high degree is: " t_max)
  layout-radial turtles links turtle t_max
end 

There is only one version of this model, created over 4 years ago by Alvaro Gil.

Attached files

File Type Description Last updated
Basic model 1: Networks.png preview Preview for 'Basic model 1: Networks' over 4 years ago, by Alvaro Gil Download

This model does not have any ancestors.

This model does not have any descendants.