Mites

No preview image

1 collaborator

Default-person Guillaume Chomé (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 234 times • Downloaded 22 times • Run 0 times
Download the 'Mites' 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

;sur la base de test v1.4
  
turtles-own [dispersion-treshold-value moving-treshold-value dispersion-tendency energy density-feel trigger-density previous-position 
  p-dispersion-tendency p-dispersion-treshold-value p-moving-treshold-value p-trigger-density sex number-offspring]
patches-own [penergy silk penergy0]


globals[mort-noir mort-energie  
  booleanCouleurN booleanCouleurG pot-size   
  µ-disp-tendency0 s-disp-tendency0
  gain-from-grazing nombre-max-mites-feuille
  liste generation liste-disp-tend liste-trigger-dens
  listeFemale listeMale nombre-feuille liste-suivis liste-distances
  temp-patch temp-head temp-voisin temp-choice-disp temp-choice-move temp-dir temp-list-silk temp-list-dir temp-t temp-list-silk-grey temp-list-silk-green
  compteur comp comp2 comp3]


; SETUP

to setup
  clear-all
  setup-patches
  setup-mites
  set mort-noir 0 set mort-energie 0
  reset-ticks
end 

to reset
  
  set generation (generation + 1 )
  
  set liste-disp-tend lput (mean [dispersion-tendency] of turtles) liste-disp-tend
  set liste-trigger-dens lput (mean [trigger-density] of turtles) liste-trigger-dens
    
  setup-patches
  setup-mites-next-gen  
  
  set mort-noir 0 set mort-energie 0
  reset-ticks
end 

to setup-patches
  let x -1
  let ok true
  while [ok] [
    ask patches [if (pxcor > x) and (pxcor < x + 10) and (pycor > 6) and (pycor < 15) [set pcolor green]]    
    ask patches [if (pxcor >= x + 10 ) and (pxcor < x + 10 + 90) and (pycor > 7) and (pycor < 14) [set pcolor grey]]
    set x x + 99
    if x >= 1409 [set ok false]
  ]   ;;setup the patches of our setups 1 patch = 1mm
  ask patches [if pcolor = green or pcolor = grey [set penergy0 10000 set penergy penergy0 set silk 0]]
end 

to setup-mites
  
  ;to run multiple generation
  
  set liste-suivis (list)  
  set pot-size 100
  
  ;defining the mites parameters
  create-turtles density-of-test [set dispersion-tendency ((random ((s-disp-tendency * 2) * 100)) / 100 + µ-disp-tendency - s-disp-tendency) set energy 100]; ;;create the n original mites that will evolve.
  ask turtles [ set color red 
    set liste-suivis lput who liste-suivis]
  ask turtles [set dispersion-treshold-value set-dispersion-treshold-value set moving-treshold-value p-moving set trigger-density ((random ((s-trigger-density * 2) * 100)) / 100 + µ-trigger-density - s-trigger-density)] ; si trigger-density <1 -> mort energie, pk?
  ask turtles [ set energy (pot-size * 0.8) set sex "F" set number-offspring 0]
  ask turtles [
    set p-dispersion-tendency (dispersion-tendency)
    set p-dispersion-treshold-value (dispersion-treshold-value)
    set p-moving-treshold-value (moving-treshold-value)
    set p-trigger-density (trigger-density)  ]
  set gain-from-grazing 0.3
  set temp-choice-disp false
  distribution 3
  
  
  ;defining the mites parameters
  set gain-from-grazing 0.3
  set temp-choice-disp false

  set temp-list-dir (list 0 45 90 135 180 225 270 315 360)
  ;distribution
end 

to distribution [maniere]
  if maniere = 1[
  (foreach [who] of turtles [ask turtle ? [
        ifelse ((count turtles with [(xcor >= 0) and (xcor < 0 + 9) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [ setxy ((random 8) + 1) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 99) and (xcor < 108) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 99) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 198) and (xcor < 207) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 198) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 297) and (xcor < 306) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 297) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 396) and (xcor < 405) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 396) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 495) and (xcor < 504) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 495) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 594) and (xcor < 603) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 594) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 693) and (xcor < 702) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 693) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 792) and (xcor < 801) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 792) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 891) and (xcor < 900) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 891) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 990) and (xcor < 999) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 990) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 1089) and (xcor < 1098) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 1089) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1188) and (xcor < 1197) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 1188) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1287) and (xcor < 1296) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 1287) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1386) and (xcor < 1395) and (ycor >= 7) and (ycor < 15)]) < number-of-mites / 15) [setxy ((random 8) + 1386) ((random 8) + 7)][die
        ]]]]]]]]]]]]]]]]])
  ]
  if maniere = 2 [
    set nombre-feuille (list)
    let bouse (list)
    file-open "distributions-heterogenous.txt" 
    if number-of-mites = 45 [if file-read = "LD" [set nombre-feuille one-of file-read]]    
    if number-of-mites = 120 [set bouse file-read-line if file-read = "MD" [set nombre-feuille one-of file-read]]    
    if number-of-mites = 195 [set bouse file-read-line set bouse file-read-line if file-read = "HD" [set nombre-feuille one-of file-read]]
    file-close
    (foreach [who] of turtles [ask turtle ? [
        ifelse ((count turtles with [(xcor >= 0) and (xcor < 0 + 9) and (ycor >= 7) and (ycor < 15)]) < (item 0 nombre-feuille)) [ setxy ((random 8) + 1) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 99) and (xcor < 108) and (ycor >= 7) and (ycor < 15)]) < item 1 nombre-feuille) [setxy ((random 8) + 99) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 198) and (xcor < 207) and (ycor >= 7) and (ycor < 15)]) < item 2 nombre-feuille) [setxy ((random 8) + 198) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 297) and (xcor < 306) and (ycor >= 7) and (ycor < 15)]) < item 3 nombre-feuille) [setxy ((random 8) + 297) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 396) and (xcor < 405) and (ycor >= 7) and (ycor < 15)]) < item 4 nombre-feuille) [setxy ((random 8) + 396) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 495) and (xcor < 504) and (ycor >= 7) and (ycor < 15)]) < item 5 nombre-feuille) [setxy ((random 8) + 495) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 594) and (xcor < 603) and (ycor >= 7) and (ycor < 15)]) < item 6 nombre-feuille) [setxy ((random 8) + 594) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 693) and (xcor < 702) and (ycor >= 7) and (ycor < 15)]) < item 7 nombre-feuille) [setxy ((random 8) + 693) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 792) and (xcor < 801) and (ycor >= 7) and (ycor < 15)]) < item 8 nombre-feuille) [setxy ((random 8) + 792) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 891) and (xcor < 900) and (ycor >= 7) and (ycor < 15)]) < item 9 nombre-feuille) [setxy ((random 8) + 891) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 990) and (xcor < 999) and (ycor >= 7) and (ycor < 15)]) < item 10 nombre-feuille) [setxy ((random 8) + 990) ((random 8) + 7)][ 
        ifelse ((count turtles with [(xcor >= 1089) and (xcor < 1098) and (ycor >= 7) and (ycor < 15)]) < item 11 nombre-feuille) [setxy ((random 8) + 1089) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1188) and (xcor < 1197) and (ycor >= 7) and (ycor < 15)]) < item 12 nombre-feuille) [setxy ((random 8) + 1188) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1287) and (xcor < 1296) and (ycor >= 7) and (ycor < 15)]) < item 13 nombre-feuille) [setxy ((random 8) + 1287) ((random 8) + 7)][
        ifelse ((count turtles with [(xcor >= 1386) and (xcor < 1395) and (ycor >= 7) and (ycor < 15)]) < item 14 nombre-feuille) [setxy ((random 8) + 1386) ((random 8) + 7)][die
        ]]]]]]]]]]]]]]]]])
  ]
  if maniere = 3 [ask turtles [setxy ((random 8) + 1) ((random 8) + 7)]] 
