Mongoose

Mongoose preview image

1 collaborator

Default-person Josh Zettel (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.0 • Viewed 127 times • Downloaded 6 times • Run 0 times
Download the 'Mongoose' 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 [ max-rats ]  ; don't let the rat population grow too large

; rat, mongoose and hawks are all breeds of turtles
breed [ rats rat ]
breed [ mongooses mongoose ]
breed [ hawks hawk ] ;I added a hawks to the model in order to add a 3rd  entity to the food web to target rats and mongooses.

; I also wrote a seperate different model included on the "model-version" tab of "sheep-bears"where bears just eat everything including grass.
; However, look at the "sheep-bears" model after observing my Mongooses and hawks" original model for this assignement.
;I wrote the add on model because wanted to see the dynamic of one predator eating everything. Basically a Tragedy of the commoms.


extensions [ Rnd ] ; I tried adding an extension to a random walk to see if I could get it to work.

turtles-own [ energy ]       ;  rats, mongooses and hawks have energy

patches-own [ countdown ]    ; this is for the rats-mongooses-sugarcane "model-version"

to setup
  clear-all

  ifelse netlogo-web? [ set max-rats 10000 ] [ set max-rats 30000 ]

  ; Check model-version switch
  ; if we're not modeling sugarcane, then the rats don't need to eat to survive
  ; otherwise each 'sugarcane' state of growth and growing logic need to be set up
  ifelse model-version = "rats-mongooses-sugarcane" [
    ask patches [
      set pcolor one-of [ green brown ]
      ifelse pcolor = green
        [ set countdown sugarcane-regrowth-time ]
      [ set countdown random sugarcane-regrowth-time ] ; initialize sugarcane regrowth, clocks randomly for brown patches
    ]
  ]
  [
    ask patches [ set pcolor green ]

    ;
    ;ask patches with [pxcor = 8 ] [set pcolor white] ;here is where I could set up a wall
    ;ask patches with [pycor = -11 ] [set pcolor white]
  ]



  ; The sheep-bears model-version below is different than the "rats-mongooses-hawks" "model-version."
  ; This is where I setup and wrote a completly different model and code to see if I could write a different code setup. I wrote this as a "sheep-bears" only and added it to the "model-version" slider.
  ; To get this "sheep-bears" model to work, you need to set the model version to "sheep-bears" and turn off all the other sliders realated to the "rats-mongooses-hawks" model (set them to zero).

   if model-version = "sheep-bears" [ ; where I created a new code and a model-version
     ask patches [
      set pcolor 66]
  create-turtles 5
  [set shape "footprint other"
    set energy 0
    set size 2
    set color yellow
    setxy random-xcor random-ycor]
  create-turtles 100
  [set shape "sheep"
    set size 2
    set color 52
      setxy random-xcor random-ycor  ;If you run the full code it has multiple turtles and eats everything, However if you use one of the lines of code below it will only eat a-sheep.

     ; ask turtles with [count turtles-here > 1] [ die ]        ;this where the bears hunt a-sheep until the bear catches the sheep, the bear won't die

  ]]






   ; This where the "rats-mongooses-hawks" "model-version" begins, I create the rats, then initialize their variables for the model-versions of  "rats-mongooses-sugarcane" and "rats-mongooses-hawks."

    create-rats  initial-number-rats
  [
    set shape  "rats"
    set color white
    set size 1.5  ; easier to see
    set label-color blue - 2
    set energy random (2 * rats-gain-from-food)
    setxy random-xcor random-ycor
]

  create-mongooses initial-number-mongooses  ; create the rats, then initialize their variables
  [
    set shape "mongoose"
    set color red
    set size 2  ; easier to see
    set energy random (2 * mongooses-gain-from-food)
    setxy random-xcor random-ycor
  ]

  create-hawks initial-number-hawks ; Here is where I added an extra carnivore to the food web. (Hawks)
  [
    set shape "hawk"
    set color black
    set size 2  ; easier to see
    set energy random (2 * hawk-gain-from-food)
    setxy random-xcor random-ycor
  ]

  ;I wanted to set some traps or create some walls that if any of the animals came across it theyt would die..... Maybe that is where a hunter would be?

  ask n-of 13 patches with [pxcor = random 13 ] [set pcolor blue] ; Where I made random blue patches for rats, mongooses and hawks to die off if they run into them.


  display-labels
  reset-ticks
end 

to go
  if not any? turtles [ stop ] ; stop the model if there are no rats, mongooses, hawks.

  if not any? mongooses and count rats > max-rats [ user-message "The rats have ate all of the sugar" stop ]
  ask rats [
    move


    ; in this version, rats eat sugarcane, sugarcane grows, and it costs rats energy to move
    if model-version = "rats-mongooses-sugarcane" [
      set energy energy - 1  ; deduct energy for rats only if running "rats-mongooses-sugarcane" "model-version."
      eat-sugarcane  ; rats eat sugarcane only if running the "rats-mongooses-sugarcane" "model-version."
      death ; rats die from starvation only if running the "rats-mongooses-sugarcane" "model-version."
    ]

    reproduce-rats  ; rats reproduce at a random rate governed by a slider.
  ]

  ask mongooses [
    move
    set energy energy - 1  ; mongooses lose energy as they move.
    eat-rats ; mongooses eat a rat on their patch.
    death ; mongooses die if they run out of energy.
    reproduce-mongooses ; mongooses reproduce at a random rate governed by a slider.
  ]

  ; Here is where I added the Hawks and had them focusing on eating mongooses and doing different target walks in order to see if the mongooses and rats can keep up with the hawks or vice versus.

  ask hawks [
    target-walk ;wait 1                            ; I added this in order to specifically target rats or mongooses in order to see how fast hawks target prey.

    ;weighted-random-walk                          ; I wanted to see the difference between weighted-random-walk and target walk. I can't run them both at the same time, so I turn the semicolon off and on.

    move
    set energy energy - 1  ; hawks lose energy as they move


    eat-mongooses                                   ; eat-mongooses ; hawks eat mongooses and turn patches grey. I have the patches turn grey where hawks eat,(further-down in the code) I did that in order to possibly target a mongoose den and know where they are at.
    death                                           ; hawks die if they run out of energy.
    reproduce-hawks                                 ; hawks reproduce at a random rate governed by a slider
  ]



  if model-version = "rats-mongooses-sugarcane" [ ask patches [ grow-sugarcane ] ]
 ; if model-version = "rats-mongooses-hawks" [ ask rats [ reproduce-rats ] ]






  ; Run this seperately from the "rats-mongooses-hawks" model-version" This is the "sheep-bears" "model-version" only.
  ;Here I wrote a "Sheep-Bears" seperate and compleletly different code for a model version of specifically Bears eating everything that includes the grass, I wanted to understand how the sheep could withstand it.
  ;For the "Sheep-Bears" model to work you have to set the model version to "sheep-bears" and move all of the sliders to zero!     Move the intial-number-sheep, initial-number-wolves, intial-number-bears to 0, before running the "sheep-bears" model
  ;The "sheep-bears' model version moves slower because I set the wait time and the bears are eating all resources within the area. This can be a tragedy of the commons, where all the resources are used up

  if model-version = "sheep-bears" [ ask turtles with [shape = "footprint other"] [if pcolor = 66 [ set pcolor 33]]
if count turtles with [ shape = "sheep"] = 0 [stop]
ask turtles with [ shape = "footprint other" ] [if any? turtles with [ shape = "sheep"] in-radius 1
[set energy energy + 10]]
ask turtles with [ shape = "footprint other" ] [if any? turtles with [ shape = "sheep"] in-radius 1
    [ask turtles with [ shape = "sheep"] in-radius 1 [die]]]
    ask turtles with [shape = "footprint other"] [ forward 1
    rt random 50
    lt random 50]
  ]

wait .1 ; This controls the speed of the bears, I could set the "wait" to a bigger number and the bears will move faster

  ask turtles with [shape = "sheep"] [rt random 50
  lt random 50
  fd 1
  ]
  tick
  display-labels
end 


; This is the continuation of the "rats-mongooses-hawks" "model-version"

to move  ; turtle procedure
  if [pcolor] of patch-here = blue [die] ; here is where the trutles rats-mongooses-hawks traps are set and run into the random blue patches and die.
  rt random 50
  lt random 50
  fd 1
end 

to eat-sugarcane  ; rats procedure ; rats eat sugarcane and turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + rats-gain-from-food  ; rats gain energy by eating
  ]
