Krill Swarm

No preview image

1 collaborator

Krill_swarm_preview Shirley Bekins (Author)


(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.1 • Viewed 73 times • Downloaded 1 time • Run 0 times
Download the 'Krill Swarm' modelDownload this modelEmbed this model

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


My model explores the effect of varying oxygen levels in an aquatic environment and other related biological parameters on a population of Antarctic krill. A krill is a small swimming crustacean that lives in large schools or swarms. Krill are an important part of the marine food chain as a key food source for baleen whales, fish, birds and other marine life.

My model is inspired by a 2010 paper by Brierley and Cox. The authors state, "Group behavior can be complex, but we have shown here that a simple mechanism, in which individuals within shoals juggle only their access to oxygen-rich water and exposure to predation, can explain observed shoal shape. Decreasing oxygen availability in a warming world ocean may impact shoal structure: because structure affects catchability by predators and fishers, understanding the response will be necessary for ecological and commercial reasons." (p. 1758) My model simulates an interrelationship between oxygen in an aquatic environment and a krill population, a key biological entity in our oceans.


The model simulates an aquatic environment with varying levels of oxygen set by a slider. The aquatic environment is composed of patches (a type of agent). The other agents in the model are krill. Krill have their own oxygen level for metabolism and movement. Krill swarm, similar to how birds flock or fish school. This model uses Wilensky's Flocking model code to simulate swarming patterns. Krill use oxygen when they move, which is similar to how wolves and sheep use energy when they move in the Wolf-Sheep Predation model. Krill reproduce if they have a threshold oxygen level because reproduction typically requires more physical capacity.

After the model starts, krill access additional oxygen based on a slider, which also includes some randomness. In addition, when krill access more oxygen from the water, this procedure decreases the oxygen levels in water patches. Krill die when they have an oxygen level of less than 1 unit. The water or patches die when they have an oxygen level of less than 10 units. The model stops when there are no more living krill. Note that in this model, krill describes both individuals and the swarm, or aggregation of individuals.

The Interface Tab When you open the model, you see the Interface tab where you adjust parameters for the model.

Adjust the size of the krill population by using the population slider. You adjust the population size between 1 and 1000 krill. Each krill starts the simulation with a random level of oxygen between 0 and 299 units.

Adjust the PERCENT-LOW-WATER-OXYGEN slider. You adjust the percentage or proportion of low oxygen patches in the water environment from 0 to 100 percent. The model defines a low oxygen environment as 1/10th the level of oxygen in the rest of the environment. If you adjust the PERCENT-LOW-WATER-OXYGEN slider to 5%, then approximately 5% of the total patches consists of low oxygen patches. If you adjust this slider to 100%, all patches have a low oxygen level.

Adjust the OXYGEN-GAIN. This is a slider that allows krill to add more oxygen to their initial level. To include randomness, the code executes a random choice between adding the oxygen-gain value from the slider, adding only half the oxygen-gain, or if neither of these two choices is executed adding nothing. In addition, when a krill obtains an oxygen increase, it decreases the oxygen level of the water (WATER-OXYGEN).

Adjust the REPRODUCTION-THRESHOLD. This is a slider based on the Wolf-Sheep Predation model. The value is 150 to 300 units, and represents the minimum oxygen level required to reproduce. If the slider is set to 150, then a krill with an oxygen level of 150 or above reproduces. When it reproduces, it will give half of its oxygen to its offspring.

Turn on or off the SHOW-OXYGEN switch. This switch will display a label for each krill with its initial oxygen level. As the model runs, the label will update. You may also wish to run the model with the switch off, as it is easier to see krill movement without labels.

Press the SETUP button. The world initializes with water and krill. If the slider is set to include low oxygen patches, these patches appear as lighter blue. The rest of the world appears as darker blue patches. The low oxygen patches are dispersed randomly in the world. Krill populate the world in random locations and have an initial random level of oxygen.

Press the GO button to start the model. Krill FLOCK (swarm). As mentioned previously, the model uses code from Wilensky's Flocking model. The three principle commands for flocking are SEPARATE, ALIGN AND COHERE. Because this model is not primarily concerned with the flocking phenomenon, the code sets values for flocking in the Code tab. Krill use 1 unit of oxygen when they FLOCK.

Krill reproduce if they have a threshold level of oxygen, which is set by the slider between 150 and 300 units of oxygen. A krill needs a relatively high level of oxygen to reproduce. When a krill parent reproduces, it will use half of its oxygen and give it to the krill offspring.

Krill access oxygen through the GET-OXYGEN procedure. This procedure allows for some oxygen replenishment as krill flock. This procedure is designed with an element of randomness. The model randomly selects one of two choices: 1.) krill will gain an oxygen value by using the slider, or 2.) krill will gain oxygen from the slider value divided by half. If one of the two choices is not selected, krill will not gain any oxygen.

