Java Python CS152
Project 5: Simulating Elephant Population Management
As noted in the lab, this is the first of a two-part project where we'll be simulating the elephant population in Kruger National Park, South Africa.
The carrying capacity of the park is approximately 7000 elephants (1 elephant per square mile of park). Previous efforts to manage the population involved culling approximately 400 animals per year. After the development of an elephant contraceptive, the current effort to manage the population involves using a contraceptive dart on adult female elephants to limit the birth rate.
The conceptual goal of this week's simulation is twofold.
First, identify differences in the population distributions between the two methods of controlling the population.
Second, identify the percentage of adult females that need to be darted with the contraceptive each year in order to maintain a stable population without culling.
Following the overall design below, continue to develop the simulation step by step creating one function at a time and testing it with the provided “test” scripts. By the end of the project you will have a program which will allow you to test the effect of different percentages of darting on the total elephant population. For this project we will employ “trial and error” to get the best darting probability. In the next project, we will utilize optimization to programmatically find the optimum darting percentage.
Project Tasks (1-9)
Task 1: Write a function to calculate which elephants survive a year
In the lab, you created the newElephant, initPopulation and incrementAge functions. The next function to create is calcSurvival. The calcSurvival function processes the elephant population and determines whether each individual elephant survives to the next year.
The function takes the parameter list and population list as arguments. The function uses the parameters max age and the three survival probabilities (calf, adult, senior).
The function should loop over the existing population list and add each elephant to a new population list if it survives, using the elephant's age to determine which probability to use to determine survival. It should return the new population list. To do this:
1. Create a new empty list, new_population.
2. Loop over the existing population list. Use the age of the elephant to determine which survival probability applies, then use the appropriate survival probability to see if the elephant should be added to the new_population list. Do this by testing if a call to random.random() is less than the survival probability.
3. After the loop, return the new_population list.
4. Test your function by downloading test_calcSurvival.py, reading the code to make sure you understand it. Read the comments to make sure you know what output to expect.
Run it, examine the output, and make any necessary changes to your code.
Task 2: Write a function to randomly dart female elephants
Write a function, dartElephants, that goes through the adult females and randomly selects individuals for darting based on the comparison of random.random() and the darting probability parameter. Make sure that you generate a new random number for each comparison. The function takes in the parameter list and the population list as arguments. It returns the updated population list. The function makes use of the probability of darting, the juvenile age, and the maximum age.
1. The function should loop over each elephant in the population list. Inside the loop, it
should test if the elephant is female and is older than the juvenile age and is less than or equal to the maximum reproductive age.
2. If the elephant is an appropriate age, then determine if the elephant should be darted by testing if a call to random.random() is less than the probability of darting.
3. If the animal should be darted, set its pregnancy field to 0 and set the months of contraceptive left field to 22.
4. After the loop, return the population list.
5. Test your dartElephants function to mak