NetLogo banner

NetLogo Publications
Contact Us

Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Farsi / Persian


NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled because this model uses extensions.)


This is a rats-mongooses-hawks predation model.

The goal of this model is to explore the stability of predator-prey ecosystems.

This model borrowed the building blocks from the wolf-sheep-predation model, and according to the wolf-sheep-predation model, a predation model is where "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."

I wanted to examine these fluctuations even further and see if I could reach stability with three species, therefore I wrote into the code three species dynamics of two predators, mongooseses, hawks and a species they both feed on, which is rats.

The reason I choose the rat, mongoose and hawk is to try to simulate what is happening in some of the Hawaiian islands where the mongoose is an invasive species that was introduced to some of the Hawaiian Islands. They were imported by the sugar industry as an effort to control rats in the sugar cane fields. However, one forgotten fact about the mongoose Hawaiians didn’t realize is that mongooses are active during the day and sleep at night in burrows while rats are primarily the opposite and more active during the night. Thus, the theory of the mongoose controlling the rat population was an epic failure! Now mongooses are ubiquitous among some of the Hawaiian Islands. Yet, mongoose will eat rats when they come upon them, therefore, I thought it would be interesting to model how successful it could have been if the sleep patterns of mongooses and rats lined up and the mongoose also has a predator to eat them, which is a hawk.

Overall, this model will to try to understand how quickly a system coud collapse if there were a variety of predators. Or to see if they could reach an equilibrium with another predator involved.


The first model-version, the "rats-mongooses-hawks" model-version, mongooses, rats and hawks either wander randomly or use the targeted walks to move around the landscape, while the mongooses and hawks look for rats to prey on or the hawk preys on both rats and mongooses or you can set it up to where the mongooses only prey on rats, or the hawk only preys on rats. It depends which code you use that will be listed in the things to try section below. There are also blue patches where the species will die if they move over them. The blue patches were added to observe if setting traps could change the outcome. When running this model-version each step costs the mongooses energy, and they must eat rats in order to replenish their energy, also the hawks use up energy and must eat rats or mongooses or both. When mongooses, hawks or rats run out of energy they die. To allow the population to continue, each mongoose, hawk or rat has a fixed probability of reproducing at each time step. In this variation, I model the sugarcane as "infinite" so that rats always have enough to eat, and I don't explicitly model the eating or growing of sugarcane. As such, rats don't either gain or lose energy by eating or moving. This variation produces interesting population dynamics, it seems diffucult to maintain and can be ultimately unstable. This variation of the model is particularly well-suited to try to understand the balance of the interacting species of mongooses and hawks where rats could be a limited resource, yet an abundant resource.

The second model-version, the "rats-mongooses-sugarcane" version explictly models sugarcane (green) in addition to mongooses and rats. The behavior of the mongooses is identical to the first variation, however this time the rats must eat sugarcane in order to maintain their energy - when they run out of energy they die. Once sugarcane is eaten it will only regrow after a fixed amount of time. This variation is a little more complex than the first, rats can easily overtake everything but you can almost get some stability if the mongooses are eating enough rats. Hawks can also be added to this variation by using the sliders.There are also blue patches where the species will die if they move over them. There are also blue patches in this model where the species will die if they move over them.The blue patches were added to observe if setting traps could change the outcome.

Third model-version "sheep-bears"
A bonus thing to add, since I built this using the wolf-sheep-predation model I wanted to see if I understood how to write the code or if I could write code that did the same thing but written slightly different. By trying to write a different code, but mimicking wolf-sheep-predation, I came up with something similar, yet different.. I wrote a code that just has bears eating sheep and all of the resources and leaving the patches brown. I added the “sheep-bears” code to the model-version tab in this model.


How to use the "rats-mongooses-sugarcane" and the "rats-mongooses-hawks" models.

1. Set the model-version chooser to "rats-mongooses-sugarcane" to include sugarcane eating and growth in the model, or to "rats-mongooses-hawks" to run the model of rats, mongoose and hawks..
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.

How to use the bonus model "bears-sheep"

1. Set the model-version to "bears-sheep."
2. Adjust the slider parameters from the other models to zero. Since it is separate from the mongoose model. If you don't set the sliders to zero from the other models, mongooses, hawks and rats will show up, and they are not part of that model.
3. Press the SETUP button.
4. Press the GO button to begin the simulation.
5. This model is not plotted, you only see bears eating everything. However, there is a wait time added to the code, so you might notice the speed is slower than other models.

