BugHunt Mutations

No preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Default-person Michael Novak (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.1pre10 • Viewed 178 times • Downloaded 8 times • Run 3 times
Download the 'BugHunt Mutations' 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 is an evolution model that shows how mutation affects genetic code which in turn can effect structure & function in organisms.

NOTES FOR DEVEL

Each segment is attached to a previous segment (or the body) in the bugs making a chain of segments. Each segment can have the following traits:

mutations in values must occur less than 10-20% of the time ....e..g. 5 % for shift, 2% for addition segments, but once a segment is already there, it is disadvantageous to loose it Ð makes compatibility harder for those who have it. Q Ð will 2% segment addition propagate into a population?

duplicate enteries (same angle and same size and same shape) are not built, angle must be different, or else physical interfance (by x degrees)

Starting with equal distribution of one segment in all the population helps seed.

What (if anything) will push for some additional complexity Ð Having one segment more is dominant over not coding for the segment (it is expressed in the presence of no conflicting information).

Any energy cost for all these segments (yes Ð at birth Ð 1 extra energy unit per segment) Ð could take this out Ð but a bit inconsistent considering mandible penalties

Can loose a trait only through genetic incompatibility Ð that causes a push toward dropping out traits, 0 and 8 trait Ð they can't interbreed, but

same odds of duplication and deletion - yes. duplication to new segment # duplication of existing segment # + angle --> but does not match any other segments.

But many who have the same trait causes a push toward keeping that trait.

go in the direction of the last link ? shape radius, turn angle go ? new shape radius, hatch the color shape you need.

next segment, repeat

HOW IT WORKS

All initial bug populations have diverse gene pools. These diverse gene pools provide a variety of different attributes that will provide different survival advantages in different environments.

These attributes include, speed of movement, vision distance, litter size, and mandible structures (for eating), color, sex, and mate-range (or the threshold of acceptable "similarly" colored bugs that a given bug will mate with).

As the individuals in a population interact across different ecosystems certain combinations of selective pressures will cause populations of bugs to become more selective about who their mates are. Over time this pressure can often lead to speciation, where an entire population of bugs no longer can interbreed with a related population of bugs. Other selective pressures will cause populations of bugs to become less selective about who their mates are. Over time this pressure can insure that a diverse gene pool is maintained in a population, where such diversity is advantageous to the population. Speciation does not occur as readily when such pressures dominate.

In general, diverse population are more desirable when the distribution of resources to survive (such as food and energy available to a species) is either nearly uniform accessible in all parts of the ecosystem(s), or when such distribution changes, it does so in a smooth spatial gradient, or with transition zones, where multiple types of resources can be found. In such cases, since multiple types of food sources are located in more than one region, it is more beneficial for a population to not speciate, and instead remain "generalist" resource consumers. It is also more beneficial for an individual in such an ecosystem to be less picky about mates, since diversity of genes is not penalized, and the odds of successfully finding a mate are also increased.

In general, speciation is more desirable, when the distribution of resources to survive (such as food and energy) is grouped in discrete and separated regions. In such cases, since one food source is located in one region and a different food source is located in a further away region, it is more beneficial for a population to speciate into two "specialist" populations, each uniquely adapted for being more efficient at resource consumption in their respective region (or niche). It is more beneficial for an individual in such an niche to be more picky about mates, since diversity of genes is penalized, and introduction of new genes is not desirable when the population is already specialized to an environment. As the mate-range of the species decreases, the penalty for finding a mate in homogenous population is far less, as the population has less variation in other attributes as well. Therefore most individuals in the population are genetically similar, and therefore acceptable mates, even for bugs using a very narrow range of acceptable traits for identification of such mates. In this manner, species self reinforce "pickyness" for mates, further driving the isolation of their population from related populations

HOW TO USE IT

SHOW-PLANTS? is the switch that provides visualization of the patch color in order to see what type of plant (by color) is growing there and how much vegetation from this type of plant is available as a food source (by saturation of the color). Since color of bugs shows an alternate attribute that is relevant to speciation, the user may wish to turn SHOW-PLANTS? to off after some period, to make it easier to study the color of the bugs.

BUG-LABELS is a chooser that allows the user to select what label the bugs will display. This is useful for studying the individual heritable traits for each bug while the simulation is running.

POPULATE-1?, POPULATE-2?, POPULATE-3?, POPULATE-4?, POPULATE-5?, POPULATE-6? are switches used to indicate which regions of the WORLD & VIEW will be initially populated with the bugs set by INITIAL-BUGS and by the birds set by INITIAL-BIRDS sliders.

The six regions are designated as follows:

--------------------------------

- - - -

- 1 - 2 - 3 -

- - - -

- - - -

- 4 - 5 - 6 -

- - - -

The BRIDGE-12, BRIDGE-23, BRIDGE-14, BRIDGE-25, BRIDGE-36, BRIDGE-45, and BRIDGE-56 switches are used to open geographic boundaries between each of the regions. BRIDGE-12 for example, when set to on, will open part or all of the bounary between region 1 and 2. If BRIDGE-SIZE is set to "large", the entire boundary will be open (no wall in between) and if it is set to "small", only a small gate in the boundary will be open.

The ECOSYSTEM chooser is used at SETUP to configure different plant distributions in each region.

The EVENT CUE chooser is used to auto-cue events (such as opening and closing geographic boundaries) or applying labels, at certain times in the simulation. This is useful for when you want to run a movie and have events occur automatically during the movie run. When EVENT CUE is set to "none" the user can cange the BRIDGE switches and BUG-LABELS chooser. When it is set to a different value, such interface actions may be overrided by automatically cued events.

The IDENTIFY SPECIES button builds a network of bugs that could potentially interbreed with each other. Often you will see that such a network links only the bugs of a certain color, in a certain region, and with a specific gene pool. When this network is not linked to other populations, those other populations can't interbreed with it.

THINGS TO NOTICE

Speciation often emerges when

1) geographic isolation of population, in combination with genetic drift, leads to two populations who eventually no longer interbreed, due to gradual divegence of the characteristics that influence their breeding behavior (color and mate-range).

