| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Pieter Provoost" |
| Date: |
01 Jun 2004 07:11:26 PM |
| Object: |
model implementation |
Hi,
I am looking for c++ implementations of very simple ecosystem or
(meta)population models. I want to know the very basics of model
implementation.
For example, if my model consists of a number of units that hold a certain
amount of nutrients, and there are flows between the units that depend on
the contents of the units (dU1 = U1 - 5*U2 for example) - how do I implement
this?
Is it correct that I should represent these units by objects of the same
class, which has properties such as "contents", "how much is the flow to U1
dependent on the contents of this unit", "how much is the flow to U1
dependent on the contents of U1"...? If that is correct, how do I start a
simulation or calculate the change in the units over time?
I have just started with c++ so please keep it very basic :)
Thanks in advance,
Pieter
.
|
|
| User: "Howard" |
|
| Title: [OT] Re: model implementation |
02 Jun 2004 03:28:48 PM |
|
|
"Pieter Provoost" <pieterprovoost@tiscali.be> wrote in message
news:40bd1b63$0$9527$a0ced6e1@news.skynet.be...
Hi,
I am looking for c++ implementations of very simple ecosystem or
(meta)population models. I want to know the very basics of model
implementation.
For example, if my model consists of a number of units that hold a certain
amount of nutrients, and there are flows between the units that depend on
the contents of the units (dU1 = U1 - 5*U2 for example) - how do I
implement
this?
Is it correct that I should represent these units by objects of the same
class, which has properties such as "contents", "how much is the flow to
U1
dependent on the contents of this unit", "how much is the flow to U1
dependent on the contents of U1"...? If that is correct, how do I start a
simulation or calculate the change in the units over time?
I have just started with c++ so please keep it very basic :)
Thanks in advance,
Pieter
This is rather off-topic for this newsgroup, but I actually wrote this exact
program for the Ecology classes at my university once, intended as a
training device for students, so I thought I'd pass my thoughts along.
What I did was create a two-dimensional array of double values, with one
index representing the different levels (indexed 0..4, if I recall, from
producers to top consumers), and the other index representing time (in
days). The values stored in this array were the "contents" for the given
level on the given day.
The total length of the simulation was a value I let the user decide, but I
limited it to 10 years I think (since this was on a Apple IIe, and didn't
have much memory). You could make a longer maximum, or dynamically allocate
the array after asking for the simulation length in days.
Then I had another two-dimensional square array, also of double values,
indexed in both directions by the biotic (?) level. This array was used to
indicate the amount of the content of each of the levels to be added (or
subtracted) from this level's "content" when calculating the next day's
"content". These values are constants given by formulas in a book I used to
model the ecosystem. (But I had some fun playing with them, so I decided to
put them into a configuration file that the user could modify if desired,
and read the file into the array at startup.)
I allowed the user to "seed" the initial starting content values, and then
simply started the simulation by stepping forward in time (and thus in the
array), calculating each level's new content based entirely on the values
for the previous day and the values in the square array. Changing the
initial values allowed the user to see how well the system recovered from
things like over-predation of a given level (such as by humans killing half
the top consumers by hunting, for example).
The basic calculation was something like this (leaving out some neat
features I added):
// 0 index is the "seed" and is already set
for (int t = 1; t < max_time; ++t)
{
for (int b = 0; b < num_levels; ++b)
{
double new_content = 0;
for (int i = 0; i < num_levels; ++i)
// here's the caluclation(s):
// add amount of given level's content,
// multiplied by appropriate factor
// (note: factor could be negative,
// if preyed upon by other level!)
new_content += factor[b,i] * content[b,t-1];
content[b,t] = new_content;
}
display_content(t);
}
As added complexity and flexibility, I also included things like modifying
the producer content based on solar input, and let the user specify the day
in the year that the smulation was to start, and the amount (and timing) of
the solar fluctuation (to account for latitude, for example). I also added
other features, such as varying the "constants" according to annual changes
(such as hibernation periods), but this is the basic idea of the system.
Good luck!
-Howard
.
|
|
|
| User: "Pieter Provoost" |
|
| Title: Re: [OT] Re: model implementation |
02 Jun 2004 03:38:01 PM |
|
|
"Howard" <alicebt@hotmail.com> schreef in bericht
news:4Mqvc.116823$hH.2045892@bgtnsc04-news.ops.worldnet.att.net...
"Pieter Provoost" <pieterprovoost@tiscali.be> wrote in message
news:40bd1b63$0$9527$a0ced6e1@news.skynet.be...
Hi,
I am looking for c++ implementations of very simple ecosystem or
(meta)population models. I want to know the very basics of model
implementation.
For example, if my model consists of a number of units that hold a
certain
amount of nutrients, and there are flows between the units that depend
on
the contents of the units (dU1 = U1 - 5*U2 for example) - how do I
implement
this?
Is it correct that I should represent these units by objects of the same
class, which has properties such as "contents", "how much is the flow to
U1
dependent on the contents of this unit", "how much is the flow to U1
dependent on the contents of U1"...? If that is correct, how do I start
a
simulation or calculate the change in the units over time?
I have just started with c++ so please keep it very basic :)
Thanks in advance,
Pieter
This is rather off-topic for this newsgroup, but I actually wrote this
exact
program for the Ecology classes at my university once, intended as a
training device for students, so I thought I'd pass my thoughts along.
What I did was create a two-dimensional array of double values, with one
index representing the different levels (indexed 0..4, if I recall, from
producers to top consumers), and the other index representing time (in
days). The values stored in this array were the "contents" for the given
level on the given day.
The total length of the simulation was a value I let the user decide, but
I
limited it to 10 years I think (since this was on a Apple IIe, and didn't
have much memory). You could make a longer maximum, or dynamically
allocate
the array after asking for the simulation length in days.
Then I had another two-dimensional square array, also of double values,
indexed in both directions by the biotic (?) level. This array was used
to
indicate the amount of the content of each of the levels to be added (or
subtracted) from this level's "content" when calculating the next day's
"content". These values are constants given by formulas in a book I used
to
model the ecosystem. (But I had some fun playing with them, so I decided
to
put them into a configuration file that the user could modify if desired,
and read the file into the array at startup.)
I allowed the user to "seed" the initial starting content values, and then
simply started the simulation by stepping forward in time (and thus in the
array), calculating each level's new content based entirely on the values
for the previous day and the values in the square array. Changing the
initial values allowed the user to see how well the system recovered from
things like over-predation of a given level (such as by humans killing
half
the top consumers by hunting, for example).
The basic calculation was something like this (leaving out some neat
features I added):
// 0 index is the "seed" and is already set
for (int t = 1; t < max_time; ++t)
{
for (int b = 0; b < num_levels; ++b)
{
double new_content = 0;
for (int i = 0; i < num_levels; ++i)
// here's the caluclation(s):
// add amount of given level's content,
// multiplied by appropriate factor
// (note: factor could be negative,
// if preyed upon by other level!)
new_content += factor[b,i] * content[b,t-1];
content[b,t] = new_content;
}
display_content(t);
}
As added complexity and flexibility, I also included things like modifying
the producer content based on solar input, and let the user specify the
day
in the year that the smulation was to start, and the amount (and timing)
of
the solar fluctuation (to account for latitude, for example). I also
added
other features, such as varying the "constants" according to annual
changes
(such as hibernation periods), but this is the basic idea of the system.
Good luck!
-Howard
Thank you very much, I'm going to experiment a bit with your concept!
Pieter
.
|
|
|
| User: "Howard" |
|
| Title: Re: [OT] Re: model implementation |
02 Jun 2004 04:30:33 PM |
|
|
"> >
// 0 index is the "seed" and is already set
for (int t = 1; t < max_time; ++t)
{
for (int b = 0; b < num_levels; ++b)
{
double new_content = 0;
for (int i = 0; i < num_levels; ++i)
// here's the caluclation(s):
// add amount of given level's content,
// multiplied by appropriate factor
// (note: factor could be negative,
// if preyed upon by other level!)
new_content += factor[b,i] * content[b,t-1];
content[b,t] = new_content;
}
display_content(t);
}
Thank you very much, I'm going to experiment a bit with your concept!
Pieter
I think there's an error in my code (it was purely from memory). I think
that the calculation was actually:
new_content += factor[b,i] * content[b,t-1] * content[i,t-1];
But, I'm not positive on that.
The idea was that the new content would be influenced BOTH by the previous
content of the GIVEN level AND by the previous content of the OTHER level
(for each "other" level).
For example, the number of primary consumers added would be relative to both
the number of producers previously present AND by the number of primary
consumers previously present, (because a given amount of primary consumers
could eat more than a fewer number of primary consumers).
Basically, it's saying that the amount added (or subtracted) due to a
specific "other" level is the given constant of interaction between the two
times the product of actual previous values for the interacting levels.
(The more you *have* to eat, the more you *can* eat, and the more there
*are* of you that are eating, the more you all *will* eat.)
The equations came from a sheet I was given that also included the
constants, and if you're working from such a sheet or book, it should
provide the actual equations. You just need to make them fit with the
arrays you define.
-Howard
.
|
|
|
|
|
|

|
Related Articles |
|
|