# A Predator-Prey Simulation

Show 50 post(s) from this thread on one page
Page 1 of 2 12 Last
• May 15th, 2013, 06:03 AM
rockx
A Predator-Prey Simulation
Let there be two fishes named Kernighans and Ritchies. The only fish know to prey on Ritchies and to be able to digest them is the colour-blind Kernighan. The Kernighan has adapted to a diet of Ritchies, and won't prey on any other species. No other fish or sea animal could prey on the Ritchies.

So with he above information, could a simulation be created to calculate the two population at different time intervals. I have done something but i belive that i could be on the wrong track.

Some other information to follow would be:

The population of Kernighans and Ritchies can be fully determined by the population size of Kernighans and Ritchies. Suppose that in a given month the number of Kernighan is pop_k, and the population of Ritchies is pop_r. The population of Kernighans and Ritchies is measured in multiples of 1000. This means a population size of 1.0 corresponds to 1000 fish. For the number of Kernighans in the next month we have:

 The population pop_k decreases by alpha_k  pop_k. This is the number of Kernighans that would starve if there were no Ritchies to eat.
The population pop_k increases by beta_k  pop_k  pop_r. This is the number of new Kernighans because they can feed on Ritchies.
The population pop_k decreases by gamma_k  pop_k2. This decrease in the number of Kernighans is due to competition between Kernighans.

Hence, given a population pop_k, the population in the next month is
pop_k - alpha_k  pop_k + beta_k  pop_k  pop_r - gamma_k.pop_k2
If the result of this computation is smaller than 0.001, then there are no Kernighan fish left

For the number of Ritchies in the next month we have

The population pop_r increases by alpha_r  pop_r. This is the number of new Ritchies, if there were no Kernighan to eat them..
 The population pop_r decreases by beta_r  pop_k  pop_r. This is the number of Ritcchies eaten by Kernighans.
 The population pop_r decreases by gamma_r  pop_r2. This decrease in the number of Ritcchies tis due to competition between Ritchies.

Hence, given a population pop_r the population in the next month is

 pop_r + alpha_r.pop_r - beta_r.pop_k.pop_r - gamma_r.pop_r 2
 If the result of this computation is smaller than 0.001, then there are no Ritchie fish left.

Measurements have shown that the constants have the following values:
 alpha_k = 0.4;
 beta_k = 0.4
 gamma_k=0.036
 alpha_r = 0.2;
 beta_r = 0.2
 gamma_r=0.036
• May 15th, 2013, 08:21 AM
GCDEF
Re: A Predator-Prey Simulation
What's your C or C++ question? Seems like this belongs in the Algorithms forum.
• May 15th, 2013, 10:15 AM
OReubens
Re: A Predator-Prey Simulation
Actually, this is a math problem. This is't a simulation all the information is static so for a given input there will be a given output.

A simulation would be about having to deal with things like... even if there are enough fish to eat, does a particular predator manage to catch enough of those prey fish to stay alive. Maybe it can't because none of the prey are nearby enough, or maybe it's not fast enough. in other words, some random effect.
• May 15th, 2013, 10:55 AM
nuzzle
Re: A Predator-Prey Simulation
Quote:

Originally Posted by OReubens
Actually, this is a math problem. This is't a simulation all the information is static so for a given input there will be a given output.

In fact predator-prey simulation is one of the cornerstones of mathematical biology. It gives rise to a system of two differential equations and to study how models like this evolve over time is called a dynamic simulation.

I suggest the OP uses the Lotka-Volterra equations and tries to identify the parameters with the ones of his problem,

http://en.wikipedia.org/wiki/Lotka%E...terra_equation
• May 15th, 2013, 04:37 PM
rockx
Re: A Predator-Prey Simulation
a program that asks the user for the current population of Kernighans and Ritchies, and to compute the population size for the next month. It should take the following into account.
 Use the above formulas to compute the population size for the next month.
 If the computed population size is smaller than 0.001, the result should be 0.
• May 15th, 2013, 06:29 PM
Paul McKenzie
Re: A Predator-Prey Simulation
Quote:

Originally Posted by rockx
a program that asks the user for the current population of Kernighans and Ritchies, and to compute the population size for the next month. It should take the following into account.
• Use the above formulas to compute the population size for the next month.
• If the computed population size is smaller than 0.001, the result should be 0.

Is that a C++ question?

Regards,

Paul McKenzie
• May 15th, 2013, 08:38 PM
GCDEF
Re: A Predator-Prey Simulation
Quote:

Originally Posted by Paul McKenzie
Is that a C++ question?

Regards,

Paul McKenzie

Doesn't look like any kind of question.
• May 16th, 2013, 08:40 AM
OReubens
Re: A Predator-Prey Simulation
I think it's a "can someone do my homework" question :p
• May 16th, 2013, 08:53 AM
OReubens
Re: A Predator-Prey Simulation
Quote:

Originally Posted by nuzzle
In fact predator-prey simulation is one of the cornerstones of mathematical biology. It gives rise to a system of two differential equations and to study how models like this evolve over time is called a dynamic simulation.

I suggest the OP uses the Lotka-Volterra equations and tries to identify the parameters with the ones of his problem,

http://en.wikipedia.org/wiki/Lotka%E...terra_equation

picking nits... it's not a simulation
if you run the math for a different range of times, It's a mathematical progression.

I doubt this is called a "dynamic simulation" because 1) it's not a simulation and 2) it's not dynamic, the input is entirely static, so the output is as well.

If I'd have to guess, I guess you're fumbling up some of the words here and it should really have been something more akin to:
...and to study how models like this evolve over time is called the dynamics of a (biological) system
dynamics != dynamic
even a static mathimatical progression has evolution dynamics

system != simulation.

I've seen the term "simulation" used incorrectly many times, even by big names, but essentially, if you can do the math in a spreadsheet (like you can here), it's a system, not a simulation.

Simulations are really about systems that are so dynamic that they branch off into 2 or more different possible states every so often, so much so that it is impossible to track EVERY state, so you end up randomly picking one of the states and go with that. You run the sim several times with different branches taken, and then try to infer your solutions/results based out of a small set of possible outcomes.

You could do the above predator/prey with an actual similation having, "playing out the lives of individual predators and prey". But the OP's quesion is really about a static system where you take statistical input about how the populations as a whole behave rather than individuals.
• May 16th, 2013, 10:56 AM
nuzzle
Re: A Predator-Prey Simulation
Quote:

Originally Posted by OReubens
picking nits... it's not a simulation
if you run the math for a different range of times, It's a mathematical progression.

I doubt this is called a "dynamic simulation" because 1) it's not a simulation and 2) it's not dynamic, the input is entirely static, so the output is as well.

You're wrong.

To model a system (any system, not just biological) using a set of differential (or difference) equations and then follow how it evolves and behaves over time on a computer is called a dynamic simulation. It's an established term.

Quote:

Simulations are really about systems that are so dynamic that they branch off into 2 or more different possible states every so often, so much so that it is impossible to track EVERY state
This is also wrong.

Dynamic simply means "varying over time" and the opposite is static. The dynamics may vary. It could be simple, complex and even chaotic but a dynamic system is a dynamic system and there is no such thing as more or less dynamic.

You seem to be confusing simulation with the concept of a statistical ensemble which is a theory to describe the overall behaviour of a system from its micro-states. To deal with it on a computer two simulation approaches are commonly used, dynamic simulation and (Markov Chain) Monte Carlo simulation. They're different but equivalent.
• May 16th, 2013, 01:47 PM
rockx
Re: A Predator-Prey Simulation
Quote:

Originally Posted by OReubens
I think it's a "can someone do my homework" question :p

Well yes it was my homework question and ive done it, as i said earlier and i quote
Quote:

I have done something but i belive that i could be on the wrong track.
Here is my code.