At each time step, krill check if they are dead. Death is defined as an oxygen level less than 1 unit. The model will stop running when all krill are dead. In addition, the water patches will check if they are dead. Death for the water patch is defined as an water-oxygen level less than 10 units.


As the model runs, observe the aggregate patterns to see krill swarming (Suggest turning OFF the Show-Oxygen switch to see the swarming). With the Show-Oxygen switch turned on, you see the changing levels of oxygen for each individual krill. Do you notice how the oxygen levels in the environment change over time? You can inspect patches and see how the water-oxygen levels of patches change.

Look at the Population Over Time plot to see how the population size changes. Watch the Count Krill monitor box on the Interface tab to see how the krill population changes. What happens when you change the reproduction threshold to either lower or higher?


Adjust the parameters and see what the outcomes are. Run the model several times to see if and how the outcomes change, even with the same parameters. Remember that this model is stochastic and includes elements of randomness. The model initializes with some random parameters such as location of low oxygen water patches, oxygen levels for krill, and how much oxygen krill can gain. You should run the model many times to see aggregate patterns emerge.


To keep this model simple, the model does not include predators such as fish or whales which will eat krill. This predation will affect population size and possibly swarm shape. A potential extension is to include predators and to add predation avoidance behaviors, such as krill moving away from predators and swarming in larger groups or swarms.

The model does not address herd behaviors in biological literature such as positions within a swarm as protective measures against predators. A potential extension could utilize some type of evolutionary adaption for krill exhibiting certain protective behaviors.

Another possibility for an extension is to create low oxygen areas within specific spatial parameters. The current model will randomly distribute low oxygen areas. In addition, for simplicity krill do not eat but rather depend on oxygen for metabolism and movement.

This model is a 2-D model. Could you create a 3-D model that models both oxygen levels and some predators in the environment? What patterns or shapes of swarms might result from a 3-D model?


In Netlogo, the world is comprised of agents. Agents are turtles, patches, links and the observer. This model includes two main types of agents: krill and water. Krill are turtles or mobile agents moving through the world. Water is a patch, which does not move and represents the world, in this case an aquatic environment. This world is a two dimensional toroidal grid with 5,041 patches. The model includes an observer which acts like an invisible overseer for the world.

The model uses a built-in Netlogo feature or primitive called hatch. The hatch command creates new turtles or krill. The krill offspring inherits its variables from its parent, including location. In this model, the offspring obtains half of its parent's oxygen.

Netlogo has a built-in library for turtle shapes such as arrows, bugs, cars, animals, etc. To make a realistic krill shape, this model creator drew a krill shape and included it in the turtle shape library.


The krill swarm model uses code from Wilensky's Flocking and Wolf-Sheep Predation models referenced below.


This model uses code from Wilensky's Flocking model and Wolf-Sheep Predation models cited below. The model is inspired by the Brierley and Cox paper cited below.

Wilensky, U. (1998). NetLogo Flocking model. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

Wilensky, U. (1997). NetLogo Wolf Sheep Predation model. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

Brierley, A and Cox, M. "Shapes of Krill Swarms and Fish Schools Emerge as Aggregation Members Avoid Predators and Access Oxygen," Current Biology (2010); 20: 1758-1762.

Comments and Questions

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

Click to Run Model

turtles-own [
 oxygen ;; krill have oxygen variable
 flockmates ;; agentset of nearby krill
 nearest-neighbor ] ;; closest one of flockmates

patches-own [ water-oxygen ] ;; water has oxygen variable

