Creating a new Species class
The New York ecologists want to study competing species of fish that occur in lakes in
upstate New York. They have species that require the same resources and can live in
essentially the same conditions, but find that in different lakes, different species
dominate, even after stocking the lakes with several different species. They would like to
adapt the MBCS model with breeding and dying to accomodate different species so that
they may study this phenomenon.
The ecologists want to make the same assumptions about the fish as in the programming
assignment for Aging, Breeding, Dying, except that the probabilities of breeding and dying are
determined by the species of the fish:
- Each fish has a species
- Fish age
- Each species of fish has its own probabilities of breeding and dying.
- Fish die at any age with the same probability; that probability is a characteristic of the species of the fish.
- Fish breed between the ages of 10 and 20 (as measured by steps in the simulation)
- The number of offspring produced when fish breed is dependent on the unused resources (i.e. empty space) which are available
- A breeding fish produces an offspring in each neighboring empty location with the probability determined by its species
- The probability of producing an offspring in one empty neighboring position is
independent of other neighboring positions
- Each offspring that is produced inherits its species from its parent
The ecologists would like to distinguish fish of different species and of different
ages in the display:
- Display the fish so that the different species can be differentiated.
- rather that giving each fish a distinct character in the display, display each
species of fish with a specific character
- Display older fish differently from younger fish
- once fish reach breeding age, change the way in which they are displayed
- Non-bredding fish should be displayed in lower a case letter, and once a fish has
reached breeding age, display the fish in upper a case letter.
The ecologists would also like to record how the populations grow or decline over
time, so that the population time series can then be displayed using a standard spreadsheet
program.
Assignment
Start with the program created for the programming assignment in unit Aging, Bredding, Dying, that has
fish that breed and die. Dupplicate
your LiveBreedDie folder and call it Spicies.
- Create a new class, Species to represent a species of fish
- This class will be similar to the Position class in the original program in that
it contains three data
members and returns their values with member functions
- The attributes of a species are a probability of dying, myProbDie, and a
probability of breeding,
myProbBreed, and a character for display
- Once set, when an instance of a species is constructed, the attributes should be immutable
- There should be an accessor function for each of the species attributes, inlcuding a ShowMe function
returning the character.
- Modify the fish data file format for the fish simulation as follows
- The first line of the file should still contain two integers, giving the number of
rows and number of columns in the fish grid
- The second line should contain one integer, the number of species
- The second line should be followed by one line for each species, each containing two
real numbers between 0.0 and 1.0 representing the probabilities of
dying and breeding (in that order)
- There should follow one line for each fish in the simulation. Each line for a fish
should contain four integers, two for the row and column giving the
position of the fish in the grid, one giving the age of the fish and one
giving the species identifier for the fish (a number from 0 to the number of species
minus 1)
- Add a new data member for the Fish class, mySpecies, with type Species.
- Remove the data members myProbDie and myProbBreed that were added in the programming
assignment for Aging, Bredding, Dying.
- Modify the Environment constructor so that it reads the species from the fish data
file and records them in a vector, then reads the fish in and assigns each fish a
species as indicated in the fish data file.
- Modify the fish member functions involved in fish breeding and dying so that they use
the probabilities given for the fish's species.
- Modify the fish member function ShowMe so that the character returned is based on the
fish's species' ShowMe result and not on the fish ID.
- Modify or add appropriate calls to DebugPrint to aid in testing your program.
- Create some fish data files and test your new program. To begin with, work with small
grids and small numbers of fish and use the debugging facility.
- Create a new class, FishLog, for recording the changes in the species populations over time
- The class should have one data member, an ofstream myOut.
- The FishLog constructor should set this data member using an apstring parameter giving
the output file name.
- There should be a destructor that closes the myOut stream.
- In order to do the following Record function correctly, you will first need to add
a data member myNumSpecies to the Evironment class. Determine where you need to set
this data value. You also will need a member function to return the myNumSpecies value.
- The class should have one public member function, Record, which records the total
number of fish for each species currently in the simulation
- Record needs one parameter, a reference to the environment from which it can get the
list of fish currently in the model
- The format of the log file should be one line for each step of the simulation where
each line has one integer for each species in the simulation, the
number of fish of that species at that step. The function Record
should write one line to the file.
- Modify the main function in the fishsim.cpp file
- The user is prompted for an output file name
- An instance of a FishLog using that file is created
- At each place where the display.Show is called, the FishLog Record function is called.
- The display can be removed if desired. This can speed up the simulation for long runs.
- Test the operation of the recording function with small numbers of fish.
Now the biologists have a tool with which they can experiment with different species in a
meaningful way. You might try experimenting to see if you can find, say, three
species that compete within the parameters of the simulation such that no one species
always wins out. A sample data file for a 50x50 grid that gives interesting results is
provided here.
fishspec.dat.
What to turn in
- Cover page with the title, date and your date.
- Report explaining how you implementated the changes and new classes.
- Code for for any header or implmentation file altered or created. Altered files should
have comments indicating code changes and the code should be highlighted!
- Output the display the fish grid before the first step of the simulation.
- Output for the log file after 50 steps of simulation.