end 

to setup-mites-next-gen
  set liste [who] of turtles
  (foreach liste [
    ask turtle ? [
    hatch number-offspring [set sex (ifelse-value (random 100 < 50) ["M"]["F"]) set number-offspring 0 set color color + 10
      set pot-size 100
      set energy (pot-size * 0.8)
      set dispersion-tendency (p-dispersion-tendency + (random (s-disp-tendency / 10 * 2))-((s-disp-tendency / 10)))
      set dispersion-treshold-value (p-dispersion-treshold-value)
      set moving-treshold-value (p-moving-treshold-value)
      set trigger-density (p-trigger-density + (random (s-trigger-density / 10 * 2))-((s-trigger-density / 10))) ] ;set p-m-size m-size set p-dispersion-tendency dispersion-tendency set p-dispersion-treshold-value dispersion-treshold-value set p-moving-treshold-value moving-treshold-value set p-trigger-density trigger-density
    die    
  ]])
  set liste [who] of turtles
  set listeFemale (list)  
  set listeMale (list)
  (foreach liste [ifelse ([sex] of turtle ?) = "F" [set listeFemale lput ([who] of turtle ?) listeFemale][ set listeMale lput ([who] of turtle ?) listeMale]])
  (foreach listeFemale [reproduction ? (one-of listeMale)])
  (foreach listeMale [ask turtle ? [die]])
  
  if (generation = 4) or (generation = 7) or (generation = 10 ) [ sauvegarde (n-of 6 turtles)]
  
  while [(count turtles) > number-of-mites][
    ask one-of turtles [die]
  ] 
  distribution type-simulation