end 

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

to reproduce-mongooses  ; mongooses procedure           ; reproduce-mongooses, is the same procedure as rats reproducing.
  if random-float 100 < mongooses-reproduce [
    set energy (energy / 2)
    hatch 1 [ rt random-float 360 fd 1 ]
  ]
end 

to reproduce-hawks    ; hawks procedure                  ; reproduce-hawks, is the same as rats and mongooses reproducing, this is how we get the 3rd predator/entity in order to keep up with the other animals that are reproducing.
  if random-float 100 < hawks-reproduce [
    set energy (energy / 2)
    hatch 1 [ rt random-float 360 fd 1 ]
  ]
end 

to eat-rats  ; mongooses procedure
  let prey one-of rats ;rats-here                          ; This is where it can be hawks eating rats or mongooses eating rats, just need to add or remove the semicolon to decide on who gets the energy.
  if prey != nobody  [                                     ; did we get one? if so,
    ask prey [ die ]                                       ; kill it, and...
    ;set energy energy + mongoose-gain-from-food           ; get energy from eating
    set energy energy + hawk-gain-from-food
  ]
end 

to eat-mongooses                                  ; This where I added only hawks eating mongooses.
  let prey one-of mongooses-here
  if prey != nobody  [
    ask prey [ die ]
   set energy energy + hawk-gain-from-food
  ]
