BugHunters Competition

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)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.1pre4 • Viewed 348 times • Downloaded 35 times • Run 0 times
Download the 'BugHunters Competition' modelDownload this modelEmbed this model

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


VERSION

$Id: BugHunters Competition.nlogo 40958 2008-09-04 21:50:13Z tisue $

WHAT IS IT?

This model explores the stability of predator-prey ecosystems. Such a system is called unstable if it tends to result in extinction for one or more species involved. In contrast, a system is stable if it tends to maintain itself over time, despite fluctuations in population sizes.

HOW IT WORKS

There are two main variations to this model.

In the first variation, wolves and sheep wander randomly around the landscape, while the wolves look for sheep to prey on. Each step costs the wolves energy, and they must eat sheep in order to replenish their energy - when they run out of energy they die. To allow the population to continue, each wolf or sheep has a fixed probability of reproducing at each time step. This variation produces interesting population dynamics, but is ultimately unstable.

The second variation includes grass (green) in addition to wolves and sheep. The behavior of the wolves is identical to the first variation, however this time the sheep must eat grass in order to maintain their energy - when they run out of energy they die. Once grass is eaten it will only regrow after a fixed amount of time. This variation is more complex than the first, but it is generally stable.

The construction of this model is described in two papers by Wilensky & Reisman referenced below.

HOW TO USE IT

1. Set the GRASS? switch to TRUE to include grass in the model, or to FALSE to only include wolves (red) and sheep (white).

2. Adjust the slider parameters (see below), or use the default settings.

3. Press the SETUP button.

4. Press the GO button to begin the simulation.

5. Look at the monitors to see the current population sizes

6. Look at the POPULATIONS plot to watch the populations fluctuate over time

Parameters:

INITIAL-NUMBER-SHEEP: The initial size of sheep population

INITIAL-NUMBER-WOLVES: The initial size of wolf population

SHEEP-GAIN-FROM-FOOD: The amount of energy sheep get for every grass patch eaten

WOLF-GAIN-FROM-FOOD: The amount of energy wolves get for every sheep eaten

SHEEP-REPRODUCE: The probability of a sheep reproducing at each time step

WOLF-REPRODUCE: The probability of a wolf reproducing at each time step

GRASS?: Whether or not to include grass in the model

GRASS-REGROWTH-TIME: How long it takes for grass to regrow once it is eaten

SHOW-ENERGY?: Whether or not to show the energy of each animal as a number

Notes:

- one unit of energy is deducted for every step a wolf takes

- when grass is included, one unit of energy is deducted for every step a sheep takes

THINGS TO NOTICE

When grass is not included, watch as the sheep and wolf populations fluctuate. Notice that increases and decreases in the sizes of each population are related. In what way are they related? What eventually happens?

Once grass is added, notice the green line added to the population plot representing fluctuations in the amount of grass. How do the sizes of the three populations appear to relate now? What is the explanation for this?

Why do you suppose that some variations of the model might be stable while others are not?

THINGS TO TRY

Try adjusting the parameters under various settings. How sensitive is the stability of the model to the particular parameters?

Can you find any parameters that generate a stable ecosystem that includes only wolves and sheep?

Try setting GRASS? to TRUE, but setting INITIAL-NUMBER-WOLVES to 0. This gives a stable ecosystem with only sheep and grass. Why might this be stable while the variation with only sheep and wolves is not?

Notice that under stable settings, the populations tend to fluctuate at a predictable pace. Can you find any parameters that will speed this up or slow it down?

Try changing the reproduction rules -- for example, what would happen if reproduction depended on energy rather than being determined by a fixed probability?

EXTENDING THE MODEL

There are a number ways to alter the model so that it will be stable with only wolves and sheep (no grass). Some will require new elements to be coded in or existing behaviors to be changed. Can you develop such a version?

NETLOGO FEATURES

Note the use of breeds to model two different kinds of "turtles": wolves and sheep. Note the use of patches to model grass.

Note use of the ONE-OF agentset reporter to select a random sheep to be eaten by a wolf.

RELATED MODELS

Look at Rabbits Grass Weeds for another model of interacting populations with different rules.

CREDITS AND REFERENCES

Wilensky, U. & Reisman, K. (1999). Connected Science: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. International Journal of Complex Systems, M. 234, pp. 1 - 12. (This model is a slightly extended version of the model described in the paper.)

Wilensky, U. & Reisman, K. (in press). Thinking like a Wolf, a Sheep or a Firefly: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. Cognition & Instruction.

To refer to this model in academic publications, please use: Wilensky, U. (1997). NetLogo Wolf Sheep Predation model. http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use: Copyright 1997 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation 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

