Parameterized Tree Graph

Parameterized Tree Graph preview image

1 collaborator

Aaronastronaut Aaron Bramson (Author)

Tags

code example 

Tagged by Aaron Bramson about 9 years ago

networks 

Tagged by Aaron Bramson about 9 years ago

tree 

Tagged by Aaron Bramson about 9 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 401 times • Downloaded 39 times • Run 0 times
Download the 'Parameterized Tree Graph' 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

;; add these features to your model

breed [terminal-nodes terminal-node]
breed [intermediate-nodes intermediate-node]
breed [centrums centrum]
turtles-own [level]

to setup
  __clear-all-and-reset-ticks
  if white-background? [ask patches [set pcolor white] ]
  create-random-tree population layers %-actors
  ask centrums [
    ifelse white-background?
      [ set color black ]
      [ set color white ]
  ]
end 

to go
  tick
end 

to create-random-tree [number-of-nodes levels %-terminals]
  set-default-shape turtles "circle"   
  create-centrums 1 [
    set color gray
    set level 1
  ]
  create-intermediate-nodes (number-of-nodes - (number-of-nodes * %-terminals) - 1) [  
    set color green
    set level 2 + random (levels - 2) 
  ]
  ask turtles with [breed != centrums] [
    ifelse any? turtles with [level = ([level] of myself - 1)]
      [ create-link-with one-of (turtles with [level = ([level] of myself - 1)]) ]
      [ create-link-with one-of centrums 
        set level 2 ]
  ]
  if count intermediate-nodes with [count link-neighbors = 1] > number-of-nodes * %-terminals [
    user-message (word "That's not enough terminal nodes for this graph.") 
    stop
  ]
  ask intermediate-nodes with [count link-neighbors = 1] [
    hatch-terminal-nodes 1 [  
      set color red
      create-link-with myself
      set level ([level] of myself + 1)
    ]
  ]
  let remaining-terminal-nodes number-of-nodes * %-terminals - count terminal-nodes
  repeat remaining-terminal-nodes [
    ask one-of turtles with [breed != terminal-nodes] [
      hatch-terminal-nodes 1 [  
        set color red
        create-link-with myself
      set level ([level] of myself + 1)
      ]
    ]
  ] 
  layout-radial turtles links one-of turtles with [breed = centrums]
end 

There is only one version of this model, created about 9 years ago by Aaron Bramson.

Attached files

File Type Description Last updated
Parameterized Tree Graph.png preview Preview for 'Parameterized Tree Graph' about 9 years ago, by Aaron Bramson Download

This model does not have any ancestors.

This model does not have any descendants.