end 

to reproduction [ind male]
  ask turtle ind [
    set p-dispersion-tendency (dispersion-tendency + [dispersion-tendency] of turtle male) / 2
    set p-dispersion-treshold-value (dispersion-treshold-value + [dispersion-treshold-value] of turtle male) / 2
    set p-moving-treshold-value (moving-treshold-value + [moving-treshold-value] of turtle male) / 2
    set p-trigger-density (trigger-density + [trigger-density] of turtle male) / 2
  ]
end 

to sauvegarde [agents]
  let name (word ( word (word (word (word (word (word (word "agent-to-test-" generation) "-")number-of-mites) "-") type-simulation) "-") random 100000) ".txt" )
  let liste-p-dispersion-tendency [p-dispersion-tendency] of agents
  let liste-p-dispersion-treshold-value [p-dispersion-treshold-value] of agents
  let liste-p-moving-treshold-value [p-moving-treshold-value] of agents
  let liste-p-trigger-density [p-trigger-density] of agents
  file-open name
  file-print (word "p-dispersion-tendency " liste-p-dispersion-tendency)
  file-print (word "p-dispersion-treshold-value " liste-p-dispersion-treshold-value)
  file-print (word "p-moving-treshold-value " liste-p-moving-treshold-value)
  file-print (word "p-trigger-density " liste-p-trigger-density)
  file-close
end 