2) a small population emegrates far away from its parent population, and in combination with the limited gene pool (called a bottle neck effect) and genetic drift or slight environmental pressures (slightly different resource distribution), leads to two populations who eventually no longer interbreed due to different genetic characteristics that influence their breeding behavior (color and mate-range).

3) two distinct niches exist in close proximity to each other, each of which can better be exploited with a limited/specialized set of traits/structures in the gene pool. Sexual selection then will reinforce speciation, to prevent "gene pool" intermixing of genes, which would only lead to a decrease in chances for survival. An example of such a scenario is where region 1 has only plant A, region 2 has plant C, and region 3 has plant B.

Speciation does not readily emerge (nor remain in place) when distinct sub-populations emerge from 1, 2, or 3, but intermediate transition "ecosystems" of mixed niches are placed between both sub-populations. Such a transition zone adds a strong selective pressure for intermediate behaviors in individuals that would serve as a "gene bridge" between both sub-populations, while also allowing such indivduals to survive in the transition zone, due to influx of desirable traits, increased mating opportunities, and ability to survive sub-optimally in the regions just outside of the transition ecosystem. An example of such a scenario is where region 1 has only plant A, region 2 has plant A and B, and region 3 has plant B.

THINGS TO TRY

EXTENDING THE MODEL

RELATED MODELS

All BEAGLE Evolution models. In particular: Bug Hunt Speeds, Bug Hunt Camouflage, Wolf Sheep Predation, and GENE DRIFT T INTERACT

CREDITS AND REFERENCES

To refer to this model in academic publications, please use: Novak, M.s and Wilensky, U. (2007). NetLogo Bug Hunt Coevolution model. http://ccl.northwestern.edu/netlogo/models/BugHuntCoevolution. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use: Copyright 2007 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/BugHuntCoevolution for terms of use.

Comments and Questions

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

Click to Run Model

breed [bugs bug]
breed [bug-segments bug-segment]
breed [bug-segment-makers bug-segment-maker]
breed [trackers tracker]
breed [selectors selector]
patches-own [resprout-countdown leaves plant-type can-be-a-wall? region]  
links-own [species]
bugs-own [
  speed             ;; gene for speed
  vision            ;; gene for vision distance
  red-gene          ;; gene for strength of expressing red pigment (0-100)
  blue-gene         ;; gene for strength of expressing blue pigment (0-100)
  green-gene        ;; gene for strength of expressing green pigment (0-100)
  segment-DNA
  segment-tRNA
  energy
  age
  other-genetic-difference
  linked?
  last-segment-color
  efficiency-A
  efficiency-B
  efficiency-C
  efficiency-D
  which-descendant-am-I
]
bug-segments-own [
  segment-DNA
  segment-tRNA
  parent-bug-id
]
bug-segment-makers-own [
  segment-DNA
  segment-tRNA
  parent-bug-id
]

