Creating a new class: Fishing Boat
The New England biologists want to study the effect of fishing on fish
populations in areas of the North Atlantic. They would like to
adapt the MBCS model with the
Aging, Breeding, Dying program to include fishing boats, so that they
can study the carrying capacity of the population -- the number of
fishing boats that will maximize the catch over
time without causing the population to die out.
The biologists want to make the same assumptions about the fish as
in the Aging, Breeding, Dying programming assignment, except that fishing boats
are introduced into the model.
- Each fishing boat has a fixed position
- A boat, on the surface, and a fish, at some depth, can occupy
the same position in the grid
- A boat cannot catch a fish at the same position (under the boat)
- Each fishing boat has a probability of catching a fish from
one of the neighboring positions
- A boat can catch fish from any neighboring position (North-East,
North-West, East, North-East, North-West, West) containing a fish
- Fish breed and die as specified in Aging, Breeding, Dying program
- The model from Spcicies with different species breeding and
dying should not be used to start with.
The display should be modified to show the positions of the boat(s).
- Character display
- Display the boat with two characters, "XX" indicating that a fish
is under the boat, "YY" that no fish is under the boat
The biologists would like to record both the fish population and the
number of fish caught in each time period. The objective is to
experiment with a given fish population
(given probabilities) and different numbers of fishing boats to find
how many boats maximize the total catch without killing off the fish population.
Assignment
Starting with the Aging, Breeding and Dying program, modified it to include multiple fishing
boats. In our new model,
the fishing boats will be static, remaining at one position.
- Create a new class, Boat to represent a fishing boat
- A boat has a position, a private data member.
- A boat has a number of fish caught, a private data member.
- A boat has a probability of catching fish, a private data member.
- A boat has a member function CatchFish that catches fish that are
located in the six neighboring positions.
- a fish in a neighboring position is caught with the probability of
catching for that boat.
- fish in different neighboring positions are caught or not caught
independently of each other.
- private "helper" member functions similar to those used with the
Fish Move function will be needed.
- 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 boats.
- The second line should be followed by one line for each boat, each containing
two integers giving the row and column of the position for that boat and one
real number between 0.0 and 1.0 representing the probability
of that boat catching a fish
- As before, there should follow one line for each fish in the simulation,
giving the row and column of the starting position for that fish. In the model with
breeding and dying, each row for the fish should
include an integer for the starting age of the fish and
two real numbers for the
probability of breeding and the probability of dying for that fish.
- Modify the Display class to display the boat. "XX" indicates a fish
under the boat, "YY" indicates no fish under the boat.
- Modify the Environment constructor so that it reads the boats from the
fish data file and records them, a vector of boats, then reads in the fish.
- Modify the Simulation Step function so that after the fish have moved,
each boat catches fish in neighboring positions, according to its probability.
- 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 fish
population and the number of fish caught over time
- The class should have one data member, an ostream myOut.
- The FishLog constructor should set this data member using an apstring
parameter giving the output file name.
- The class should have one public member function, Record, which records the
total number of fish currently in the simulation, the total
number of fish caught by each boat, and the total number of fish
caught so far
- 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 the number of fish in the simulation,
one integer for the number fish that have died in the simulation,
and one integer for the number of fish caught by each boat, and one integer for
the total number of fish caught. The function
Record should write one line to the file. There should be a tab between all integer
values on each line (use the escape sequence "\t".) The tab
will be needed to import the data to a spreadsheet. You will need to add another
private variable to the Environment class to keep track of the number of fish
that have died, plus edit or create any functions that need to manipulate this
private data member.
- Modify the main function in the fishsim.cpp file
- The user is prompted for the input data file name.
- 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.
In your simulation, the number of
fish caught and the number of fish left in the simulation should always equal
the number of fish at the start of the simulation plus the number of fish born,
minus the number of fish that have died. Test you program with
FishBoat.dat.
When the program is complete and working, use it with the data
file fish and boat data file,
with fish population of 206 and 6 boats. Run your simulation for 2000 steps.
Depending on which computer you use, this simulation could 20 minutes or more.
Which boat catches the most fish?
What to turn in
- Listing of all files you changed with noticebale comments specifying your changes.
Use a highlite marker and higlite all your changes/additions.
- Test data produced from your FishLog class. ONLY print out the first and last pages of data
from the log file.