MODEL-VERSION: Whether I model rats mongooses/hawks and sugarcane or just rats, hawks and mongooses
INITIAL-NUMBER-RATS: The initial size of rat population
INITIAL-NUMBER-MONGOOSES: The initial size of mongoose population
INITIAL-NUMBER-HAWKS: The initial size of the hawk population
RATS-GAIN-FROM-FOOD: The amount of energy rats get for every sugarcane patch eaten (Note this is not used in the rats-mongooses-hawks model version)
MONGOOSES-GAIN-FROM-FOOD: The amount of energy mongooses get for every rat eaten
HAWKS-GAIN-FROM-FOOD: The amount of energy hawks get for every rat/mongoose eaten (depends which target-walk)
RATS-REPRODUCE: The probability of a rat reproducing at each time step
MONGOOSE-REPRODUCE: The probability of a mongoose reproducing at each time step
HAWKS-REPRODUCE: The probability of hawks reproducing at each time step
SUGARCANE-REGROWTH-TIME: How long it takes for sugarcane to regrow once it is eaten (Note this is not used in the rats-mongooses-hawks model version)
SHOW-ENERGY?: Whether or not to show the energy of each animal as a number

- one unit of energy is deducted for every step a mongoose or hawk takes
- when running the rats-mongooses-sugarcane model version, one unit of energy is deducted for every step a rat takes

There are four monitors to show the populations of the rats, mongooses, hawks and sugarcane, also a populations plot to display the population values over time.

If there are no mongooses or hawks left and too many rats, the model run stops.


When running the rats-mongooses-hawks model variation, watch as the rats, mongooses and hawks populations fluctuate. Notice that increases and decreases in the sizes of each population are related. For some moments in time they have a balance. In what way are they related? What eventually happens?

When running the rats-mongooses-sugarcane model or the rats-mongooses-hawks model, notice the random blue patches (traps). Having these traps can sometimes really impact the population growth, it can depend on hpw many random traps were set. Some times the random blue patches prevents the rats from completely dying off and just continuing in an up and down cycle.

When running the rats-mongooses-sugarcane model or the rats-mongooses-hawks model, notice the patches can turn grey or yellow depending on the targeted walk.(this is listed in things to try)

In the rats-mongooses-sugarcane model variation, notice the green line added to the population plot representing fluctuations in the amount of sugarcane.


For the "rats-mongooses-sugarcane" and the "rats-mongooses-hawks" models.

In the rats-mongooses-sugarcane model or the rats-mongooses-hawks model I coded in target walks. Try going into the code and either code-in or code-out the different walks (to code-in or code-out remove the semicolon (;) in front of the code). Notice how quckly or not so quickly the mongooses and hawks target rats etc. and how the patches can change color depending on the targeted-walk. You can either have mongoose target rats or hawks target mongooses.

Try using the pen-down code in the targeted-walks to see how long of a trail it can leave.

try adjusting the world wraps settings to see if the species stay within an area or if they wonder off.

Try adjusting the sliders/parameters under various settings. Can there be a stabilty?

Try running the rats-mongooses-sugarcane model variation, but setting INITIAL-NUMBER-MONGOOSES to 0. This gives an ecosystem with only rats and sugarcane.

Try coding out the blue patches (traps) and see if the mice die out when running only the mice, or see what happens to rest of the model without the patches.


For the "bears-sheep" bonus model, it's pretty simple without any sliders.

Try changing the times on the "wait" section and see if it gets faster.

Try coding out the blue patches.

Try changing patch colors to see if the bear still eats everything. Get creative, there are ways to change or add to it.


There are a number ways to alter the model so that it will be stable with only one species or all of the mongooses, hawks and rats.

I could change things such the radius of where mongooses eat or use only a specific walk where hawks only eat rats etc.

Maybe I could add other plants that are fighting for space with the sugarcane.

I could change the reproduction rules to specifically match each species, instead of using sliders. Possibly change reproduction to depend on energy rather than being determined by a fixed probability?

I could create storage where maybe rats could slow feeding if they put thier energy/goods into storage.


Other models I looked at for this project.

"Rabbits-Grass-Weeds" for interacting populations with different rules.
"Wall-following" model to see how I could possibly put up a wall or set a fixed movement.
"Traffic-base-adaptive" to see about ebb and flow movement.
"Ants-adaptation" to see how ants moved across patches.


The wolf-sheep-predation model says

"If you mention this model or the NetLogo software in a publication, we ask that you include the citations below."

So here are the citations below...

For the model itself:

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

Please cite the NetLogo software as:

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


Copyright 1997 Uri Wilensky.

![CC BY-NC-SA 3.0](

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2000.

<!-- 1997 2000 -->

(back to the NetLogo User Community Models)