globals [
    bridge-12
    bridge-23
    ecosystem
    bridge-size
    total-caught                 ;; keeps track of total number of bugs caught
    histogram-interval-size      ;; the value of the interval size for each bar of the histogram
    max-vision                   ;; upper limit for the maximum vision allowable for birds or bugs
    max-speed                    ;; upper limit for the maximum speed allowable for birds or bugs
    max-leaves                   ;; upper limit for consumable food in a patch (set to 100 by default)
    leaf-regrowth-rate           ;; number of new leaves each time step that regrow on a patch of plants
    bug-mate-energy-threshold    ;; amount of energy the female must have (min. to be able to mate)
    bug-base-metabolism          ;; the energy lost by the bug every tick to maintain its base metabolism
    bird-base-metabolism         ;; the energy lost by the bird every tick to maintain its base metabolism
    bug-mating-energy-cost       ;; the energy lost in mating, by both male and female
    descendants                  ;; the number of descendents 
    
    wall-color 
    bug-last-selected                    ;; agent currently selected
    bug-selected-countdown               ;; countdown timer for selected bug to no longer be displayed
    %-segment-separation                 ;; visualization parameter for segment overlap
    min-segment-size max-segment-size
    max-init-body-segments min-init-body-segments
    id-for-segments             ;; parent-id
    bug-body
    segment-handedness  ;; -1 or 1
      
    
    bug-labels-old-state         ;; state variable for keeping track if the bug-lables chooser has been changed and therefore should new labels be assigned to the bugs
    speed-factor                 ;; scalar used to adjust the speed of the all the bugs to make the catching of bugs appropriately difficult for different speed computers
    plant-A-color                ;; color of plant A
    plant-B-color                ;; color of plant B
    plant-C-color                ;; color of plant C
    plant-D-color                ;; color of plant D
    bridge-length
    small-bridge-color                 ;; color of the portion of the wall (itself a region # > 100) that are the small bridges between plant regions
    large-bridge-color                 ;; color of the portion of the wall (itself a region # > 100) that are the small bridges between plant regions
    min-bug-mate-age             ;; the youngest age a bug can begin mating at
    max-bug-age                  ;; the oldest a bug can live
    
    mouse-down-last?
    
    bug-mandible-loss-mutation-% ;; chance of inheriting a mutation that causes loss of an allele for expressing a mandible structure
    show-segment-old-state
    
    mouse-event
]
;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures
;;;;;;;;;;;;;;;;;;;;;

to setup
  ca  
  set ecosystem "4"
  set  bridge-12 false
  set bridge-23 false
  set bridge-size "small"
  set bug-last-selected nobody
  set bug-selected-countdown 0 
    set %-segment-separation 90
  set max-segment-size 1.2
  set min-segment-size 0.8
  set max-init-body-segments 3
  set  min-init-body-segments 3
  set id-for-segments -1
  set bug-body nobody
  set show-segment-old-state false
  set total-caught 0
  set histogram-interval-size 1
  set max-leaves 100
  set leaf-regrowth-rate 1
  set bug-mate-energy-threshold   50
  set max-bug-age 500
  set speed-factor 0.05
  set bridge-length 15
  set descendants 0
  set min-bug-mate-age 20
  set bug-base-metabolism 1   
  set bug-labels-old-state "none"
  set plant-A-color  red + 4.9             
  set plant-B-color  yellow + 4.9             
  set plant-C-color  lime + 4.9            
  set plant-D-color  violet + 4.9
  set small-bridge-color gray - 2
  set large-bridge-color black
  set wall-color black
  set mouse-down-last? false
  setup-plants
    
  setup-bugs
  check-bridges
  setup-tracker-and-selector
  
  do-plots
  visualize-labels
  ask bugs [build-full-segment-bug]
  visualize-segments
  
  display
end 


;;;;;;;;;;;;;;;;;;;;;
;; Patches and Environment Setup Procedures
;;;;;;;;;;;;;;;;;;;;;

to setup-plants
  ask patches [  set pcolor white]   ;; white background
  setup-regions
   if ecosystem = "1" [setup-ecosystem-1]
   if ecosystem = "2" [setup-ecosystem-2]
   if ecosystem = "3" [setup-ecosystem-3]
   if ecosystem = "4" [setup-ecosystem-4]
   ask patches [visualize-plants]
end 

to setup-regions
  let region-1 patches with [pxcor < 0 and pxcor > min-pxcor  and pycor < max-pycor - 1 and pycor > min-pycor + 1]
  let region-2 patches with [pxcor > 1 and pxcor < max-pxcor  and pycor < max-pycor - 1 and pycor > 1 ]
  let region-3 patches with [pxcor > 1 and pxcor < max-pxcor  and pycor > min-pycor + 1 and pycor < 0 ]
   
  ;; the walls between the regions are themselves regions. So, for example, region-12 is the wall between region 1 and region 2
    let region-12 patches with [pxcor >= 0 and pxcor <= 1 and  pycor < (max-pycor - 5) and pycor >= max-pycor - 8 ]
   let region-23 patches with [pxcor >=  max-pxcor - 10  and pxcor <= max-pxcor - 8 and  pycor <= 1 and pycor >= 0 ]

    
  ask patches [set region 0 ]
   
  ask region-12 [ set region 12 ]
  ask region-23 [set region 23 ]
  
  ask region-1 [set region 1]
  ask region-2 [set region 2]
  ask region-3 [set region 3]
end 

;; These ecosystems settings are attempts to setup interesting combinations of the four plant types in each region.  Setting
;; the ecosystem chooser to 1,2, or 3 will employ one of these settings in SETUP

to setup-ecosystem-1
    ask patches with [region = 2 ] [
     let distribution random 100
      if distribution >= 0 and distribution < 20 [set plant-type "A" set resprout-countdown 0 set leaves random 100]
      if distribution >= 20 and distribution < 40 [set plant-type "B"  set resprout-countdown 0 set leaves random 100] 
      if distribution >= 40 and distribution < 60 [set plant-type "C" set resprout-countdown 0 set leaves random 100]
      if distribution >= 60 and distribution < 80 [set plant-type "D"  set resprout-countdown 0 set leaves random 100] 
  ]
  
    ask patches with [region = 1] [
     let distribution random 100
      if distribution >= 0 and distribution < 40 [set plant-type "B" set resprout-countdown 0 set leaves random 100]
      if distribution >= 40 and distribution < 80 [set plant-type "D"  set resprout-countdown 0 set leaves random 100] 
  ]
    
    ask patches with [region = 3] [
     let distribution random 100
      if distribution >= 0 and distribution < 40 [set plant-type "C" set resprout-countdown 0 set leaves random 100]
      if distribution >= 40 and distribution < 80 [set plant-type "A"  set resprout-countdown 0 set leaves random 100] 
  ]
      
  ask patches with [region = 0] [set pcolor black]
end 

to setup-ecosystem-2
    ask patches with [region = 1] [
     let distribution random 100
      if distribution >= 0 and distribution < 20 [set plant-type "A" set resprout-countdown 0 set leaves random 100]
      if distribution >= 20 and distribution < 40 [set plant-type "B"  set resprout-countdown 0 set leaves random 100] 
      if distribution >= 40 and distribution < 60 [set plant-type "C" set resprout-countdown 0 set leaves random 100]
      if distribution >= 60 and distribution < 80 [set plant-type "D"  set resprout-countdown 0 set leaves random 100] 
  ]
  
    ask patches with [region = 2 or region = 3] [
     let distribution random 100
      if distribution >= 0 and distribution < 80 [set plant-type "C" set resprout-countdown 0 set leaves random 100]
  ]
      
  ask patches with [region = 0] [set pcolor black]
end 

to setup-ecosystem-3
    ask patches with [region = 1] [
     let distribution random 100
      if distribution >= 0 and distribution < 30 [set plant-type "A" set resprout-countdown 0 set leaves random 100]
      if distribution >= 30 and distribution < 60 [set plant-type "B"  set resprout-countdown 0 set leaves random 100] 
            if distribution >= 60 and distribution < 90 [set plant-type "D" set resprout-countdown 0 set leaves random 100]
  ]
  
    ask patches with [region = 2] [
     let distribution random 100
      if distribution >= 0 and distribution < 30 [set plant-type "A" set resprout-countdown 0 set leaves random 100]
      if distribution >= 30 and distribution < 60 [set plant-type "C"  set resprout-countdown 0 set leaves random 100] 
       if distribution >= 60 and distribution < 90 [set plant-type "D" set resprout-countdown 0 set leaves random 100]
  ]
    
    ask patches with [region = 3] [
     let distribution random 100
      if distribution >= 0 and distribution < 30 [set plant-type "B" set resprout-countdown 0 set leaves random 100]
      if distribution >= 30 and distribution < 60 [set plant-type "C"  set resprout-countdown 0 set leaves random 100] 
       if distribution >= 60 and distribution < 90 [set plant-type "D" set resprout-countdown 0 set leaves random 100]
  ]
 
  ask patches with [region = 0] [set pcolor black]
end 

to setup-ecosystem-4
    ask patches with [region = 1] [
     let distribution random 100
      if distribution >= 0 and distribution < 80 [set plant-type "B" set resprout-countdown 0 set leaves random 100]
  ]  
  
    ask patches with [region = 2] [
     let distribution random 100
      if distribution >= 0 and distribution < 80 [set plant-type "C" set resprout-countdown 0 set leaves random 100]
  ]
    
    ask patches with [region = 3] [
     let distribution random 100      
      if distribution >= 0 and distribution < 80 [set plant-type "A" set resprout-countdown 0 set leaves random 100]
  ]
      
  ask patches with [region = 0] [set pcolor black]
end 

;;;;;;;;;;;;;;;;;;;;;
;; Bug Setup Procedures
;;;;;;;;;;;;;;;;;;;;;

to setup-tracker-and-selector
  create-trackers 1 [set shape "target" set size 8 set color red setxy 0 0 inspect self]
    create-selectors 1 [
    set shape "empty"
    set color gray - 3
    set size 1.5
    set heading 315
    hide-turtle
  ]
end 

to setup-bugs
  let available-patches nobody
   ;; determine which regions will be populated with the bugs by checking the populate-1?, populate-2? etc... switches  
   set available-patches patches with [region = 1]
  
  create-bugs initial-bugs [   
    set descendants descendants + 1
    set which-descendant-am-I descendants
    set shape "bug"
    let target-patch one-of available-patches 
    setxy [pxcor] of target-patch [pycor] of target-patch
    set label-color 0
    set energy random 200
    set age random max-bug-age  
    assign-color-genes
    if initial-bugs-segments = "all random" [ setup-initial-random-segments ]
   ]   
    if initial-bugs-segments = "identical vari-segments" [
     ask bugs [
        set segment-DNA []
        set segment-tRNA []
        repeat 3 [setup-initial-identical-vari-segments]
      ]
    ]
    if initial-bugs-segments = "identical mono-segments" [
       setup-initial-identical-mono-segments
    ]
end 

to assign-color-genes ;; turtle procedure
    ifelse initial-bugs-segments = "identical mono-segments" or  initial-bugs-segments = "identical vari-segments"  [
      set red-gene (50)
      set blue-gene (50)
      set green-gene (50)
    ]  
     [
      set red-gene (random 100)
      set blue-gene (random 100)
      set green-gene (random 100)
    ]    
    set-phenotype-color
end 

to build-full-segment-bug            ;; this procedure builds the body segments on newly hatched offspring
 ;;ask bugs with [new?]  [
  set bug-body self
  set id-for-segments who
  let handedness-power 1
  let these-two-segments-attach-to segments-attach-to
  ifelse segments-attach-to = "3 sides"
    [set these-two-segments-attach-to "side-1"]
    [set these-two-segments-attach-to segments-attach-to]
 
  hatch 2 [
    set segment-handedness -1 ^ handedness-power
    set handedness-power handedness-power + 1
    orient-segment-body-attachment  segment-handedness these-two-segments-attach-to
    ]
  
 if segments-attach-to = "3 sides"
 [
   set these-two-segments-attach-to "side-2"
   hatch 2 [
    set segment-handedness -1 ^ handedness-power
    set handedness-power handedness-power + 1
    orient-segment-body-attachment  segment-handedness these-two-segments-attach-to
    ]
 ]
   if segments-attach-to = "3 sides"
 [
   set these-two-segments-attach-to "side-3"
   hatch 2 [
    set segment-handedness -1 ^ handedness-power
    set handedness-power handedness-power + 1
    orient-segment-body-attachment  segment-handedness these-two-segments-attach-to
    
    ]
 ]  
 
     if length segment-DNA > 0 [  analyze-last-segment-color item (length segment-DNA - 1 ) segment-DNA]
end 

to orient-segment-body-attachment [this-segment-handedness these-two-segments-attach-to]
    set segment-tRNA segment-DNA
    set breed bug-segment-makers
    set label ""
    if these-two-segments-attach-to ="back" [right 170 * this-segment-handedness]
    if these-two-segments-attach-to ="side" [right 90 * this-segment-handedness]
    if these-two-segments-attach-to ="front" [right 10 * this-segment-handedness]
        if these-two-segments-attach-to ="side-1" [right 130 * this-segment-handedness]
        if these-two-segments-attach-to ="side-2" [right 90 * this-segment-handedness]
        if these-two-segments-attach-to ="side-3" [right 50 * this-segment-handedness]
    let this-segment-radius (size / 4)
    bk this-segment-radius ;;* (%-segment-separation / 100) 
    if length segment-DNA > 0 [
      
      repeat length segment-DNA [
        add-one-segment 
        set segment-tRNA remove-item 0 segment-tRNA]   
      
      ]   
    die
end 



;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures
;;;;;;;;;;;;;;;;;;;;;

to go
    
    move-bugs
    
    if selection-mechanism = "ecosystem interactions" [
        age-bugs
        ask bugs [without-interruption [check-for-reproduction]]
        bugs-eat-plants
        grow-plants    
        
    ]
    
   if selection-mechanism = "keep randomly selecting" 
    [every 0.5 [auto-select]]
 
    do-plots
    move-selectors
    move-trackers
    check-caught
    
    ask patches [visualize-plants]
    check-bridges 
    visualize-segments
    
    tick
    visualize-labels
end 

to check-bridges
    ask patches with [region = 0 ] [set pcolor black]
    
      ask patches with [region = 12] [
     ifelse bridge-12  [ set pcolor white]
       [set pcolor small-bridge-color]
     ]
   ask patches with [region = 23] [
     ifelse bridge-23 [ set pcolor white]
       [set pcolor small-bridge-color]
     ]
end 

to move-bugs
  ask bugs [
    let dist (3 * speed-factor)
    let color-self color
    let pcolor-of-patch-ahead [pcolor] of patch-ahead dist
    fd dist
    ifelse pcolor-of-patch-ahead  = black or pcolor-of-patch-ahead = large-bridge-color or pcolor-of-patch-ahead = small-bridge-color
    [ bk dist rt  50 ]
    [ fd dist ] 
    bug-wiggle 
  ]
end 

to bugs-eat-plants
  let energy-gain 8
  ask bugs [if plant-type != nobody and leaves >= 10 [ ;;;and mandible-plant-match? [
           set leaves leaves - 10
          set energy energy + energy-gain
          
         ;; if mandible-plant-match? and use-extra-food-end-segment-match? [
          ;;  show word "gain: " (2 * extra-efficiency-from-plant-match)
          ;;  set energy energy + 2 * extra-efficiency-from-plant-match
        ;;  ]
        ]   
       if energy < 0 [bug-death ]
  ]  
end 

to bug-death  
         let this-parent-bug-id  who 
         ask bug-segments with [this-parent-bug-id = parent-bug-id] [die]        
        die
end 

to remove-half-of-bugs
  ask n-of (floor count bugs / 2) bugs [  bug-death ]
end 

to bug-wiggle
    let new-direction-chance random 100
    right (random-float 40)
    left (random-float 40)
    if new-direction-chance < 2 [right 90]
    if new-direction-chance > 97 [left 90]  
end 

;;;;;;;;;;;;;;;;;;;;;
;; Reproduction and Growth Procedures
;;;;;;;;;;;;;;;;;;;;;

to reset-all-efficiencies
  set efficiency-A 0
  set efficiency-B 0
  set efficiency-C 0
  set efficiency-D 0
  if shade-of? plant-A-color last-segment-color [
   ;;  show (word "shade of ; " plant-A-color "  " last-segment-color)
     set efficiency-A 1 - 1 * abs (plant-A-color - last-segment-color) / 10
    ;; show word "A: " efficiency-A
     ]
  if shade-of? plant-B-color last-segment-color [
;;     show (word "shade of ; " plant-B-color "  " last-segment-color)
     set efficiency-B 1 - 1 * abs (plant-B-color - last-segment-color) / 10
   ;;  show word "B: "efficiency-B
     ]
    if shade-of? plant-C-color last-segment-color [
   ;;  show (word "shade of ; " plant-C-color "  " last-segment-color)
     set efficiency-C 1 - 1 * abs (plant-C-color - last-segment-color) / 10
   ;;  show word "C: "efficiency-C
     ]
        if shade-of? plant-D-color last-segment-color [
  ;;   show (word "shade of ; " plant-D-color "  " last-segment-color)
     set efficiency-D 1 - 1 * abs (plant-D-color - last-segment-color) / 10
   ;;  show word "D: "efficiency-D
     ]
end 

;; reproduce one identical offspring from one
;; of the bugs remaining in the population

to check-for-reproduction                      
  if energy > 100 [  ; 
    set energy energy / 2        
    reproduce-one-bug
    
  ]
end 

to reproduce-one-bug
      hatch 1 [
      set descendants descendants + 1
      set which-descendant-am-I descendants
      set age 0
      
      alter-genetics-offspring-bug
      set label-color black
      set heading (random-float 360)
      set linked? false
      
       if show-segments? [without-interruption [build-full-segment-bug]]
       reset-all-efficiencies
    ]  
end 

to grow-plants
  ask patches [
    set resprout-countdown resprout-countdown - 1
    if resprout-countdown <= 0 [ ;; growing
      set leaves leaves + leaf-regrowth-rate
    ]
        if leaves <= 0 [set resprout-countdown 30]
        if leaves >= max-leaves [  set leaves max-leaves]  
    
  ]
end 

to age-bugs
  ask bugs [
    set energy energy - 5   
    set age age + 1    
    if age > max-bug-age [ bug-death ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;
;; Plotting procedures
;;;;;;;;;;;;;;;;;;;;;

to do-plots
    set-current-plot "Segments of Bugs"
    histogram [ length segment-DNA ] of bugs 
end     

;;;;;;;;;;;;;;;;;;;;;
;; Mouse inspection and seleciton Procedures
;;;;;;;;;;;;;;;;;;;;;

to move-trackers
  if mouse-down? and selection-mechanism = "user moves the inspector view" [
    let snap-shot-mouse-xcor (mouse-xcor)
    let snap-shot-mouse-ycor (mouse-ycor)
    ask one-of trackers [setxy snap-shot-mouse-xcor snap-shot-mouse-ycor]
  ]
end 

to move-selectors
  ask selectors [
    setxy mouse-xcor mouse-ycor
    ;; only show the predator if the mouse pointer is
    ;; actually inside the view
    set hidden? not mouse-inside? or (selection-mechanism != "user selects which bug to remove" and  selection-mechanism != "user selects which bug has offspring")
    if selection-mechanism = "user selects which bug to remove" [
       set shape "x"
       set color gray - 3
    ]
        if selection-mechanism = "user selects which bug has offspring" [
       set shape "star"
       set color yellow - 1
    ]
  ]
end 

to check-caught
  if not mouse-down? or not mouse-inside? [ set mouse-event "" stop ]
  let prey [bugs in-radius (size / 2)] of one-of selectors
  let bug-to-die nobody
  let bug-to-reproduce nobody
  ;; no prey here? oh well
  if not any? prey [ stop ]
  ;; eat only one of the bugs at the mouse location
  if mouse-event != "selected" [ask one-of prey [
        if selection-mechanism = "user selects which bug to remove" [
         set bug-to-die self
         set bug-to-reproduce one-of bugs with [self != bug-to-die]
         set mouse-event "selected"
         
         if bug-to-die != nobody [ ask bug-to-die [bug-death]]
         
    ]
        if selection-mechanism = "user selects which bug has offspring" [
       
         set bug-to-reproduce self
         set bug-to-die one-of bugs with [self != bug-to-reproduce]
         set mouse-event "selected"
         
         ask bug-to-reproduce  [ reproduce-one-bug]
    ]
    
    ]
  ;; replace the eaten bug with a random offspring from the remaining population
  
  
  ]
end 



;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures
;;;;;;;;;;;;;;;;;;;;;

to auto-select
  let bug-to-die nobody
  let bug-to-reproduce nobody
  set bug-to-reproduce one-of bugs
  set mouse-event "selected"
         
  ;; replace the eaten bug with a random offspring from the remaining population
  ask bug-to-reproduce  [show 1 reproduce-one-bug]
  set bug-to-die one-of bugs 
  ask bug-to-die [bug-death]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;Segment related procedures ;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to analyze-last-segment-color [mRNA]
    set last-segment-color approximate-rgb (item 0 color + item 0 (item 3 mRNA)) ( item 1 color + item 1 (item 3 mRNA)) ( item 2 color + item 2 (item 3 mRNA))
end 

to add-one-segment
 let bug-segment-maker self
 let bug-segment nobody
 
 let mRNA item 0 segment-tRNA  ;;mRNA is the next triplet from the tRNA
 
 
 if length mRNA > 0 [
   let this-segment-radius (size / 2)
   fd this-segment-radius * (%-segment-separation / 100)  ;; move foward half of size of old segment
 
   ;;run word "set color approximate-rgb item 0 color item 1 color item 2 color + " item 0 mRNA  ;;the third NetLogo instruction for the segment color
   set size  item 0 mRNA   ;;the first NetLogo instruction for the segment size
   run word (word "right " segment-handedness ) (word " * " item 1 mRNA)  ;;the first NetLogo instruction for the segment size

   set this-segment-radius (size / 2)
   fd this-segment-radius * (%-segment-separation / 100)
 
   hatch 1 [
    set bug-segment self
    set breed bug-segments
     set shape word "segment-" item 2 mRNA  ;;the first NetLogo instruction for the segment size
    set color approximate-rgb (item 0 color + item 0 (item 3 mRNA)) ( item 1 color + item 1 (item 3 mRNA)) ( item 2 color + item 2 (item 3 mRNA))
    set parent-bug-id id-for-segments
    set hidden? false
    create-link-from bug-body [ tie hide-link]  
   ]
 ]
end 

to apply-segment-mutations
    
    if (random-float 100 < deletion-mutation) [delete-gene-segment]    ;;chance-drift-mutation
    if (random-float 100 < duplication-mutation) [duplicate-gene-segment]    ;;chance-drift-mutation
    if (random-float 100 < insertion-mutation) [insert-a-new-gene-segment]    ;;chance-drift-mutation

;;    if (r = 1 and random-float 100 < chance-segment-mutation) [delete-gene-segment]     ;;chance-insertion-mutation
;;    if (r = 2 and random-float 100 < chance-segment-mutation) [duplicate-gene-segment]  ;;chance-duplication-mutation
end 

to setup-initial-random-segments
    set segment-DNA []
    set segment-tRNA []
      repeat (min-init-body-segments + random (max-init-body-segments - min-init-body-segments)) [
                                                                   ;;; add build instructions to DNA string
        ]
        set segment-tRNA segment-DNA
end 

to setup-initial-identical-mono-segments
  let triplet []
  let first-gene .4 ;;random-segment-size
  let second-gene 10 ;;random-segment-turn
  let third-gene 1 ;;random-segment-shape
  let forth-gene random-segment-color-shift
  
  ask bugs [
  set segment-DNA []
  set segment-tRNA []
  set triplet []
  
    set triplet lput (first-gene) triplet     ;; size
    set triplet lput (second-gene) triplet     ;; turn
    set triplet lput (third-gene) triplet         ;; color
    set triplet lput (forth-gene) triplet   ;; shape
  ;;  show triplet
  
    repeat 3 [ set segment-DNA lput triplet segment-DNA ]
  ]
end 

to setup-initial-identical-vari-segments
  let triplet []
    set triplet a-new-DNA-segment
  
    set segment-DNA lput triplet segment-DNA 
end 


;;;;;;;;;;;;;;;;;;;;;
;; Bug Mutation Procedures
;;;;;;;;;;;;;;;;;;;;;

to alter-genetics-offspring-bug
  apply-segment-mutations
  set-phenotype-color
end 

to-report  a-new-DNA-segment
    let triplet []
 
  set triplet lput (random-segment-size) triplet     ;; size
  set triplet lput (random-segment-turn) triplet     ;; turn
  set triplet lput (random-segment-shape) triplet         ;; color
  set triplet lput (random-segment-color-shift) triplet   ;; shape
  report triplet
end 

to insert-a-new-gene-segment
  let number-original-items (length segment-DNA)   ;; number of segments coded for in the DNA
  if number-original-items > 0 [
    let target-item (random number-original-items)   ;; choose a target location in the list
    let segment-DNA-first-set sublist segment-DNA 0 (target-item)    ;; break out the first set of DNA (up to but not including the target location)   
    let segment-DNA-last-set sublist segment-DNA (target-item + 1) (number-original-items)  ;; break out the last set of DNA (past and not including target location) 
    let segment-DNA-target-set lput  a-new-DNA-segment []  
    set segment-DNA (sentence segment-DNA-first-set segment-DNA-target-set segment-DNA-last-set)            ;; string the first set, inserted set, and last set back together
  ]
end 

to duplicate-gene-segment
  let number-original-items (length segment-DNA)   ;; number of segments coded for in the DNA
  let target-item (random number-original-items)   ;; choose a target location in the list
  if number-original-items > 0 and number-original-items < 6 [
  let segment-DNA-first-set sublist segment-DNA 0 (target-item + 1)    ;; break out the first set of DNA (up to and including the target location)
  let segment-DNA-target-set item (target-item) segment-DNA            ;; make a copy of the target segment
  let segment-DNA-last-set sublist segment-DNA (target-item + 1) (number-original-items)  ;; break out the last set of DNA (past and not including target location)
  set segment-DNA-first-set lput segment-DNA-target-set segment-DNA-first-set    ;; put the copied segment at the end of the first set
  set segment-DNA sentence segment-DNA-first-set segment-DNA-last-set            ;; string the first set and last set back together
  ]
end 

to delete-gene-segment
  let number-original-items (length segment-DNA)
  let target-item (random number-original-items)
  if (length segment-DNA > 0) [set segment-DNA remove-item (target-item) segment-DNA  ]
end 

;;;;;;;;;;;;;;;;;;;;;
;; Visualization Procedures
;;;;;;;;;;;;;;;;;;;;;

to visualize-segments
   if not show-segments?  ;;;show-segment-old-state != 
     [ ask bug-segments [die ]]  ;;die]]
   if  show-segments? and show-segment-old-state = false 
   [
      ask bugs [build-full-segment-bug]
      ask bug-segments [set hidden? false]
   ]
   ifelse show-segments? [set show-segment-old-state true] [set show-segment-old-state false]
end 

to visualize-plants
  
  if resprout-countdown <= 0
     [ 
       if plant-type = "A" [set pcolor plant-A-color - 4 * leaves / 100]
       if plant-type = "B" [set pcolor plant-B-color - 4 * leaves / 100]
       if plant-type = "C" [set pcolor plant-C-color - 4 * leaves / 100]
       if plant-type = "D" [set pcolor plant-D-color - 4 * leaves / 100]    
     ]
      if not show-plants? [ set pcolor white if region > 10 [set pcolor black] ]     
end 

;; convert the genetic representation of gene frequency
;; into a phenotype (i.e., a color, using an RGB list
;; instead of a standard NetLogo color)

to set-phenotype-color  ;; turtle procedure
  ;; RGB lists are expected to be in the 0-255 range,
  ;; so we must convert from the 0-100 range in the genotype
  set color (list ((red-gene   / 100) * 255)
                  ((green-gene / 100) * 255)
                  ((blue-gene  / 100) * 255))
end 

to visualize-labels
 ask bugs [
    if bug-labels = "none" [set label ""]
    if bug-labels = "descendant #" [set label which-descendant-am-I]
    if bug-labels = "energy" [set label floor energy]
    if bug-labels = "age" [set label age]
    if bug-labels = "# segments" [set label length segment-DNA]   
    ]
end 
  

;;;;;;;;;;;;;;;;;;;;;;
;; Reporters
;;;;;;;;;;;;;;;;;;;;;;

to-report random-segment-size
   let min-size  0.2
   let max-size  0.6
   let increment 0.1
   report precision  (min-size + increment * floor (random-float (max-size - min-size) / increment ))  2
end 

to-report random-segment-turn
   let min-turn -90
   let max-turn 90
   let increment 10
   let angle (min-turn + increment * floor (random-float (max-turn - min-turn) / increment )) 
   report angle
end 

to-report random-segment-color-shift
   let r-val (random-float 100) 
   let g-val (random-float 100) 
   let b-val (random-float 100) 
   let rgb-list []
   set rgb-list lput r-val rgb-list
   set rgb-list lput g-val rgb-list
   set rgb-list lput b-val rgb-list
   report rgb-list
end 

to-report random-segment-shape
   let gene-value ""
   let gene-seed random 4
   let new-gene-seed word gene-value gene-seed
   report gene-seed
end 

to-report inherited-genes [mothers-alleles fathers-alleles]
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele " "
  let father-allele " "
  if random-float 100 > bug-mandible-loss-mutation-% [set mother-allele (item mother-loci mothers-alleles)]  
  if random-float 100 > bug-mandible-loss-mutation-% [set father-allele  (item father-loci fathers-alleles)]  
  report (word mother-allele father-allele)
end 

to-report mandible-plant-match?
  let match? false
  if plant-type = "A" and (shade-of? plant-A-color last-segment-color) [set match? true]
  if plant-type = "B" and (shade-of? plant-B-color last-segment-color) [set match? true]  
  if plant-type = "C" and (shade-of? plant-C-color last-segment-color) [set match? true]
  if plant-type = "D" and (shade-of? plant-D-color last-segment-color) [set match? true]
   report match?
end 

to-report extra-efficiency-from-plant-match
  let eff 0
  if plant-type = "A" and (shade-of? plant-A-color last-segment-color) [set eff efficiency-A]
  if plant-type = "B" and (shade-of? plant-B-color last-segment-color) [set eff efficiency-B] 
  if plant-type = "C" and (shade-of? plant-C-color last-segment-color) [set eff efficiency-C]
  if plant-type = "D" and (shade-of? plant-D-color last-segment-color) [set eff efficiency-D]
   report eff
end 



  ;; use EVERY to limit the overall speed of the model
  

;;;;;;;;;;;

; *** NetLogo 4.0.2 Model Copyright Notice ***
;
; Copyright 2007 by Uri Wilensky.  All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from Uri Wilensky.
; Contact Uri Wilensky for appropriate licenses for redistribution for
; profit.
;
; To refer to this model in academic publications, please use:
; Novak, M.s and Wilensky, U. (2007). NetLogo Bug Hunt Coevolution model.
; http://ccl.northwestern.edu/netlogo/models/BugHuntCoevolution.
; Center for Connected Learning and Computer-Based Modeling,
; Northwestern University, Evanston, IL.
;
; In other publications, please use:
; Copyright 2007 Uri Wilensky.  All rights reserved.
; See http://ccl.northwestern.edu/netlogo/models/BugHuntCoevolution
; for terms of use.
;
; *** End of NetLogo 4.0.2 Model Copyright Notice ***

There is only one version of this model, created almost 9 years ago by Uri Wilensky.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.