If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: A Predator-Prey Simulation

I just wish to know if my coding is correct or have i made errors in my coding

Since you've used float variables throughout and if the code compiles there's nothing wrong with your C++ "coding". Any problems must lay with the algorithm you're using.

The algorithm can be deducted from the C++ code of course but how much effort should be put on the people here really? If all burden is on us then you could as well be cut out of the loop. Post the task and let us send in answers directly to your professor? We'll promise to credit you as the major inspirator.

Re: A Predator-Prey Simulation

hi nuzzle, i have already submitted my assignments back in April, when it was due. and i have uploaded the code that i had submitted, all i need to do now is that to make sure where i went wrong, i got my final exams coming in a few days time so i m basically trying to prepare for that. i m not asking anyone to do my assignment for me, i just needed a little guidance to perfect myself.

Re: A Predator-Prey Simulation

Originally Posted by rockx

hi nuzzle, i have already submitted my assignments back in April, when it was due. and i have uploaded the code that i had submitted, all i need to do now is that to make sure where i went wrong, i got my final exams coming in a few days time so i m basically trying to prepare for that. i m not asking anyone to do my assignment for me, i just needed a little guidance to perfect myself.

Re: A Predator-Prey Simulation

Originally Posted by rockx

This was due in checked in April. I just wish to get to the correct coding so i could know where i went wrong

Did you not get any comments/feedback from your teacher? If not, then check your results with another student or with another implementation, e.g. in a spreadsheet. Find out where any difference originates and then analyze which implementation is correct.

So far, you haven't done more than post your code and ask people to correct it. Programming doesn't work that way; you need to be able to verify your own code and, if not correct, hunt down and fix any errors. Whenever you get stuck, we can help you, but you'll need to show us all the steps you've taken. Otherwise, we cannot help you; we can only do the work for you (which is pointless).

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: A Predator-Prey Simulation

Lets imagine in the reef the 2 fishes reside in has been divided into 7 different sectors, which are populated by Kernighans and Ritchies. This predator-prey relationship determines largely the population size. However, the population is also influenced by migration of fish. Measurements show that every month a certain fraction in a sector will migrate to a neighbouring sector.

So lets now use functions and arrays to calculate the population whilst keeping the migration into consideration.

Suppose that in a given month the number of Kernighan in sector i is pop_k[i], and the population of Ritchies is pop_r[i]. The number of Kernighans in sector i changes as follows:

The population pop_k[i] decreases by alpha_k · pop_k[i]. This is the number of Kernighans that would starve if there were no Ritchies to eat.
• The population pop_k[i] increases by beta_k · pop_k[i] · pop_r[i]. This is the number of new Kernighans because they can feed on Ritchies.
• The population pop_k[i] decreases by gamma_k · pop_k[i]2. This decrease in the number of Kernighans is due to competition between Kernighans.
• The population pop_k[i] increases by omega_k · pop_k[left(i)]. This is the number of Kernighans that migrated from the sector to the left of sector i.
• The population pop_k[i] increases by omega_k · pop_k[right(i)]. This is the number of Kernighans that migrated from the sector to the right of sector i.
• The population pop_k[i] decreases by 2 omega_k · pop_k[i]. This is the number of Kernighans that migrated from the sector i to one of the two neighbouring sectors.
• If the result of this computation is smaller than 0.001, then there are no Kernighan fish left.

The number of Ritchies in sector i changes as follows:

The population pop_r[i] increases by alpha_r · pop_r[i]. This is the number of new Ritchies, if there were no Kernighan to eat them..
• The population pop_r[i] decreases by beta_r · pop_k[i] · pop_r[i]. This is the number of Ritcchies eaten by Kernighans.
• The population pop_r[i] decreases by gamma_r · pop_r[i]2. This decrease in the number of Ritcchies tis due to competition between Ritchies.
• The population pop_r[i] increases by omega_r · pop_r[left(i)]. This is the number of Ritcchies that migrated from the sector to the left of sector i.
• The population pop_r[i] increases by omega_r · pop_r[right(i)]. This is the number of Ritcchies that migrated from the sector to the right of sector i.
• The population pop_r[i] decreases by 2 omega_r · pop_r[i]. This is the number of Ritcchies that migrated from the sector i to one of the two neighbouring sectors.

So to implement a simulator that computes the populations for a given number of months for all sectors. This simulator has to take into account the predator-prey model and the influence of migration. It should give the user an option to set the population of Ritchies in a randomly selected sector to 0.

Re: A Predator-Prey Simulation

Apart from the fact that AskZero doesn't always return a value, GetMonth never returns a value, left doesn't do anything and doesn't return a value, you don't set the initial conditions for the different sectors (apart from asking if one should randomly be set to 0) and you have all the calculation code commented, what is your question (mindful that we won't write your code for you)?

Have you actually produced a program design for this simulation? If you haven't, your first task should be to produce the design. If you have a design, what is your problem in coding the program from the design?

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
C, C++ Compiler: Microsoft VS2015