to setup
  create-turtles population ;; create krill by adjusting population slider, initialize variables
  [ set shape "krill"  ;; krill have shrimp-like shape
    set color orange + 2  ;; krill are reddish orange
    set size 4  ;; easier to see
    set label-color black ;; label is black for visibility, can be turned on or off with switch
    set oxygen random-float 300  ;; give krill random initial level of oxygen,
    ;; greater than or equal to 0 and less than 300 units
    setxy random-xcor random-ycor ;; give krill random initial location
    set flockmates no-turtles ]
  display-labels ;; display label showing initial level of oxygen for krill
  ask patches ;; create patches representing aquatic environment
  [ ifelse random-float 100.0 < percent-low-water-oxygen ;; throw "dice" to see if patches will have low oxygen level
    [ set pcolor blue - 20 ] ;; lighter blue patches have lower initial levels of oxygen
    [ set pcolor blue - 10 ] ] ;; darker blue patches have higher initial levels of oxygen
  ask patches with [ pcolor = blue - 20 ]
  [ set water-oxygen 50  ] ;; lighter blue patches have 50 initial units of oxygen
  ask patches with [ pcolor = blue - 10 ]
  [ set water-oxygen 500 ]  ;; darker blue patches have 500 initial units of oxygen

to go
  if not any? turtles [ stop ] ;; simulation will stop when all turtles are dead
  ask turtles
  [ flock ]  ;; krill will flock (swarm)
  repeat 5 [ ask turtles [ fd 0.1 ] display ];; make the turtles animate more smoothly
  ask turtles
  [ set oxygen oxygen - 1  ;; take away a unit of oxygen from flocking movement
    reproduce-krill ;; krill reproduce
    get-oxygen ;; krill add oxygen to initial amount
    check-if-dead  ;; krill checks if dead due to insufficient oxygen
    check-if-water-dead ] ;; patch checks if dead due to insufficient oxygen
  tick ;; a time interval
  display-labels ;; after a time interval update krill oxygen level

to reproduce-krill ;; turtle procedure
  if oxygen > reproduction-threshold ;; give birth to a krill if oxygen level greater than birth threshold
  [ set oxygen ( oxygen / 2 ) ;; divide oxygen between parent and offspring
    hatch 1 [ rt random-float 360 fd 1 ] ;; produce an offspring which turns right by random degree and moves forward

to get-oxygen ;; turtle procedure
  let choice random 2
   choice = 0 [
    set oxygen oxygen + oxygen-gain  ;; increase krill's oxygen by slider value
    set water-oxygen water-oxygen - oxygen-gain ]  ;; decrease water oxygen on patch by slider value
    choice = 1 [
    set oxygen oxygen + ( oxygen-gain / 2 ) ;; increase krill's oxygen by half slider value
    set water-oxygen water-oxygen - oxygen-gain / 2 ]
  ;; elsecommands
  [ set oxygen oxygen + 0
    set water-oxygen water-oxygen + 0 ])

to check-if-dead
  if oxygen < 1 [ die ] ;; krill dies if has less than 2 units of oxygen

to check-if-water-dead
  if water-oxygen < 10
  [ die ]

to display-labels ;; displays krill energy levels
  ask turtles [ set label "" ]
  if show-oxygen? [
    ask turtles [ set label round oxygen ] ;; if show-oxygen label is on, display labels

;; due to length of full flocking procedure, this code presented after all other procedures above

to flock  ;; turtle procedure
  find-flockmates ;; defined as other turtles within a radius of 5 patches
  if any? flockmates
    [ find-nearest-neighbor
      ifelse distance nearest-neighbor < 1 ;; minimum separation
        [ separate ]
        [ align
        cohere ] ]

to find-flockmates  ;; turtle procedure
  set flockmates other turtles in-radius 5 ;; krill has vision of 5 patches

to find-nearest-neighbor ;; turtle procedure
  set nearest-neighbor min-one-of flockmates [distance myself] ;; reports a random flockmate with closest distance

to separate  ;; turtle procedure
  turn-away ([heading] of nearest-neighbor) 1 ;;max-separate-turn

to align  ;; turtle procedure
  turn-towards average-flockmate-heading 5 ;; max-align-turn

to-report average-flockmate-heading  ;; turtle procedure
  let x-component sum [dx] of flockmates
  let y-component sum [dy] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]

to cohere  ;; turtle procedure
  turn-towards average-heading-towards-flockmates  3 ;; max-cohere-turn

to-report average-heading-towards-flockmates  ;; turtle procedure
  let x-component mean [sin (towards myself + 180)] of flockmates
  let y-component mean [cos (towards myself + 180)] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]


to turn-towards [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings new-heading heading) max-turn

to turn-away [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings heading new-heading) max-turn
;; turn right by "turn" degrees (or left if "turn" is negative),
;; but never turn more than "max-turn" degrees

to turn-at-most [turn max-turn]  ;; turtle procedure
  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]

There is only one version of this model, created 4 months ago by Shirley Bekins.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.