;; bugs and birds are both breeds of turtle.
breed [bugs bug]  ;; bugs is its own plural, so we use "bug" as the singular.
breed [birds bird]
breed [students student ]
;; both birds and bugs have energy
bugs-own [ destination-patch  controlled-by-student? owned-by energy]
birds-own [destination-patch  controlled-by-student? owned-by energy]
students-own [destination-patch user-id]
patches-own [grass-spot? countdown]
globals [stride-length bird-reproduce bugs-reproduce
   min-energy-of-any-bug 
   max-energy-of-any-bug 
   avg-energy-of-bugs 
   rock-color
   dirt-color
   grass-color
  ]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to startup
  setup
  set stride-length .2
  set bird-reproduce 4
  set bugs-reproduce 5
  set grass-color green
  set dirt-color brown - 1
  set rock-color gray + 4
 
  hubnet-set-client-interface "COMPUTER" []
  hubnet-reset
end 

to setup
  cp 
  cd
  clear-all-plots
  reset-ticks
  ask bugs with [not controlled-by-student?] [die]
  ask birds [die]
  clear-output
  setup-grass
  
  set-default-shape bugs "bug"
  create-bugs initial-number-bugs  ;; create the bugs, then initialize their variables
  [
    set color blue - 2
    set size 1.5  ;; easier to see
    set label-color yellow + 2.5
    ifelse initial-random-energy? 
      [ set energy random (4 * bugs-gain-from-food)  ]
      [ set energy 4 * bugs-gain-from-food]
    set controlled-by-student? false
    setxy random-xcor random-ycor
  ]
  set-default-shape birds "bird"
  create-birds initial-number-birds  ;; create the birds, then initialize their variables
  [
    set color red - 1
    set size 1.5  ;; easier to see
    set label-color yellow + 2.5
    ifelse initial-random-energy? 
      [ set energy random (2 * bird-gain-from-food)  ]
      [ set energy 2 * bird-gain-from-food]
    set controlled-by-student? false
    setxy random-xcor random-ycor
  ]
  
  ask students [assign-bug-to-student]
  
  display-labels
  update-plots
end 

to setup-grass
  ask patches [set grass-spot? false set pcolor rock-color]
  ask n-of (floor (count patches * %-grass / 100)) patches [ set grass-spot? true ]
  ;; check GRASS? switch.
  ;; if it is true, then grass grows and the bugs eat it
  ;; if it false, then the bugs don't need to eat
    ask patches [
     if grass-spot? [
        ifelse random 2 = 0 
          [set pcolor grass-color]
          [set pcolor dirt-color set countdown random grass-regrowth-time ];; initialize grass grow clocks randomly
       ]
    ]
end 

to setup-new-bugs-for-student [p-user-id]
    set hidden? false
    set color red
    set size 1.5  ;; easier to see
    set label-color red + 2
    ifelse initial-random-energy? 
      [ set energy random (4 * bugs-gain-from-food)  ]
      [ set energy 4 * bugs-gain-from-food]
    set owned-by p-user-id
    set controlled-by-student? true
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Runtime procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if not any? turtles or ticks > length-competition [ stop ]
  ask bugs with [not controlled-by-student?]  [ turn-automated-bugs-and-birds ]
  ask birds with [not controlled-by-student?] [turn-automated-bugs-and-birds]
    
  ask bugs [
    if moving-lose-energy? [
      set energy energy - 1  ;; deduct energy for bugs only if grass? switch is on
    ]
      fd stride-length
      eat-grass
      death
   if reproduce? [ reproduce-bugs ]
    
  ]
  
  ask birds [
    if moving-lose-energy? [
      set energy energy - 1  ;; deduct energy for bugs only if grass? switch is on
    ]
    fd stride-length
    catch-bugs
    death
    if reproduce? [ reproduce-birds ]
    
  ]
  every 0.1
  [
    listen-clients
    send-all-info
    display
  ]
  
   ask patches [ grow-grass ]
  tick
  update-plots
  display-labels
end 

to turn-automated-bugs-and-birds  ;; turtle procedure
  rt random 50
  lt random 50
end 

to eat-grass  ;; bugs procedure
  ;; bugs eat grass, turn the patch brown
  if pcolor = green [
    set pcolor dirt-color
    set energy energy + bugs-gain-from-food  ;; bugs gain energy by eating
  ]
end 

to reproduce-bugs  ;; bugs procedure
  if random-float 100 < bugs-reproduce [  ;; throw "dice" to see if you will reproduce
    set energy (energy / 2)                ;; divide energy between parent and offspring
    hatch 1 [ rt random-float 360 fd stride-length ]   ;; hatch an offspring and move it forward 1 step
  ]
end 

to reproduce-birds  ;; bird procedure
  if random-float 100 < bird-reproduce [  ;; throw "dice" to see if you will reproduce
    set energy (energy / 2)               ;; divide energy between parent and offspring
    hatch 1 [ rt random-float 360 fd stride-length ]  ;; hatch an offspring and move it forward 1 step
  ]
end 