end 


;I wrote several different target walks. My different target walks are my things to try part of the "info" tab.
; I wrote a target walk for a hawk to target rats and one for mongooses. You can add the pen down to see the movement

to target-walk                          ; Here you can see the hawks latch onto the mongoose.
 ; pen-down  ; Here is a pen down to track the movement of the target walk if you want to see it...it leaves lots of trails.

                                        ; I want hawks to eat mongoose
ask hawks  [                                    ; I added a monitor to observe the rats, mongooses and hawks numbers.
     let target Rnd:weighted-one-of mongooses with
  [color = red] in-radius 1 [distance myself]
  ifelse target != nobody [
    move-to target
    ask patch-here [set pcolor grey]   ; Here I can track where the hawks are eating mongooses. Maybe to pinpoint mongooses dens.
  ][
    set heading random 360

   fd 1

  ]
]
end 

; Here Is the same code as above, but with hawks targeting rats and turning the patches to yellow. Here you could also change the movement patterns for a different movement pattern and a different radius,
                                                                                                                      ; I wanted to see if changing the Radius and walk slowed/sped up the process.

;to target-walk
;;pen-down
;  ask hawks [
;    let target rnd:weighted-one-of rats with
;    [color = white ] in-radius 1 [distance myself]
;   ; [energy]
;    ifelse target != nobody [
;      move-to target
;      ask patch-here [set pcolor yellow]
;    ][
;    set heading random 360
;    fd 1
;    ]
;  ]
;end

; Here is a target walk for a hawks to specifically target rats. I wanted to see if the rats could die off before the mongooses when the hawks are only eating mongooses.

;to target-walk                                  ; I wanted hawks to target and eat mongooses.
;ask hawks  [
;  let target min-one-of mongooses with
;  [color = red] in-radius 0 [distance myself]
;  ifelse target != nobody [
;    move-to target
;    ;ask patch-here [set pcolor grey]
;  ][
;    set heading random 360
;   fd 1
;  ]
;]
;end

to death  ; turtle procedure (i.e. both mongoose and rats procedure)
  ; when energy dips below zero, die
  if energy < 0 [ die ]
end 

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

to-report sugarcane
  ifelse model-version = "rats-mongooses-sugarcane" [
    report patches with [pcolor = green]
  ]
  [ report 0 ]
end 

to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
    ask mongooses [ set label round energy ]
    if model-version = "rats-mongooses-sugarcane" [ ask rats [ set label round energy ] ]
  ]
end 


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

There is only one version of this model, created about 2 years ago by Josh Zettel.

Attached files

File Type Description Last updated
Mongoose.png preview Preview for 'Mongoose' about 2 years ago, by Josh Zettel Download

This model does not have any ancestors.

This model does not have any descendants.