to calcul-distance
  set liste-distances (list)
  (foreach liste-suivis [ if turtle ? != nobody [ask turtle ? [
        ifelse ((xcor >= 0) and (xcor < 0 + 9) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 0 liste-distances][ 
        ifelse ((xcor >= 99) and (xcor < 108) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 1 liste-distances][
        ifelse ((xcor >= 198) and (xcor < 207) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 2 liste-distances][ 
        ifelse ((xcor >= 297) and (xcor < 306) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 3 liste-distances][ 
        ifelse ((xcor >= 396) and (xcor < 405) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 4 liste-distances][ 
        ifelse ((xcor >= 495) and (xcor < 504) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 5 liste-distances][
        ifelse ((xcor >= 594) and (xcor < 603) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 6 liste-distances][ 
        ifelse ((xcor >= 693) and (xcor < 702) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 7 liste-distances][ 
        ifelse ((xcor >= 792) and (xcor < 801) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 8 liste-distances][ 
        ifelse ((xcor >= 891) and (xcor < 900) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 9 liste-distances][ 
        ifelse ((xcor >= 990) and (xcor < 999) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 10 liste-distances][ 
        ifelse ((xcor >= 1089) and (xcor < 1098) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 11 liste-distances][
        ifelse ((xcor >= 1188) and (xcor < 1197) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 12 liste-distances][
        ifelse ((xcor >= 1287) and (xcor < 1296) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 13 liste-distances][
        ifelse ((xcor >= 1386) and (xcor < 1395) and (ycor >= 7) and (ycor < 15)) [set liste-distances lput 14 liste-distances][set liste-distances lput 9999 liste-distances]]]]]]]]]]]]]]]      
  ]]])
   ; liste-distances
end 


;SIMULATION

to go
  if ticks >= 3600 * 24 * sim-length [calcul-distance stop] ;; 3 = number of days
  if count turtles = 0 [stop]
  if generation > 10 [stop]
  mites-move  
  mites-lay-egg  
  check-death
  patch-update  
  tick
end 

