Practical Computing for Scientists Assignment -
Object-oriented programming and Individual-based Simulation Models: Lotka-Volterra Predator-Prey Interactions
As we have been working on in class, individual-based simulation models are powerful tools for exploring all kinds of hypotheses about how natural systems function. In order to use these tools, however, you must understand how object-oriented programming works and how programs can be written to "model" natural systems. In class, we worked on a single organism population model, but now we will progress to one in which we will examine a more complicated dynamic.
Predator-Prey interactions have been an important areas of research in the field of Population Ecology for a long-time and one of the classic examples in this field are Predator- Prey interactions as described by Lotka-Volterra equations. The Lotka-Volterra equations were analytical solutions (partial differential equations) derived to describe a system where there existed only two populations of species, a predator and a prey species:
![438_figure.png](https://secure.tutorsglobe.com/CMSImages/438_figure.png)
where x is the number of prey (for example, rabbits); y is the number of some predator (for example, foxes); dy/dt and dx/dt represent the growth rates of the two populations over time; t represents time; and α, β, γ, δ are positive real parameters describing the interaction of the two species. Overall, these equations yield the following dynamic of a harmonic relationship between the two species:
![176_figure1.png](https://secure.tutorsglobe.com/CMSImages/176_figure1.png)
For your assignment, you will be altering a provided "population" Python script similar to one we worked on in class to re-create this dynamic, but from an individual-based modeling perspective. There are two options you will have to set when running the program: 1) where to do a parameterization run or not ('Y' or 'N'); 2) how many iterations to run on the model. To complete this assignment, do the following:
1) Add a "Predator" class (called "Predator") to the population.assignment.py script. It must have variables for "age" and "offspring" that are initially equal to zero, a method called "reproduce" that changes the number of offspring each Predator has to 2, and a method called "changeAge" that changes a Predator's age to increase by 1.
2) Fill in all the blank comments throughout the program. These are lines with only a "#" on them. Explain what is the purpose/action of the code following each of these "#"s. FYI: "pop" method for lists removes an item from the end of the list each time it is called.
3) Add code to use the matplotlib package to create a single line plot with two line for lists that track the Prey and Predadator populations, respectively. Run the program with parameterization turned off ('N') and 1 iteration. You should see Lotka-Volterra-like behavior.
4) Change the line of code that is currently shown as:
if(PreyPop[i].age>=PreyAgeReprod and len(PreyPop) < Q ):
to
if(PreyPop[i].age>=PreyAgeReprod):
Create a line plot from the results. Compare it to the previous line plot. How are the two plots different? What is the role of the variable "Q"? Do the Lotka-Volterra equations from the introduction have variable "Q"? Which model to you think is more realistic and why?
5) Models are great for figuring out what values are reasonable for variable you might be interested in knowing about if you trust your model. For instance, say you were going to allow hunting on foxes, how much mortality would you be able to tolerate from hunting mortality? To figure this out, we can use a simple model "parameterization" method. The basic process is to propose a random value for mortality and then test to see if the model is viable under this new parameter. You will notice there is a "Parameterization run" as a raw input switch in the code.
Change the model code back to what it was before you changed it in Part 4. Run the code and turn it on (answer 'Y' to 'Parameterization run?' question) and set number of iteration for the model to 10,000. This will take some time to run.
To parameterize this model for the hunting of foxes, you have changed the model to one that includes mortality due to hunting on the "fox" predators. It also changes the model so that it will only consider a value hunting mortality rate as viable if as the population stays above at least 20 individuals, which we will assume to be the minimum number of foxes to allow the population to persist.
This parameterization run will output a frequency histogram for viable values for hunting mortality that allow fox population to cycle for the 50 years of the model and have a final population greater than 20.
Describe precisely how the probability of foxes dying from hunting (i.e. HuntMortRate) is being generated and examine the output by generating a frequency histogram of the data. Examine the resulting histogram and report what is reasonable rate of harvesting for foxes that allows for population persistence and what ranges are likely to drive the species to extinction?
Attachment:- Assignment Files.rar