to catch-bugs  ;; bird procedure
  let prey one-of bugs-here                    ;; grab a random bugs
  if prey != nobody                             ;; did we get one?  if so,
    [ ask prey [ die ]                          ;; kill it
      set energy energy + bird-gain-from-food ] ;; get energy from eating
end 

to death  ;; turtle procedure
  ;; when energy dips below zero, die
  let p-owned-by owned-by
  if controlled-by-student? [ask students with [p-owned-by = user-id] [hubnet-reset-perspective user-id]]
  if energy < 0 [ die ]
end 

to grow-grass  ;; patch procedure
  ;; countdown on brown patches: if reach 0, grow some grass
  if pcolor = dirt-color  [
    ifelse countdown <= 0
      [ set pcolor grass-color
        set countdown grass-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Student enter / exit procedures  ;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to create-new-student
  create-students 1
  [
    set user-id hubnet-message-source
    set label user-id
    set hidden? true
    assign-bug-to-student
  ]
end 

to assign-bug-to-student
  
     let p-user-id user-id
     let parent-player self
     let child-bug nobody
     ask bugs with [p-user-id = owned-by] [die]
     hatch 1 [
      set breed bugs 
      set child-bug self
      setup-new-bugs-for-student p-user-id
      ]
      
   ;;   ask parent-player [create-link-from child-bug [ tie set hidden? true]]
end 

to remove-student
  ask bugs with [owned-by = hubnet-message-source  and controlled-by-student?] [die]
  ask students with [user-id = hubnet-message-source]
  [ die ]
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Handle client interactions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to listen-clients
  while [ hubnet-message-waiting? ]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-student ]
    [
      ifelse hubnet-exit-message?
      [ remove-student ]
      [ ask students with [user-id = hubnet-message-source] [ execute-command hubnet-message-tag hubnet-message ]]    
    ]
  ]
end 

to execute-command [command msg]
  
  if command = "View"
    [ orient-my-turtle command msg ]
  if command = "Mouse Up"
    [ ] 
  if command = "my-view"  [
      if msg = "whole world"       [hubnet-reset-perspective user-id]
      if msg = "spotlight on me"   [hubnet-send-follow user-id self max-pxcor]
      if msg = "ride and follow"   [hubnet-send-follow user-id self 5]
   ]
end 

to execute-turn [new-heading]
  set heading new-heading
  ;;fd stride-length
  ;;send-info-to-clients
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plotting Procedures  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-plots
  set-current-plot "populations"
  set-current-plot-pen "bugs"
  plot count bugs
  set-current-plot-pen "birds"
  plot count birds
  
    set-current-plot-pen "grass / 4"
    plot count patches with [pcolor = green] / 4  ;; divide by four to keep it within similar
                                                  ;; range as bird and bugs populations
  
  
  set-current-plot "Bugs with Energy Level"
      histogram [ energy ] of bugs
end 

to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
    ask birds [ set label round energy ]
    if show-energy? [ ask bugs [ set label round energy ] ]
  ]
end 

to orient-my-turtle [name coords]
  let next-destination-patch patch first coords last coords
  if patch-here != destination-patch [
     ask my-agent [ set destination-patch next-destination-patch set heading towards destination-patch ]
  ]
end 

to-report my-agent
  let this-user-id user-id
  let my-bug-or-bird nobody
  set my-bug-or-bird bugs with [owned-by = this-user-id] 
  if any? birds with [owned-by = this-user-id] [set my-bug-or-bird birds with [owned-by = this-user-id]   ]
  report my-bug-or-bird
end 

to-report energy-of-your-bug
  let this-user-id user-id
  let this-bug-energy 0
  if any? bugs with [owned-by = this-user-id] [
      ask bugs with [owned-by = this-user-id] [set this-bug-energy energy ] ]
  report this-bug-energy
end 
;; update the monitors on the client

to send-this-players-info ;; player procedure
  hubnet-send user-id  "Your name" user-id
  hubnet-send user-id "Energy of your bug" energy-of-your-bug
end 

to send-all-info
  ask students with [ user-id = hubnet-message-source ] [send-this-players-info]
  send-common-info
end 

to send-common-info
    update-statistics
    hubnet-broadcast "Min Energy Any Bug" min-energy-of-any-bug
    hubnet-broadcast "Max Energy Any Bug" max-energy-of-any-bug
    hubnet-broadcast "Avg Energy of Bugs" avg-energy-of-bugs
end 

to update-statistics
   set min-energy-of-any-bug min [energy] of bugs
   set max-energy-of-any-bug max [energy] of bugs
   set avg-energy-of-bugs mean [energy] of bugs
end 
  
;;to drop-turtle [name coords]
;;  ask turtles with [grabber = name] 
;;  [ setxy first coords last coords
;;    set grabber "" ]
;;end


There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago BugHunters Competition Download this version
Uri Wilensky over 14 years ago BugHunters Competition Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.