to mites-move
  
  ;on bridges
  
  ask turtles [ if pcolor = grey [
      set booleanCouleurN false ;;"patch pas noir"
      set booleanCouleurG false ;;"patch pas gris"
      set temp-head random-normal 90 20
      if (heading >= 180) [set temp-head 180 + temp-head]
      set temp-patch patch-at-heading-and-distance temp-head (deplacement energy pcolor)
      if temp-patch != nobody [ ask temp-patch [if (pcolor = black) [set booleanCouleurN true] if (pcolor = grey) [set booleanCouleurG true]]];; si noir booleanCouleur = true;
      if temp-patch != nobody [ifelse (booleanCouleurN = false) [move-to temp-patch set heading temp-head (lost-energy 2 who)] [ set booleanCouleurN false set comp2 (comp2 + 1) if random 1000000 < p-falling-bridge [set heading temp-head move-to temp-patch set comp3 (comp3 + 1)]]]
      
      set previous-position pcolor
      ]]  ;; if the mites is on a bridge -> move forward with little chance to go back 
  
  ;;----------------------------------------------------------
  ;On patches
    
  ask turtles [ if pcolor = green [     
      ifelse movement-choice who [; random 100 < p-moving[ 
      set booleanCouleurN false ;;"patch pas noir"
      set booleanCouleurG false ;;"patch pas gris"
      set temp-head direction-choice who
      set temp-patch patch-at-heading-and-distance temp-head (deplacement energy pcolor)
      if temp-patch != nobody [ ask temp-patch [if (pcolor = black) [set booleanCouleurN true] if (pcolor = grey) [set booleanCouleurG true]]];; si noir booleanCouleur = true;
      if temp-patch != nobody [ifelse (booleanCouleurN = false) [if (booleanCouleurG = false) [move-to temp-patch set heading temp-head (lost-energy 2 who)]] [ set booleanCouleurN false if random 1000000 < p-falling [set heading temp-head move-to temp-patch set comp (comp + 1)]]] ;;      
      if temp-patch != nobody [if (booleanCouleurN = false) [if (booleanCouleurG = true) [set heading temp-head set comp2 comp2 + 1 if (dispersion-choice who) [move-to temp-patch (lost-energy 2 who) set compteur compteur + 1] ]]] ;; in case of next patch = grey -> go on bridge if choice is true      
      ]
      [grazing who]
      
      set previous-position pcolor 
      ]] ;; moving in p-moving % of the time
end 

to check-death
  
  ;;ask turtles [set label energy] ; allow to have a tag on each mite to follow their energy level
  
  ask turtles [if pcolor = black [(set mort-noir mort-noir + 1) die]] ; if fall in the cotton -> die
  
  ask turtles [if energy < 1 [(set mort-energie mort-energie + 1) die] ]   ; no more energy ->die
  
  ask turtles [if random 10000000 < (5 * ( 1 + ((((density-feel - trigger-density) / trigger-density)) - ((energy - (pot-size / 2)) / pot-size) ))) [die]]
  ;;----------------------------------------------------------
  
  lost-energy 1 -1 ;; the mites loose energy to live
end 

to lost-energy [cond ind]
  if cond = 1 [ask turtles [ set energy energy - 0.1 ]] ; to live
  if cond = 2 [ask turtle ind [ set energy energy - 0.1]] ; to move
  if cond = 3 [ask turtle ind [ set energy energy - 5]] ; to reproduce
end 

to grazing [ind]         
  ask turtle ind [ if ((pcolor = green) and (energy < pot-size) and (penergy >= gain-from-grazing))  [(set energy energy + gain-from-grazing) (set penergy (penergy - gain-from-grazing))]] ; mite gain energy from grazing and patch loose
   ; ask turtles [ if pcolor = green and energy < 100 [set energy energy + 10]] 
end 

to patch-update
  ask turtles [
    set silk (silk + 0.1)
  ]
  ;if ticks - temp-t = 100 [set temp-t ticks ask patches with [silk > (0.5 * silk)] [set silk (silk - (0.5 * silk))]]
end 

to calcul-densite [ind]
  ask turtle ind [set density-feel ((sum [count turtles-here] of neighbors) + (count turtles-here))]  
end 

  ;;----------------------------------------------------------

to-report deplacement [input-energy milieu]
  if milieu = green [report ( 2 + ( 0.5 *(input-energy / pot-size)))]
  if milieu = grey [report (2 +  (0.5 *(input-energy / pot-size)))]
end 

to-report find-max-silk [ind]  
  ask turtle ind [ set temp-voisin (max-one-of neighbors [silk])]
  report temp-voisin
end 

to-report direction-choice [ind]   
  report random 360
end  

to-report movement-choice [ind] ; report wether or not to move
  ifelse ((random 100) < moving-treshold-value) [report true][report false] ;;;
end 

to-report dispersion-choice [ind] ; report wether or not to disperse
  calcul-densite ind ;;;;;;
  ask turtle ind [  
    set temp-choice-disp (
      ifelse-value (dispersion-treshold-value / 100 < ((42.5 / 100 * (dispersion-tendency))+ (20 / 100 * (ifelse-value (density-feel < trigger-density) [0] [density-feel / trigger-density])) + (25 / 100 * (ifelse-value (([pcolor] of find-max-silk ind) = grey) [1][0] )) + (12.5 / 100 * (ifelse-value (energy < (energy / 2)) [0] [energy / pot-size]))  ))
      [true]
      [ifelse-value (random 1000 > 2) [false][true]]     
      )
     ] 
  report temp-choice-disp
end 

  ;;----------------------------------------------------------

to mites-lay-egg
  ask turtles [
    if ((random 10000 < 1) and (energy > 5)) [
      set number-offspring (number-offspring + 1)
      lost-energy 3 who
      ]]
end 
  
  
  ;;----------------------------------------------------------
  ;functions for display

to-report mort1
  report mort-noir
end 

to-report mort2
  report mort-energie
end 

to-report compteur1
  report compteur
end 

to-report compteur3
  report comp3
end 

to-report compteur2
  report comp
end 

to-report compteur4
  report comp2
end 

to-report rapport
  report max [density-feel] of turtles 
end 

to-report rapport2
  ifelse temp-choice-disp [report 1][report 0]
end 

There is only one version of this model, created over 11 years ago by Guillaume Chomé.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.