Fish Predator Prey Interaction Model

Fish Predator Prey Interaction Model preview image

1 collaborator

Default-person Ian Kenny (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.4.0 • Viewed 99 times • Downloaded 3 times • Run 0 times
Download the 'Fish Predator Prey Interaction Model' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

globals
[
  patch-counter1 ;counter for setting patch color
  patch-counter2 ;counter for growing patches
]

breed[prey a-prey] ;create prey breed
breed[predators predator] ;create predator breed

patches-own
[
  chl ;chl(mg/m^3) = Chlorophyl-A, a commonly used proxy for phytoplankton biomass
]
turtles-own
[
  energy
  schoolmates ;agentset of nearby fish of the same species
  nearest-neighbor ;closest schoolmate
  targets ;agentset of potential targets for predators
  nearest-target ;closest target for predators
  attackers ;agentset of potential predators
  nearest-attacker ;closest predator to a prey fish
  attack-counter ;counter for whether a predator can attack or not
]

to setup
  ca
  reset-ticks

  ask n-of food-clusters patches ;chl patch sizes are determined by the user
  [
    ifelse food-cluster-size > 20 ;if food-cluster-size is set too small, it will cause an error when the radius is set to food-cluster-size/5
    [
      ask n-of food-cluster-size patches in-radius (food-cluster-size / 5)
      [
        set chl 10
      ]
    ]
    [
      ask n-of food-cluster-size patches in-radius (food-cluster-size / 4)
      [
        set chl 10
      ]
    ]
  ]

  ask patches ;chl values are set in steps and are based upon the chl values of their neighbors, creating a realistic distribution of values
  [
    if chl = 0 and [chl = 10] of one-of neighbors
    [
      set chl 7
    ]
  ]

  ask patches
  [
    if chl = 0 and [chl >= 7] of one-of neighbors
    [
      set chl 4
    ]
  ]

  ask patches
  [
    if chl = 0 and [chl >= 4] of one-of neighbors
    [
      set chl 2
    ]
  ]

  ask patches
  [
    set pcolor scale-color green chl 18 0
    set patch-counter1 25
    set patch-counter2 bloom-time-interval

    if chl = 0
    [
      set pcolor sky
    ]
  ]


  create-prey initial-num-prey-fish ;initialize prey fish
  [
    set size 3
    set color orange
    setxy random-xcor random-ycor
    set schoolmates no-turtles
    set energy 299

    ifelse fish?
    [set shape "fish"]
    [set shape "default"]
  ]

  create-predators initial-num-predator-fish ;initialize predator fish
  [
    set size 5
    set color red
    setxy random-xcor random-ycor
    set schoolmates no-turtles
    set energy 299

    ifelse fish?
    [set shape "fish"]
    [set shape "default"]
  ]
end 

to go
  ask patches
  [
    set patch-counter1 patch-counter1 - 1
    set patch-counter2 patch-counter2 - 1

    if patch-counter2 <= 0
    [
      if chl <= 10 and [chl > 0] of one-of neighbors
      [
        set chl chl + mean [chl] of neighbors ;creates a large chl (phytoplankton) bloom
      ]

      if chl > 10
      [
        set chl 10
      ]

      set patch-counter2 bloom-time-interval
    ]

    if patch-counter1 <= 0 ;updates the map with new chl values
    [
      set pcolor scale-color green chl 18 0

      if chl >= 0 and chl < 0.4
      [
        set pcolor sky
        set chl 0
      ]

      set patch-counter1 25
    ]
  ]

  ask prey
  [
    prey-move
  ]

  ask predators
  [
    predator-move
  ]

  ask turtles
  [
    forward 1
  ]

  tick
end 

to prey-move
  set schoolmates other prey in-radius vision
  set attackers other predators in-radius vision
  set energy energy - 0.2

  if energy < 0
  [
    ask self [die]
  ]

  if energy > 300 ;energy needed to reproduce
  [
    hatch 1
    [
      set schoolmates no-turtles
      set attackers no-turtles
      set energy 100
    ]

    set energy energy - 100 ;reproduction cost
  ]

  ifelse random-float 1 < 0.08 ;random movement
  [
    right (random 50) - 25
  ]
  [
    ifelse any? attackers
    [
      set nearest-attacker min-one-of attackers [distance myself]

      turn-towards (atan [dx] of nearest-attacker [dy] of nearest-attacker) 30 ;prey evasive movement

      if vision > 0
      [
        forward vision / 3
      ]
    ]
    [
      if any? patches with [chl > 1] in-radius 3 ;prey eat phytoplankton
      [
        let food max-one-of patches in-radius 3 [chl]

        turn-towards (towards food) prey-food-affinity

        set energy energy + (chl / 2)
        set chl chl / 2
      ]

      if any? schoolmates
      [
        set nearest-neighbor min-one-of schoolmates [distance myself]

        ifelse distance nearest-neighbor < 1
        [
          turn-away ([heading] of nearest-neighbor) 5 ;separates itself from neighbors if too close
        ]
        [
          turn-towards average-schoolmate-heading 5 ;changes directions to align with neighbors headings to exhibit grouping behavior
        ]
      ]
    ]
  ]
end 

to predator-move
  set schoolmates other predators in-radius vision
  set targets other prey in-radius vision

  set attack-counter attack-counter - 1
  set energy energy - 0.6

  if energy < 0
  [
    ask self [die]
  ]

  if energy > 300 ;energy needed to reproduce
  [
    hatch 1
    [
      set schoolmates no-turtles
      set targets no-turtles
      set energy 100
    ]

    set energy energy - 100 ;reproduction cost
  ]

  ifelse random-float 1 < 0.08 ;random movement
  [
    right (random 50) - 25
  ]
  [
    ifelse any? targets
    [
      set nearest-target min-one-of targets [distance myself]

      ifelse attack-counter <= 0
      [
        turn-away (atan [dx] of nearest-target [dy] of nearest-target) 30 ;predator attack movement

        if vision > 0
        [
          forward vision / 2
        ]

        if random-float 1 < attack-success-rate ;attacks are successful half of the time
        [
          ask nearest-target [die]
          set energy energy + 60
        ]

        set attack-counter 15 ;predators will only attack after a given interval, creating a realistic attack pattern
      ]
      [
        turn-away average-target-heading 20 ;predators will follow their targets
      ]
    ]
    [
      if any? schoolmates ;if predators have no targets, they will school to hunt more efficiently
      [
        set nearest-neighbor min-one-of schoolmates [distance myself]

        ifelse distance nearest-neighbor < 1
        [
          turn-away ([heading] of nearest-neighbor) 5 ;separates itself from neighbors if too close
        ]
        [
          turn-towards average-schoolmate-heading 5
        ]
      ]
    ]
  ]
end 



;Helper functions

to turn-towards [new-heading max-turn-radius] ;turns towards something by subtracting current and new headings
  let turn subtract-headings new-heading heading

  ifelse abs turn > max-turn-radius
  [
    ifelse turn > 0
    [
      right max-turn-radius
    ]
    [
      left max-turn-radius
    ]
  ]
  [
    ifelse turn > 0
    [
      right turn
    ]
    [
      left turn
    ]
  ]
end 

to turn-away [new-heading max-turn-radius] ;turns away from something by subtracting current and new headings
  let turn subtract-headings heading new-heading

  ifelse abs turn > max-turn-radius
  [
    ifelse turn > 0
    [
      right max-turn-radius
    ]
    [
      left max-turn-radius
    ]
  ]
  [
    ifelse turn > 0
    [
      right turn
    ]
    [
      left turn
    ]
  ]
end 

to-report average-schoolmate-heading  ;Cannot simply average heading values (ie. avg of 1 and 359 should be calculated as 0)
  let x-component sum [dx] of schoolmates
  let y-component sum [dy] of schoolmates
  ifelse x-component = 0 and y-component = 0
  [
    report heading
  ]
  [
    report atan x-component y-component
  ]
end 

to-report average-target-heading  ;Cannot simply average heading values (ie. avg of 1 and 359 should be calculated as 0)
  let x-component sum [dx] of targets
  let y-component sum [dy] of targets
  ifelse x-component = 0 and y-component = 0
  [
    report heading
  ]
  [
    report atan x-component y-component
  ]
end 

There is only one version of this model, created 8 months ago by Ian Kenny.

Attached files

File Type Description Last updated
Fish Predator Prey Interaction Model.png preview Preview for 'Fish Predator Prey Interaction Model' 8 months ago, by Ian Kenny Download

This model does not have any ancestors.

This model does not have any descendants.