Trout and lamprey swimming mode;

Trout and lamprey swimming mode; preview image

1 collaborator

Default-person Aryan Chandra (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.2 • Viewed 145 times • Downloaded 9 times • Run 0 times
Download the 'Trout and lamprey swimming mode;' 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

globals [
  max-energy           ;; the maximum amount of energy any animal can have
  min-energy           ;; the minimum amount of energy an animal needs to reproduce
  max-stride           ;; the maximum stride length, the minimum stride length is 0,
                       ;; the stride will always be between these limits
  lampreys-gain-from-food  ;; energy units lampreys get for eating
  trouts-gain-from-food ;; energy units trouts get for eating
  trouts-reproduce      ;; probability that trouts will reproduce at each time step
  lampreys-reproduce       ;; probability that lampreys will reproduce at each time step
  plankton-regrowth-time  ;; number of ticks before eaten plankton regrows.
]

breed [trouts a-trouts]
breed [lampreys a-lampreys]

turtles-own [ energy stride-length ]
patches-own [ countdown ]  ;; patches countdown until they regrow

to setup
  clear-all
  ;; initialize constant values
  set max-stride 3
  set min-energy 200
  set max-energy 500
  set lampreys-gain-from-food 20
  set trouts-gain-from-food 20
  set trouts-reproduce 5
  set lampreys-reproduce 6
  set plankton-regrowth-time 138

  ;; setup the plankton
  ask patches [ set pcolor green ]
  ask patches [
    set countdown random plankton-regrowth-time ;; initialize plankton grow clocks randomly
    if random 2 = 0  ;;half the patches start out with plankton
      [ set pcolor brown ]
  ]

  set-default-shape trouts "fish"
  create-trouts initial-number-trouts  ;; create the trouts, then initialize their variables
  [
    set color white
    set stride-length initial-trouts-stride
    set size max-stride  ;; easier to see
    set energy random max-energy
    setxy random-xcor random-ycor
  ]

  set-default-shape lampreys "line"
  create-lampreys initial-number-lampreys  ;; create the lampreys, then initialize their variables
  [
    set color black
    set stride-length initial-lampreys-stride
    set size max-stride  ;; easier to see
    set energy random max-energy
    setxy random-xcor random-ycor
  ]
  reset-ticks
end 

to go
  if not any? turtles [ stop ]
  ask trouts [
    move
    ;; trouts always loose 0.5 units of energy each tick
    set energy energy - 0.5
    ;; if larger strides use more energy
    ;; also deduct the energy for the distance moved
    if stride-length-penalty?
    [ set energy energy - stride-length ]
    eat-plankton
    maybe-die
    reproduce-trouts
  ]
  ask lampreys [
    move
    ;; lampreys always loose 0.5 units of energy each tick
    set energy energy - 0.5
    ;; if larger strides use more energy
    ;; also deduct the energy for the distance moved
    if stride-length-penalty?
    [ set energy energy - stride-length ]
    catch-trouts
    maybe-die
    reproduce-lampreys
  ]
  ask patches [ grow-plankton ]
  tick
end 

to move  ;; turtle procedure
  rt random-float 50
  lt random-float 50
  fd stride-length
end 

to eat-plankton  ;; trouts procedure
  ;; trouts eat plankton, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + trouts-gain-from-food  ;; trouts gain energy by eating
    if energy > max-energy
    [ set energy max-energy ]
  ]
end 

to reproduce-trouts  ;; trouts procedure
  reproduce trouts-reproduce trouts-stride-length-drift
end 

to reproduce-lampreys  ;; lampreys procedure
  reproduce lampreys-reproduce lampreys-stride-length-drift
end 

to reproduce [reproduction-chance drift] ;; turtle procedure
  ;; throw "dice" to see if you will reproduce
  if random-float 100 < reproduction-chance and energy > min-energy [
    set energy (energy / 2 )  ;; divide energy between parent and offspring
    hatch 1 [
      rt random-float 360
      fd 1
      ;; mutate the stride length based on the drift for this breed
      set stride-length mutated-stride-length drift
    ]
  ]
end 

to-report mutated-stride-length [drift] ;; turtle reporter
  let l stride-length + random-float drift - random-float drift
  ;; keep the stride lengths within the accepted bounds
  if l < 0
  [ report 0 ]
  if stride-length > max-stride
  [ report max-stride ]
  report l
end 

to catch-trouts  ;; lampreys procedure
  let prey one-of trouts-here
  if prey != nobody
  [ ask prey [ die ]
    set energy energy + lampreys-gain-from-food
    if energy > max-energy [set energy max-energy]
  ]
end 

to maybe-die  ;; turtle procedure
  ;; when energy dips below zero, die
  if energy < 0 [ die ]
end 

to grow-plankton  ;; patch procedure
  ;; countdown on brown patches, if reach 0, grow some plankton
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown plankton-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end 


; Copyright 2006 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created over 6 years ago by Aryan Chandra.

Attached files

File Type Description Last updated
Trout and lamprey swimming mode;.png preview Preview for 'Trout and lamprey swimming mode;' over 6 years ago, by Aryan Chandra Download

This model does not have any ancestors.

This model does not have any descendants.