Homework 7 - "Catch me if you can!" - Modeling predators and prey

One of the most common interactions between species of animals is the predator-prey relationship, which can take many forms. These interactions are critical to the health of animal populations and to the flow of energy through an ecosystem, and altering these populations (by hunting, for example) can have significant consequences to an ecosystem.

The Michigan Department of Natural Resources (DNR) has been examining the population of deer on North Manitou Island (part of Sleeping Bear Dunes National Lakeshore). The main large predators are North Manitou Island are coyotes, and the main large prey animals are white-tailed deer. There are not enough coyotes on the island due to former residents of the island hunting them, and the deer population is getting too large. One consequence of this is that there is not enough readily available food for the deer population, which is destroying the vegetation on the island and also affecting the health of the deer. The DNR has decided that some number of deer should be removed from the population (by hunting or transportation to the mainland) in order for the remaining population to stay at a healthy level.

You have been asked by the Michigan Department of Natural Resources to make a model of the interactions between coyotes and deer to determine how many deer should be removed from North Manitou Island. You're going to do this by developing an agent-based model of the interactions between coyotes and deer, and vary the number and properties of both species to examine how the populations change in relation to each other. In the sections below, we will provide you with some instructions on how to set up the model and some specific questions that the Michigan DNR would like to know the answers to. Happy simulating!

Note: While it's fine to talk with others about this homework - and in fact we strongly encourage you to do so - you need to write your own code and turn in your own homework assignment!

Your name

// put your name here!


Building a predator-prey model

Here are the rules of this model:

  • The island is represented by a square grid of cells that is $N_{G}$ on a side.
  • The model takes a total of $N_{S}$ steps.
  • There are two species, Coyotes and Deer, with $N_{C}$ coyotes and $N_{D}$ deer initially, which are placed at random places on the island (i.e., in random cells on the board).
  • If a coyote does not catch a deer after $N_{eat}$ turns, it dies of starvation. Deer are assumed to have sufficient food. (Not really true, but we're simplifying for this model.)
  • Both species move around the island island randomly, moving one cell in any direction per time step. (Note that "any direction" means into any of the up to 8 adjacent cells!)
    • Animals at the edge of the board cannot leave the board - they must move in some other direction.
    • Animals cannot move into a cell that is already occupied by another animal.
    • If an animal has nowhere to move (i.e., it is totally surrounded by other animals) it stays still.
  • If two deer end up in adjacent cells, there is a probability $P_{d}$ that the two deer breed and produce a new deer. The new deer is placed in one of the cells immediately adjacent to the other two deer.
  • If two coyotes end up in adjacent cells, there is a probability $P_{c}$ that the two coyotes breed and produce a new coyote. The new coyote is placed in one of the cells immediately adjacent to the other two coyotes.
  • If a coyote is in a cell next to a deer, there is a probability $P_{eat}$ that the coyote catches and eats the deer. In this case, the deer dies and is replaced by an empty cell.
  • Every step, there is a probability $P_{rem}$ that each deer is removed from the island's population by hunting or transport to the mainland.

Section 1 - The Model

Your task is to create a code that implements the predator-prey interaction model described above. No code has been provided to get you started - however, we strongly encourage you to look back at previous in-class and homework assignments, since there's a lot of code from previous assignments that you will find to be very helpful.

Some specific instructions are as follows.

  • Implement everything as functions, which separate functions for:
    • evolving the system
    • plotting the game board (with predators and prey shown as different shapes and colors)
    • moving animals around the game board
    • determining if animals reproduce
    • determining if deer are eaten by coyotes or removed from the island by humans.
    • calculating the total number of deer and, separately, coyotes at each simulation step
  • Keep track of the number of deer and coyotes as a function of simulation step, and return that in your simulation code.

Note that you will be graded both on the correctness of your solution and the quality of your code. Use functions when possible, and make sure that your code is clearly written and has comments explaining what everything does. Also make sure that all plots are clearly marked with axis labels and a title!


In [ ]:
# Put your code here, and add additional cells as necessary

Section 2 - some questions and plots

Note: make sure that all plots have appropriate x- and y-limits, as well as figure titles and axis labels. The questions may require both code and a written answer, so please make sure to do both!

For all models, assume a game board that is $N_G = 40$ cells on a side unless otherwise instructed!

Question 1: First, let's test the limits of our model. How does it behave when there are only Coyotes, and only Deer? Try setting $N_C = 20$ and $N_D = 0$, and then do a second model with $N_C = 0$ and $N_D = 20$. For both models, take $N_S = 100$ steps, set $N_{eat} = 10$, and give both deer and coyotes a probability of $P_D = P_C = 0.25$ of reproducing when they interact with others of their species. Set $P_{rem}=0$ (no deer are removed by humans). Use the code you have written to show how these two situations evolve over time (i.e., show the total population of coyotes and deer as a function of simulation time step), explain what you see, and explain why it makes sense.


In [ ]:
# Put your code and figures here - add additional cells if necessary

// explain what you see in the figures here!

Question 2: Now, let's try models with both species, but where they are far out of equilibrium. Consider a model with $N_C = 20$ and $N_D = 2$, and then do a second model with $N_C = 2$ and $N_D = 20$. For both models, take $N_S = 100$ steps, set $N_{eat} = 10$, give both deer and coyotes a probability of $P_D = P_C = 0.25$ of reproducing when they interact with others of their species, and give coyotes a probability $P_{eat} = 0.5$ of catching and eating a deer upon encountering it. Set $P_{rem}=0$ (no deer are removed by humans). Use the code you have written to show how these two situations evolve over time (i.e., show the total population of coyotes and deer as a function of simulation time step), explain what you see, and explain why it makes sense.


In [ ]:
# Put your code and figures here - add additional cells if necessary

Put your answer here!

Question 3: Now, let's modify the model above to try to create stable populations of coyotes and deer by removing deer from the island. Consider a model with $N_C = 2$ and $N_D = 40$. For both models, take $N_S = 100$ steps, set $N_{eat} = 10$, give both deer and coyotes a probability of $P_D = P_C = 0.25$ of reproducing when they interact with others of their species, and give coyotes a probability $P_{eat} = 0.5$ of catching and eating a deer upon encountering it. Start with $P_{rem}=0$ and do several runs where you increase it by steps of 0.1 to $P_{rem} = 1.0$, showing all of the results on a single plot with lines of different colors and/or types indicating different models. How does the situation change as deer are removed by humans? Over what range of $P_{rem}$ do you get populations that are relatively stable, meaning that they do not continuously increase or decrease?


In [ ]:
# Put your code here!

Put your answer here!

Question 4: Run several models where you change the other parameters, and show two or three of the most interesting ones below. Explain in the text box below your figures what is going on, and why.


In [ ]:
# Put your code here!

Put your answer here!

Question 5: After you've run all of these different models, what general principles can you take away? In other words, what have you learned about the interactions of predator and prey species from this model?

Put your answer here!

Question 6: In what ways could this model be modified to make it more realistic?

Put your answer here!


Section 3: Feedback (required!)

How long did you spend on the homework?

// Write your answer here

What questions do you have after this assignment?

// Write your answer here


Congratulations, you're done!

How to submit this assignment

Log into the course Desire2Learn website (d2l.msu.edu) and go to the "Homework assignments" folder. There will be a dropbox labeled "Homework 7". Upload this notebook there.