Evolving Fractal Trees

No preview image

1 collaborator

Tags

almost as cool as ifs kits 

"but only almost"

Tagged by Michelle Wilkerson-Jerde over 15 years ago

coolest models 

"because I need to compete with Michelle"

Tagged by Forrest Stonedahl almost 16 years ago

fractals 

"fractals are fun"

Tagged by Reuven M. Lerner over 15 years ago

work-in-progress 

"should be self explanatory..."

Tagged by Forrest Stonedahl almost 16 years ago

Model group Fractal Lovers | Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.1beta2pre2 • Viewed 856 times • Downloaded 55 times • Run 15 times
Download the 'Evolving Fractal Trees' modelDownload this modelEmbed this model

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


VERSION

$Id: Evolving Fractal Trees.nlogo 43333 2009-03-14 05:20:52Z fjs750 $

WHAT IS IT?

This section could give a general understanding of what the model is trying to show or explain.

HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.

HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.

THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.

Comments and Questions

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

Click to Run Model

breed [drawings drawing ]

drawings-own [
   genome
   fitness
]

to setup
  ca
  ask patches [
    sprout-drawings 1 [
      set genome n-values 8 [ random-float 1.0 ]
      ht
    ]
  ]

 ask drawings [ do-drawing ]
end 

to go
  every 5 [
    ask drawings [ pen-up ]
    create-next-generation
    clear-drawing
    ask drawings
    [
      pen-down
      do-drawing
    ]
    tick
   ]
  if mouse-down? [
    ask patch mouse-xcor mouse-ycor [
      ask turtles-here [
        set fitness fitness + 1
      ]
    ]
  ]
end 

to do-drawing
  let max-dist 0.5
  let scale-factor 0.5 + 0.5 * item 0 genome
  let n floor (2 + 9 * item 1 genome)
  let angle1 floor (360 * item 2 genome)
  let angle2 floor (360 * item 3 genome)
  let col 1 + 10 * (floor 14 * item 4 genome)
  let col-incr 0.00 + 14 * item 5 genome
  let psize 5 * item 6 genome
  set heading 360 * item 7 genome

  let dist max-dist * (scale-factor - 1) / (scale-factor ^ n - 1)

  pd
  draw-tree n dist psize scale-factor col col-incr angle1 angle2
end 

to draw-tree [ n dist pensize scale-factor col col-incr angle1 angle2]
  if (n = 0) [ stop ]
  set pen-size pensize
  set color col
  fd dist
  rt angle1
  draw-tree (n - 1) dist * scale-factor pensize * scale-factor scale-factor col + col-incr col-incr angle1 angle2
  lt angle1
  rt angle2
  draw-tree (n - 1) dist * scale-factor pensize * scale-factor scale-factor col + col-incr col-incr angle1 angle2
  lt angle2
  set pen-size pensize
  set color col
  bk dist
end 

;; This procedure does the main work of the genetic algorithm.
;; We start with the old generation of solutions.
;; We choose solutions with good fitness to produce offspring
;; through crossover (sexual recombination), and to be cloned
;; (asexual reproduction) into the next generation.
;; There is also a chance of mutation occurring in each individual.
;; After a full new generation of solutions has been created,
;; the old generation dies.

to create-next-generation
  ; The following line of code looks a bit odd, so we'll explain it.
  ; if we simply wrote "LET OLD-GENERATION SONGS",
  ; then OLD-GENERATION would mean the set of all songs, and when
  ; new solutions were created, they would be added to the breed, and
  ; OLD-GENERATION would also grow.  Since we don't want it to grow,
  ; we instead write "SONGS WITH [TRUE]", which makes OLD-GENERATION
  ; an agentset, which doesn't get updated when new solutions are created.
  let old-generation drawings with [true]
  let population-size (count patches)
  ; Some number of the population is created by crossover each generation
  ; we divide by 2 because each time through the loop we create two children.
  let crossover-count  (floor (population-size * crossover-rate / 100 / 2))

  repeat crossover-count
  [
    ; We use "tournament selection", with tournament size = 3.
    ; This means, we randomly pick 3 solutions from the previous generation
    ; and select the best one of those 3 to reproduce.

    let parent1 min-one-of (n-of 3 old-generation) [fitness]
    let parent2 min-one-of (n-of 3 old-generation) [fitness]
    let inherited-fitness 0.3 * ([fitness] of parent1 + [fitness] of parent2)
    let child-genome-pair crossover ([genome] of parent1) ([genome] of parent2)

    ; create the two children, with their new genetic material
    ask parent1 [ hatch 1 [ set genome item 0 child-genome-pair set fitness inherited-fitness ] ]
    ask parent2 [ hatch 1 [ set genome item 1 child-genome-pair set fitness inherited-fitness ] ]
  ]

  ; the remainder of the population is created by cloning
  ; selected members of the previous generation
  repeat (population-size - crossover-count * 2)
  [
    ask max-one-of (n-of 3 old-generation) [fitness]
      [ hatch 1 [ set fitness 0.3 * fitness ] ]
  ]

  ask old-generation [ die ]

  ; now we're just talking to the new generation of solutions here
  ask drawings
  [
    ; there's a chance of mutations occurring
    mutate
    let emptyspots patches with [ not any? turtles-here ]
    if any? emptyspots [ move-to one-of emptyspots ]
  ]
end 

;; ===== Mutations

;; This reporter performs one-point crossover on two lists of bits.
;; That is, it chooses a random location for a splitting point.
;; Then it reports two new lists, using that splitting point,
;; by combining the first part of bits1 with the second part of bits2
;; and the first part of bits2 with the second part of bits1;
;; it puts together the first part of one list with the second part of
;; the other.

to-report crossover [bits1 bits2]
  let split-point 1 + random (length bits1 - 1)
  report list (sentence (sublist bits1 0 split-point)
                        (sublist bits2 split-point length bits2))
              (sentence (sublist bits2 0 split-point)
                        (sublist bits1 split-point length bits1))
end 

to mutate   ;; song procedure
  set genome map [ifelse-value (random-float 100.0 < mutation-rate) [(? + random-normal 0 0.5) mod 1.0] [?]]
               genome
end 

There are 2 versions of this model.

Uploaded by When Description Download
Forrest Stonedahl over 14 years ago I moved around interface items. I didn't do anything else. I don't know where this model is going. this is just a test, to see how long of comments I can make. Download this version
Forrest Stonedahl over 14 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.