Code:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){

//Variable Declaration

const float Alpha_k = 0.4;
const float Beta_k  = 0.4;
const float Gamma_k = 0.036;

const float Alpha_r = 0.2;
const float Beta_r  = 0.2;
const float Gamma_r =0.036;

float pop_k = 0;
float pop_r = 0;

float new_k = 0;
float new_r = 0;

cout << " ***** Kernighan and Ritchie fish simulator ****\n\n";

cout << "Enter population size of Kernighans:\t\t";
cin >> pop_k;

cout << "Enter population size of Ritchies:\t\t";
cin >> pop_r;

//Computes the population size of Kernighans for the next month
new_k = pop_k - (Alpha_k * pop_k) + (Beta_k * pop_k * pop_r) - (Gamma_k * pop_k * pop_k);

//Computes the population size of Ritchies for the next month
new_r = pop_r + (Alpha_r * pop_r) - (Beta_r * pop_k * pop_r) - (Gamma_r * pop_r * pop_r);

cout << endl << endl;

cout << "The population of Kernighan one month later is\t:" << new_k << ".\n";
cout << "The population of Ritchie one month later is\t:" << new_r << ".\n\n";

system("pause");
return 0;
}

And

Code:

#include <iostream>
#include <stdlib.h>
#include <iomanip>

using namespace std;

int main(){

//Variable Declaration

const float Alpha_k  = 0.4;
const float Beta_k  = 0.4;
const float Gamma_k  = 0.036;

const float Alpha_r  = 0.2;
const float Beta_r  = 0.2;
const float Gamma_r  = 0.036;

float pop_k = 0;
float pop_r = 0;

float current_k = 0;
float current_r = 0;

int months = 0;

cout << " ***** Kerninghan and Ritchie fish simulator ****\n\n";

cout << "Enter population size of Kerninghans:\t";
cin >> pop_k;

cout << "Enter population size of Ritchies:\t";
cin >> pop_r;

cout << "Enter months you want to forecast:\t";
cin >> months;

cout << "\n\n\nMonth\tKerninghans\tRitchies\n";

for( int m=0; m <(months+1); m++){

cout << m << '\t' << pop_k << "      " << '\t' << pop_r << endl;

//Computes the population size of Kernighans for the next month
current_k = pop_k - (Alpha_k * pop_k) + (Beta_k * pop_k * pop_r) - (Gamma_k * pop_k * pop_k);

//Computes the population size of Ritchies for the next month
current_r = pop_r + (Alpha_r * pop_r) - (Beta_r * pop_k * pop_r) - (Gamma_r * pop_r * pop_r);

pop_k = current_k;// Update the population size of Kernighans
pop_r = current_r;// Update the population size of Ritchies
}

cout << endl;

system("pause");
return 0;
}

This was due in checked in April. I just wish to get to the correct coding so i could know where i went wrong
• May 16th, 2013, 03:16 PM
2kaud
Re: A Predator-Prey Simulation
So what's the problem? What's not working as it should?
• May 16th, 2013, 09:21 PM
rockx
Re: A Predator-Prey Simulation
I just wish to know if my coding is correct or have i made errors in my coding
• May 17th, 2013, 03:58 AM
2kaud
Re: A Predator-Prey Simulation
Assuming the calculations are correct (Does the program produce the output expected?) the only small comments re the code is that

Code:

for( int m=0; m <(months+1); m++){
could be written as

Code:

for( int m=0; m <= months; m++){
Also, if the input is <= 0 or input is >= 1 then you get strange results. You might want to restrict input to just > 0 and < 1 (or fix the formula so that it works for all positive numbers!).
• May 17th, 2013, 05:34 PM
nuzzle
Re: A Predator-Prey Simulation
Quote:

Originally Posted by OReubens
I've seen the term "simulation" used incorrectly many times, even by big names, but essentially, if you can do the math in a spreadsheet (like you can here), it's a system, not a simulation.

I must comment on this because it looks like the worst besserwisser approach I've seen in a long time.

So you've come up with your own oddball definition of what constitutes a simulation. And since you're the centre of the world yours is now the correct definition of simulation. And from this follows that everybody else must be wrong! All off a sudden everybody who are sticking to the standard or orthodox or established or timetested definition of simulation, are wrong!

Before we continue this discussion I would like you to present some support of your view of what is a simulation. Is it something you've cooked up or do you have references in support of it?
Show 50 post(s) from this thread on one page
Page 1 of 2 12 Last