Wolf Sheep Benchmark

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (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.0beta5 • Viewed 185 times • Downloaded 15 times • Run 1 time
Download the 'Wolf Sheep Benchmark' 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: Wolf Sheep Benchmark.nlogo 37529 2008-01-03 20:38:02Z craig $

Comments and Questions

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

Click to Run Model

globals [ result ]
breed [ sheep a-sheep ]
breed [ wolves wolf ]
turtles-own [ energy prey ]
patches-own [ countdown ]

to benchmark
  random-seed 579
  setup
  reset-timer
  repeat 400 [ go ]
  set result timer
end 

to setup
  ca
  ask patches [ set pcolor green ]
  if grass? [
      ;; indicates whether the grass switch is on
      ;; if it is true, then grass grows and the sheep eat it
      ;; if it false, then the sheep don't need to eat
    ask patches [
      set countdown random grass-delay ;; initialize grass grow clocks randomly
      if (random 2) = 0  ;;half the patches start out with grass
          [ set pcolor brown ]
    ]
  ]

  create-ordered-sheep init-sheep  ;; create the sheep, then initialize their variables
  ask sheep
  [
    set color white
    set energy random-float (2 * sheep-metabolism)
    set shape "sheep"
    setxy random world-width random world-height
  ]

  create-ordered-wolves init-wolves  ;; create the wolves, then initialize their variables
  ask wolves
  [
    set color black
    set energy random-float (2 * wolf-metabolism)
    set shape "wolf"
    setxy random world-width random world-height
  ]

  if plot? [ graph ]
end 

to go
  ask sheep [
    move
    if grass? [
      set energy energy - 1  ;; deduct energy for sheep only if grass? switch is on
      eat-grass
    ]
    reproduce-sheep
    death
  ]
  ask wolves [
    move
    set energy energy - 1  ;; wolves lose energy as they move
    catch-sheep
    reproduce-wolves
    death
  ]
  if grass? [ ask patches [ grow-grass ] ]
  if plot? [ graph ] ;; plot populations
  tick
  if (count turtles = 0) [ stop ]
end 

to move  ;; turtle procedure
  rt random 50 - random 50
  fd 1
end 

to eat-grass  ;; sheep procedure
  ;; sheep eat grass, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + sheep-metabolism  ;; sheep gain energy by eating
  ]
end 

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

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

to catch-sheep  ;; wolf procedure
  set prey one-of sheep-here  ;;set prey to ID of one of the sheep in your patch
  if (prey != nobody) [              ;;check if prey represents a sheep (there is no sheep with ID = -1)
    ask prey [ set energy -1 ]       ;; sheep will then die on next tick
    set energy energy + wolf-metabolism    ;;get energy from sheep
  ]
end 

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

to grow-grass  ;; patch procedure
  ;; countdown on brown patches, if reach 0, grow some grass
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown grass-delay ]
      [ set countdown (countdown - 1) ]
  ]
end 

to graph
  set-current-plot-pen "sheep"
  plot count sheep
  set-current-plot-pen "wolves"
  plot count wolves
  if grass? [
    set-current-plot-pen "grass / 4"
    plot count patches with [ pcolor = green ] / 4  ;; divide by four to keep it within similar
                                                ;; range as wolf and sheep populations
  ]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago Wolf Sheep Benchmark Download this version
Uri Wilensky over 14 years ago Wolf Sheep Benchmark Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.